commit a0d3257be0461688f2b969236dd048fa8ff029c2 Author: dheepa Date: Fri Jul 2 08:40:37 2021 +0000 sql files diff --git a/ReadMe.txt b/ReadMe.txt new file mode 100755 index 0000000..54265f9 --- /dev/null +++ b/ReadMe.txt @@ -0,0 +1,42 @@ +#For folder mmt: +pre requisite: +1. Table fw_core.fw_jobctl_runschedule has a column (end_time) , this column needs to be updated to current date + one can run following queries to update time: + update fw_core.fw_jobctl_runschedule set end_time=current_timestamp + +2. (optional): tables , , has column + the data for this column should be "stg1-completed". if this column has different value apart from the expected values then run the below queries: + update fw_core.fw_jobctl_runschedule set end_status =case when end_status <> '' then 'stg1-completed' end + update fw_core.fw_jobctl_file_sheet_runschedule set end_status =case when end_status <> '' then 'stg1-completed' end + update fw_core.fw_jobctl_file_runschedule set end_status =case when end_status <> '' then 'stg1-completed' end + +3. select fn_update_na() + +Now +1. compile: + In unix terminal, navigate to scripts folder ( home/jagadish/mmt/scripts) + In terminal type: ./run_onetime_compile.sh + In Terminal Type: ./run_onetime_compile.sh 1>/dev/null + this will only print errors on the screen. + + This will compile all applications by creating tables,inserting data etc. + + run_onetime_individual will run compile single folder (plz change the script as per needs) + +2. on linux : run wrappers: + wrapper : run_master_wrapper.sh is a wrapper that executes all wrapper function + it fails to execute if jobctl_runschedule table count is zero for the current date + else executes all the wrappers +running wrapper: + running run_master_wrapper.sh: + to run this wrapper just type in terminal: ./run_master_wrapper.sh + This will execute all the wrappers function. +Done + +one can test things by executing following queries in DBeaver:( + select * from fw_core.db_run_status where error_timestamp::date = date'2021-05-25%'; + select * from fw_core.fw_jobctl_file_runschedule where run_schedule_date::date = date'2021-05-25%'; + select * from fw_core.fw_jobctl_file_sheet_runschedule where run_schedule_date::date = date'2021-05-25%'; + select * from fw_core.check_model_count where create_timestamp::date = date'2021-05-25%; + select * from fw_core.check_mnemonic_count where create_time::date =date'2021-05-25%; + select * from fw_core.check_table_stg_trx_count where create_time::date =date'2021-05-25%; \ No newline at end of file diff --git a/onetime/archive/create/archive_create.sql b/onetime/archive/create/archive_create.sql new file mode 100755 index 0000000..2e73a2d --- /dev/null +++ b/onetime/archive/create/archive_create.sql @@ -0,0 +1,211 @@ +create schema archive; + +create table archive.budni_arc_perf_atmos_meas_test_block_archive( like staging2.budni_arc_perf_atmos_meas_test_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_arc_spec_h1_block_archive( like staging2.budni_arc_spec_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_arc_test_obs_summary_block_archive( like staging2.budni_arc_test_obs_summary_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_brk_other_observations_block_archive( like staging2.budni_brk_other_observations_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_brk_parking_barke_test_block_archive( like staging2.budni_brk_parking_barke_test_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_brk_service_cold_ballasted_25kmph_block_archive( like staging2.budni_brk_service_cold_ballasted_25kmph_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_brk_service_cold_ballasted_maximum_block_archive( like staging2.budni_brk_service_cold_ballasted_maximum_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_brk_service_cold_standard_25kmph_block_archive( like staging2.budni_brk_service_cold_standard_25kmph_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_brk_service_cold_standard_maximum_block_archive( like staging2.budni_brk_service_cold_standard_maximum_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_brk_service_fade_ballasted_25kmph_block_archive( like staging2.budni_brk_service_fade_ballasted_25kmph_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_brk_service_fade_standard_maximum_block_archive( like staging2.budni_brk_service_fade_standard_maximum_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_brk_spec_h1_block_archive( like staging2.budni_brk_spec_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_brk_test_obs_summary_block_archive( like staging2.budni_brk_test_obs_summary_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_dbp_drawbar_perf_block_archive( like staging2.budni_dbp_drawbar_perf_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_dbp_spec_h1_block_archive( like staging2.budni_dbp_spec_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_fld_cage_wheel_block_archive( like staging2.budni_fld_cage_wheel_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_fld_impl_test_block_archive( like staging2.budni_fld_impl_test_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_fld_spec_h1_block_archive( like staging2.budni_fld_spec_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_fld_sum_perf_test_block_archive( like staging2.budni_fld_sum_perf_test_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_fld_test_obs_summary_block_archive( like staging2.budni_fld_test_obs_summary_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_hdl_lifting_capacity_test_block_archive( like staging2.budni_hdl_lifting_capacity_test_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_hdl_maintenance_of_lift_load_block_archive( like staging2.budni_hdl_maintenance_of_lift_load_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_hdl_power_test_block_archive( like staging2.budni_hdl_power_test_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_hdl_spec_h1_block_archive( like staging2.budni_hdl_spec_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_hdl_test_obs_summary_block_archive( like staging2.budni_hdl_test_obs_summary_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_hlg_perf_test_block_archive( like staging2.budni_hlg_perf_test_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_hlg_spec_h1_block_archive( like staging2.budni_hlg_spec_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_hlg_test_obs_summary_block_archive( like staging2.budni_hlg_test_obs_summary_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_lcg_gravity_test_block_archive( like staging2.budni_lcg_gravity_test_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_lcg_spec_h1_block_archive( like staging2.budni_lcg_spec_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_nmt_atmos_cond_1_block_archive( like staging2.budni_nmt_atmos_cond_1_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_nmt_atmos_cond_2_block_archive( like staging2.budni_nmt_atmos_cond_2_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_nmt_meas_results_1_block_archive( like staging2.budni_nmt_meas_results_1_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_nmt_meas_results_2_block_archive( like staging2.budni_nmt_meas_results_2_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_nmt_noise_at_bystander_position_block_archive( like staging2.budni_nmt_noise_at_bystander_position_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_nmt_noise_at_operator_ear_level_block_archive( like staging2.budni_nmt_noise_at_operator_ear_level_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_nmt_spec_h1_block_archive( like staging2.budni_nmt_spec_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_nmt_test_obs_summary_block_archive( like staging2.budni_nmt_test_obs_summary_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_pto_mmtkeyword1_block_archive( like staging2.budni_pto_mmtkeyword1_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_pto_mmtkeyword2_block_archive( like staging2.budni_pto_mmtkeyword2_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_pto_perf_report_block_archive( like staging2.budni_pto_perf_report_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_pto_spec_h1_block_archive( like staging2.budni_pto_spec_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_pto_summary_block_archive( like staging2.budni_pto_summary_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_vmt_perf_meas_test_block_archive( like staging2.budni_vmt_perf_meas_test_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_vmt_spec_h1_block_archive( like staging2.budni_vmt_spec_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.budni_vmt_test_obs_summary_block_archive( like staging2.budni_vmt_test_obs_summary_block including all, insert_time timestamp default current_timestamp); +create table archive.dboecd_test_drawbar_performance_fuel_consumption_block_archive( like staging2.dboecd_test_drawbar_performance_fuel_consumption_block including all, insert_time timestamp default current_timestamp); +create table archive.dboecd_test_drawbar_performance_gear_performance_block_archive( like staging2.dboecd_test_drawbar_performance_gear_performance_block including all, insert_time timestamp default current_timestamp); +create table archive.dboecd_test_drawbar_performance_selected_summary_block_archive( like staging2.dboecd_test_drawbar_performance_selected_summary_block including all, insert_time timestamp default current_timestamp); +create table archive.dboecd_test_engine_rpm_engine_to_pto_block_archive( like staging2.dboecd_test_engine_rpm_engine_to_pto_block including all, insert_time timestamp default current_timestamp); +create table archive.dboecd_test_engine_rpm_required_pull_block_archive( like staging2.dboecd_test_engine_rpm_required_pull_block including all, insert_time timestamp default current_timestamp); +create table archive.dboecd_test_engine_rpm_rpm_block_archive( like staging2.dboecd_test_engine_rpm_rpm_block including all, insert_time timestamp default current_timestamp); +create table archive.dboecd_test_engine_rpm_tyre_details_block_archive( like staging2.dboecd_test_engine_rpm_tyre_details_block including all, insert_time timestamp default current_timestamp); +create table archive.dboecd_test_engine_rpm_weight_block_archive( like staging2.dboecd_test_engine_rpm_weight_block including all, insert_time timestamp default current_timestamp); +create table archive.dboecd_test_h1_block_archive( like staging2.dboecd_test_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.dboecd_test_measurement_uncertainty_block_archive( like staging2.dboecd_test_measurement_uncertainty_block including all, insert_time timestamp default current_timestamp); +create table archive.dboecd_test_remarks_block_archive( like staging2.dboecd_test_remarks_block including all, insert_time timestamp default current_timestamp); +create table archive.dboecd_test_remarks_footer_block_archive( like staging2.dboecd_test_remarks_footer_block including all, insert_time timestamp default current_timestamp); +create table archive.dboecd_test_test_condition_block_archive( like staging2.dboecd_test_test_condition_block including all, insert_time timestamp default current_timestamp); +create table archive.dboecd_test_test_equipment_used_block_archive( like staging2.dboecd_test_test_equipment_used_block including all, insert_time timestamp default current_timestamp); +create table archive.dboecd_test_tractor_specifications_cleaner_block_archive( like staging2.dboecd_test_tractor_specifications_cleaner_block including all, insert_time timestamp default current_timestamp); +create table archive.dboecd_test_tractor_specifications_cylinders_block_archive( like staging2.dboecd_test_tractor_specifications_cylinders_block including all, insert_time timestamp default current_timestamp); +create table archive.dboecd_test_tractor_specifications_engine_details_block_archive( like staging2.dboecd_test_tractor_specifications_engine_details_block including all, insert_time timestamp default current_timestamp); +create table archive.dboecd_test_tractor_specifications_fuel_and_injection_block( like staging2.dboecd_test_tractor_specifications_fuel_and_injection_block including all, insert_time timestamp default current_timestamp); +create table archive.dboecd_test_transmission_clutch_block_archive( like staging2.dboecd_test_transmission_clutch_block including all, insert_time timestamp default current_timestamp); +create table archive.dboecd_test_transmission_drawbar_block_archive( like staging2.dboecd_test_transmission_drawbar_block including all, insert_time timestamp default current_timestamp); +create table archive.dboecd_test_transmission_fuel_lubricant_block_archive( like staging2.dboecd_test_transmission_fuel_lubricant_block including all, insert_time timestamp default current_timestamp); +create table archive.dboecd_test_transmission_speed_chart_block_archive( like staging2.dboecd_test_transmission_speed_chart_block including all, insert_time timestamp default current_timestamp); +create table archive.dboecd_test_transmission_speed_chart_desc_block_archive( like staging2.dboecd_test_transmission_speed_chart_desc_block including all, insert_time timestamp default current_timestamp); +create table archive.dboecd_test_transmission_wheels_block_archive( like staging2.dboecd_test_transmission_wheels_block including all, insert_time timestamp default current_timestamp); +create table archive.dbstd_test_drawbar_performance_gear_performance_block_archive( like staging2.dbstd_test_drawbar_performance_gear_performance_block including all, insert_time timestamp default current_timestamp); +create table archive.dbstd_test_drawbar_performance_selected_summary_block_archive( like staging2.dbstd_test_drawbar_performance_selected_summary_block including all, insert_time timestamp default current_timestamp); +create table archive.dbstd_test_engine_rpm_engine_to_pto_block_archive( like staging2.dbstd_test_engine_rpm_engine_to_pto_block including all, insert_time timestamp default current_timestamp); +create table archive.dbstd_test_engine_rpm_required_pull_block_archive( like staging2.dbstd_test_engine_rpm_required_pull_block including all, insert_time timestamp default current_timestamp); +create table archive.dbstd_test_engine_rpm_rpm_block_archive( like staging2.dbstd_test_engine_rpm_rpm_block including all, insert_time timestamp default current_timestamp); +create table archive.dbstd_test_engine_rpm_tyre_details_block_archive( like staging2.dbstd_test_engine_rpm_tyre_details_block including all, insert_time timestamp default current_timestamp); +create table archive.dbstd_test_engine_rpm_weight_block_archive( like staging2.dbstd_test_engine_rpm_weight_block including all, insert_time timestamp default current_timestamp); +create table archive.dbstd_test_h1_block_archive( like staging2.dbstd_test_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.dbstd_test_measurement_uncertainty_block_archive( like staging2.dbstd_test_measurement_uncertainty_block including all, insert_time timestamp default current_timestamp); +create table archive.dbstd_test_remarks_block_archive( like staging2.dbstd_test_remarks_block including all, insert_time timestamp default current_timestamp); +create table archive.dbstd_test_remarks_footer_block_archive( like staging2.dbstd_test_remarks_footer_block including all, insert_time timestamp default current_timestamp); +create table archive.dbstd_test_test_condition_block_archive( like staging2.dbstd_test_test_condition_block including all, insert_time timestamp default current_timestamp); +create table archive.dbstd_test_test_equipment_used_block_archive( like staging2.dbstd_test_test_equipment_used_block including all, insert_time timestamp default current_timestamp); +create table archive.dbstd_test_tractor_specifications_cleaner_block_archive( like staging2.dbstd_test_tractor_specifications_cleaner_block including all, insert_time timestamp default current_timestamp); +create table archive.dbstd_test_tractor_specifications_cylinders_block_archive( like staging2.dbstd_test_tractor_specifications_cylinders_block including all, insert_time timestamp default current_timestamp); +create table archive.dbstd_test_tractor_specifications_engine_details_block_archive( like staging2.dbstd_test_tractor_specifications_engine_details_block including all, insert_time timestamp default current_timestamp); +create table archive.dbstd_test_tractor_specifications_fuel_and_injection_block( like staging2.dbstd_test_tractor_specifications_fuel_and_injection_block including all, insert_time timestamp default current_timestamp); +create table archive.dbstd_test_transmission_clutch_block_archive( like staging2.dbstd_test_transmission_clutch_block including all, insert_time timestamp default current_timestamp); +create table archive.dbstd_test_transmission_drawbar_block_archive( like staging2.dbstd_test_transmission_drawbar_block including all, insert_time timestamp default current_timestamp); +create table archive.dbstd_test_transmission_fuel_lubricant_block_archive( like staging2.dbstd_test_transmission_fuel_lubricant_block including all, insert_time timestamp default current_timestamp); +create table archive.dbstd_test_transmission_speed_chart_block_archive( like staging2.dbstd_test_transmission_speed_chart_block including all, insert_time timestamp default current_timestamp); +create table archive.dbstd_test_transmission_speed_chart_desc_block_archive( like staging2.dbstd_test_transmission_speed_chart_desc_block including all, insert_time timestamp default current_timestamp); +create table archive.dbstd_test_transmission_wheels_block_archive( like staging2.dbstd_test_transmission_wheels_block including all, insert_time timestamp default current_timestamp); +create table archive.ftdry_sum_comments_by_block_archive( like staging2.ftdry_sum_comments_by_block including all, insert_time timestamp default current_timestamp); +create table archive.ftdry_sum_implement_block_archive( like staging2.ftdry_sum_implement_block including all, insert_time timestamp default current_timestamp); +create table archive.ftdry_sum_test_condition_1_block_archive( like staging2.ftdry_sum_test_condition_1_block including all, insert_time timestamp default current_timestamp); +create table archive.ftdry_sum_test_condition_2_block_archive( like staging2.ftdry_sum_test_condition_2_block including all, insert_time timestamp default current_timestamp); +create table archive.ftdry_sum_trac_h1_block_archive( like staging2.ftdry_sum_trac_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.ftdry_trs_engine_rpm_block_archive( like staging2.ftdry_trs_engine_rpm_block including all, insert_time timestamp default current_timestamp); +create table archive.ftdry_trs_h1_block_archive( like staging2.ftdry_trs_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.ftdry_trs_implement_block_archive( like staging2.ftdry_trs_implement_block including all, insert_time timestamp default current_timestamp); +create table archive.ftdry_trs_spec_block_archive( like staging2.ftdry_trs_spec_block including all, insert_time timestamp default current_timestamp); +create table archive.fthlg_sum_comments_by_block_archive( like staging2.fthlg_sum_comments_by_block including all, insert_time timestamp default current_timestamp); +create table archive.fthlg_sum_test_condition_1_block_archive( like staging2.fthlg_sum_test_condition_1_block including all, insert_time timestamp default current_timestamp); +create table archive.fthlg_sum_test_condition_2_block_archive( like staging2.fthlg_sum_test_condition_2_block including all, insert_time timestamp default current_timestamp); +create table archive.fthlg_sum_trac_h1_block_archive( like staging2.fthlg_sum_trac_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.fthlg_sum_trail_type_block_archive( like staging2.fthlg_sum_trail_type_block including all, insert_time timestamp default current_timestamp); +create table archive.fthlg_trs_engine_rpm_block_archive( like staging2.fthlg_trs_engine_rpm_block including all, insert_time timestamp default current_timestamp); +create table archive.fthlg_trs_h1_block_archive( like staging2.fthlg_trs_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.fthlg_trs_spec_block_archive( like staging2.fthlg_trs_spec_block including all, insert_time timestamp default current_timestamp); +create table archive.fthlg_trs_trailer_block_archive( like staging2.fthlg_trs_trailer_block including all, insert_time timestamp default current_timestamp); +create table archive.ftwet_sum_cage_wheel_block_archive( like staging2.ftwet_sum_cage_wheel_block including all, insert_time timestamp default current_timestamp); +create table archive.ftwet_sum_comments_by_block_archive( like staging2.ftwet_sum_comments_by_block including all, insert_time timestamp default current_timestamp); +create table archive.ftwet_sum_implement_block_archive( like staging2.ftwet_sum_implement_block including all, insert_time timestamp default current_timestamp); +create table archive.ftwet_sum_test_condition_block_archive( like staging2.ftwet_sum_test_condition_block including all, insert_time timestamp default current_timestamp); +create table archive.ftwet_sum_trac_h1_block_archive( like staging2.ftwet_sum_trac_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.ftwet_trs_engine_rpm_block_archive( like staging2.ftwet_trs_engine_rpm_block including all, insert_time timestamp default current_timestamp); +create table archive.ftwet_trs_h1_block_archive( like staging2.ftwet_trs_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.ftwet_trs_implement_block_archive( like staging2.ftwet_trs_implement_block including all, insert_time timestamp default current_timestamp); +create table archive.ftwet_trs_spec_block_archive( like staging2.ftwet_trs_spec_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbt30_bt30_footer_block_archive( like staging2.ihtbt30_bt30_footer_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbt30_bt30_h1_block_archive( like staging2.ihtbt30_bt30_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbt30_bt30_test_condition_block_archive( like staging2.ihtbt30_bt30_test_condition_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbt30_bt30_test_res_1_block_archive( like staging2.ihtbt30_bt30_test_res_1_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbt30_bt30_test_res_2_block_archive( like staging2.ihtbt30_bt30_test_res_2_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbt30_bt30_test_res_3_block_archive( like staging2.ihtbt30_bt30_test_res_3_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbt30_bt30_test_res_4_block_archive( like staging2.ihtbt30_bt30_test_res_4_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbt30_bt30_tyre_details_block_archive( like staging2.ihtbt30_bt30_tyre_details_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbt30_bt30_weight_block_archive( like staging2.ihtbt30_bt30_weight_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbt50_bt50_footer_block_archive( like staging2.ihtbt50_bt50_footer_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbt50_bt50_h1_block_archive( like staging2.ihtbt50_bt50_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbt50_bt50_test_condition_block_archive( like staging2.ihtbt50_bt50_test_condition_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbt50_bt50_test_res_1_block_archive( like staging2.ihtbt50_bt50_test_res_1_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbt50_bt50_test_res_2_block_archive( like staging2.ihtbt50_bt50_test_res_2_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbt50_bt50_test_res_3_block_archive( like staging2.ihtbt50_bt50_test_res_3_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbt50_bt50_test_res_4_block_archive( like staging2.ihtbt50_bt50_test_res_4_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbt50_bt50_tyre_details_block_archive( like staging2.ihtbt50_bt50_tyre_details_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbt50_bt50_weight_block_archive( like staging2.ihtbt50_bt50_weight_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbtd_btd_footer_block_archive( like staging2.ihtbtd_btd_footer_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbtd_btd_h1_block_archive( like staging2.ihtbtd_btd_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbtd_btd_test_condition_block_archive( like staging2.ihtbtd_btd_test_condition_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbtd_btd_test_res_1_block_archive( like staging2.ihtbtd_btd_test_res_1_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbtd_btd_test_res_2_block_archive( like staging2.ihtbtd_btd_test_res_2_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbtd_btd_test_res_3_block_archive( like staging2.ihtbtd_btd_test_res_3_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbtd_btd_test_res_4_block_archive( like staging2.ihtbtd_btd_test_res_4_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbtd_btd_test_res_5_block_archive( like staging2.ihtbtd_btd_test_res_5_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbtd_btd_test_res_6_block_archive( like staging2.ihtbtd_btd_test_res_6_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbtd_btd_tyre_details_block_archive( like staging2.ihtbtd_btd_tyre_details_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtbtd_btd_weight_block_archive( like staging2.ihtbtd_btd_weight_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtcgm_cgm_footer_block_archive( like staging2.ihtcgm_cgm_footer_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtcgm_cgm_h1_block_archive( like staging2.ihtcgm_cgm_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtcgm_cgm_lifting_block_archive( like staging2.ihtcgm_cgm_lifting_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtcgm_cgm_results_block_archive( like staging2.ihtcgm_cgm_results_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtcgm_cgm_tyre_details_block_archive( like staging2.ihtcgm_cgm_tyre_details_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtcgm_cgm_weight_block_archive( like staging2.ihtcgm_cgm_weight_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtcgm_cgm_wheel_block_archive( like staging2.ihtcgm_cgm_wheel_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtemt_emt_brake_pedal_block_archive( like staging2.ihtemt_emt_brake_pedal_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtemt_emt_footer_block_archive( like staging2.ihtemt_emt_footer_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtemt_emt_h1_block_archive( like staging2.ihtemt_emt_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtemt_emt_pedal_block_archive( like staging2.ihtemt_emt_pedal_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtemt_emt_steering_block_archive( like staging2.ihtemt_emt_steering_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtemt_emt_tyre_details_block_archive( like staging2.ihtemt_emt_tyre_details_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtemt_emt_weight_block_archive( like staging2.ihtemt_emt_weight_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtemt_emt_wheel_block_archive( like staging2.ihtemt_emt_wheel_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtemt_std_raw_data_block_archive( like staging2.ihtemt_std_raw_data_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtham_ham_atmos_cond_block_archive( like staging2.ihtham_ham_atmos_cond_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtham_ham_drawbar_block_archive( like staging2.ihtham_ham_drawbar_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtham_ham_engine_rpm_block_archive( like staging2.ihtham_ham_engine_rpm_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtham_ham_footer_block_archive( like staging2.ihtham_ham_footer_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtham_ham_h1_block_archive( like staging2.ihtham_ham_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtham_ham_results_block_archive( like staging2.ihtham_ham_results_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtham_ham_tractor_block_archive( like staging2.ihtham_ham_tractor_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtham_ham_tyre_details_block_archive( like staging2.ihtham_ham_tyre_details_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtham_ham_weight_block_archive( like staging2.ihtham_ham_weight_block including all, insert_time timestamp default current_timestamp); +create table archive.ihthls_hls_footer_block_archive( like staging2.ihthls_hls_footer_block including all, insert_time timestamp default current_timestamp); +create table archive.ihthls_hls_h1_block_archive( like staging2.ihthls_hls_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.ihthls_hls_numeric_block_archive( like staging2.ihthls_hls_numeric_block including all, insert_time timestamp default current_timestamp); +create table archive.ihthls_hls_tyre_details_block_archive( like staging2.ihthls_hls_tyre_details_block including all, insert_time timestamp default current_timestamp); +create table archive.ihthls_hls_weight_block_archive( like staging2.ihthls_hls_weight_block including all, insert_time timestamp default current_timestamp); +create table archive.ihthls_hls_wheel_block_archive( like staging2.ihthls_hls_wheel_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtnst_nst_atmos_cond_block_archive( like staging2.ihtnst_nst_atmos_cond_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtnst_nst_engine_rpm_block_archive( like staging2.ihtnst_nst_engine_rpm_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtnst_nst_footer_block_archive( like staging2.ihtnst_nst_footer_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtnst_nst_h1_block_archive( like staging2.ihtnst_nst_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtnst_nst_oel_noise_block_archive( like staging2.ihtnst_nst_oel_noise_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtnst_nst_oel_noise_load_block_archive( like staging2.ihtnst_nst_oel_noise_load_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtnst_nst_stand_noise_block_archive( like staging2.ihtnst_nst_stand_noise_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtnst_nst_tyre_details_block_archive( like staging2.ihtnst_nst_tyre_details_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtnst_nst_weight_block_archive( like staging2.ihtnst_nst_weight_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtsll_sll_footer_block_archive( like staging2.ihtsll_sll_footer_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtsll_sll_forward_block_archive( like staging2.ihtsll_sll_forward_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtsll_sll_h1_block_archive( like staging2.ihtsll_sll_h1_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtsll_sll_lead_lag_block_archive( like staging2.ihtsll_sll_lead_lag_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtsll_sll_reverse_block_archive( like staging2.ihtsll_sll_reverse_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtsll_sll_tyre_details_block_archive( like staging2.ihtsll_sll_tyre_details_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtsll_sll_weight_block_archive( like staging2.ihtsll_sll_weight_block including all, insert_time timestamp default current_timestamp); +create table archive.ihtsll_sll_wheel_block_archive( like staging2.ihtsll_sll_wheel_block including all, insert_time timestamp default current_timestamp); +create table archive.ptoben_gvg_performance_governing_trails_block_archive( like staging2.ptoben_gvg_performance_governing_trails_block including all, insert_time timestamp default current_timestamp); +create table archive.ptoben_mpm_performance_boost_natural_block_archive( like staging2.ptoben_mpm_performance_boost_natural_block including all, insert_time timestamp default current_timestamp); +create table archive.ptoben_prf_2hrs_max_power_natural_ambient_block_archive( like staging2.ptoben_prf_2hrs_max_power_natural_ambient_block including all, insert_time timestamp default current_timestamp); +create table archive.ptoben_prf_2hrs_max_power_test_high_ambient_block_archive( like staging2.ptoben_prf_2hrs_max_power_test_high_ambient_block including all, insert_time timestamp default current_timestamp); +create table archive.ptoben_prf_engine_oil_consumption_block_archive( like staging2.ptoben_prf_engine_oil_consumption_block including all, insert_time timestamp default current_timestamp); +create table archive.ptoben_prf_key_performance_parameters_block_archive( like staging2.ptoben_prf_key_performance_parameters_block including all, insert_time timestamp default current_timestamp); +create table archive.ptoben_prf_smoke_test_block_archive( like staging2.ptoben_prf_smoke_test_block including all, insert_time timestamp default current_timestamp); +create table archive.ptoben_prf_tractor_specs_block_archive( like staging2.ptoben_prf_tractor_specs_block including all, insert_time timestamp default current_timestamp); +create table archive.ptoben_prf_varying_load_rated_rpm_block_archive( like staging2.ptoben_prf_varying_load_rated_rpm_block including all, insert_time timestamp default current_timestamp); +create table archive.ptoben_prf_varying_load_std_pto_block_archive( like staging2.ptoben_prf_varying_load_std_pto_block including all, insert_time timestamp default current_timestamp); +create table archive.ptoben_prf_varying_speed_natural_ambient_block_archive( like staging2.ptoben_prf_varying_speed_natural_ambient_block including all, insert_time timestamp default current_timestamp); +create table archive.ptoben_prf_varying_speed_test_high_ambient_block_archive( like staging2.ptoben_prf_varying_speed_test_high_ambient_block including all, insert_time timestamp default current_timestamp); diff --git a/onetime/archive/function/fn_archive.sql b/onetime/archive/function/fn_archive.sql new file mode 100755 index 0000000..c8a6a65 --- /dev/null +++ b/onetime/archive/function/fn_archive.sql @@ -0,0 +1,251 @@ +--drop function if exists fw_core.fn_run_block_archive; + +CREATE OR REPLACE FUNCTION fw_core.fn_run_block_archive(p_client_id int,p_function_id int,p_job_id int,p_step_id int) + RETURNS void AS $$ + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __jobid int := p_job_id; + declare __stepid int := p_step_id; + declare __file_mnemonic text :='ARCHIVE'; + declare __file_sheet_mnemonic text :='ARCHIVE_SHEET'; + declare __file_syspk int := null; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + +begin +insert into archive.budni_arc_perf_atmos_meas_test_block_archive select * from staging2.budni_arc_perf_atmos_meas_test_block; +insert into archive.budni_arc_spec_h1_block_archive select * from staging2.budni_arc_spec_h1_block; +insert into archive.budni_arc_test_obs_summary_block_archive select * from staging2.budni_arc_test_obs_summary_block; +insert into archive.budni_brk_other_observations_block_archive select * from staging2.budni_brk_other_observations_block; +insert into archive.budni_brk_parking_barke_test_block_archive select * from staging2.budni_brk_parking_barke_test_block; +insert into archive.budni_brk_service_cold_ballasted_25kmph_block_archive select * from staging2.budni_brk_service_cold_ballasted_25kmph_block; +insert into archive.budni_brk_service_cold_ballasted_maximum_block_archive select * from staging2.budni_brk_service_cold_ballasted_maximum_block; +insert into archive.budni_brk_service_cold_standard_25kmph_block_archive select * from staging2.budni_brk_service_cold_standard_25kmph_block; +insert into archive.budni_brk_service_cold_standard_maximum_block_archive select * from staging2.budni_brk_service_cold_standard_maximum_block; +insert into archive.budni_brk_service_fade_ballasted_25kmph_block_archive select * from staging2.budni_brk_service_fade_ballasted_25kmph_block; +insert into archive.budni_brk_service_fade_standard_maximum_block_archive select * from staging2.budni_brk_service_fade_standard_maximum_block; +insert into archive.budni_brk_spec_h1_block_archive select * from staging2.budni_brk_spec_h1_block; +insert into archive.budni_brk_test_obs_summary_block_archive select * from staging2.budni_brk_test_obs_summary_block; +insert into archive.budni_dbp_drawbar_perf_block_archive select * from staging2.budni_dbp_drawbar_perf_block; +insert into archive.budni_dbp_spec_h1_block_archive select * from staging2.budni_dbp_spec_h1_block; +insert into archive.budni_fld_cage_wheel_block_archive select * from staging2.budni_fld_cage_wheel_block; +insert into archive.budni_fld_impl_test_block_archive select * from staging2.budni_fld_impl_test_block; +insert into archive.budni_fld_spec_h1_block_archive select * from staging2.budni_fld_spec_h1_block; +insert into archive.budni_fld_sum_perf_test_block_archive select * from staging2.budni_fld_sum_perf_test_block; +insert into archive.budni_fld_test_obs_summary_block_archive select * from staging2.budni_fld_test_obs_summary_block; +insert into archive.budni_hdl_lifting_capacity_test_block_archive select * from staging2.budni_hdl_lifting_capacity_test_block; +insert into archive.budni_hdl_maintenance_of_lift_load_block_archive select * from staging2.budni_hdl_maintenance_of_lift_load_block; +insert into archive.budni_hdl_power_test_block_archive select * from staging2.budni_hdl_power_test_block; +insert into archive.budni_hdl_spec_h1_block_archive select * from staging2.budni_hdl_spec_h1_block; +insert into archive.budni_hdl_test_obs_summary_block_archive select * from staging2.budni_hdl_test_obs_summary_block; +insert into archive.budni_hlg_perf_test_block_archive select * from staging2.budni_hlg_perf_test_block; +insert into archive.budni_hlg_spec_h1_block_archive select * from staging2.budni_hlg_spec_h1_block; +insert into archive.budni_hlg_test_obs_summary_block_archive select * from staging2.budni_hlg_test_obs_summary_block; +insert into archive.budni_lcg_gravity_test_block_archive select * from staging2.budni_lcg_gravity_test_block; +insert into archive.budni_lcg_spec_h1_block_archive select * from staging2.budni_lcg_spec_h1_block; +insert into archive.budni_nmt_atmos_cond_1_block_archive select * from staging2.budni_nmt_atmos_cond_1_block; +insert into archive.budni_nmt_atmos_cond_2_block_archive select * from staging2.budni_nmt_atmos_cond_2_block; +insert into archive.budni_nmt_meas_results_1_block_archive select * from staging2.budni_nmt_meas_results_1_block; +insert into archive.budni_nmt_meas_results_2_block_archive select * from staging2.budni_nmt_meas_results_2_block; +insert into archive.budni_nmt_noise_at_bystander_position_block_archive select * from staging2.budni_nmt_noise_at_bystander_position_block; +insert into archive.budni_nmt_noise_at_operator_ear_level_block_archive select * from staging2.budni_nmt_noise_at_operator_ear_level_block; +insert into archive.budni_nmt_spec_h1_block_archive select * from staging2.budni_nmt_spec_h1_block; +insert into archive.budni_nmt_test_obs_summary_block_archive select * from staging2.budni_nmt_test_obs_summary_block; +insert into archive.budni_pto_mmtkeyword1_block_archive select * from staging2.budni_pto_mmtkeyword1_block; +insert into archive.budni_pto_mmtkeyword2_block_archive select * from staging2.budni_pto_mmtkeyword2_block; +insert into archive.budni_pto_perf_report_block_archive select * from staging2.budni_pto_perf_report_block; +insert into archive.budni_pto_spec_h1_block_archive select * from staging2.budni_pto_spec_h1_block; +insert into archive.budni_pto_summary_block_archive select * from staging2.budni_pto_summary_block; +insert into archive.budni_vmt_perf_meas_test_block_archive select * from staging2.budni_vmt_perf_meas_test_block; +insert into archive.budni_vmt_spec_h1_block_archive select * from staging2.budni_vmt_spec_h1_block; +insert into archive.budni_vmt_test_obs_summary_block_archive select * from staging2.budni_vmt_test_obs_summary_block; +insert into archive.dboecd_test_drawbar_performance_fuel_consumption_block_archive select * from staging2.dboecd_test_drawbar_performance_fuel_consumption_block; +insert into archive.dboecd_test_drawbar_performance_gear_performance_block_archive select * from staging2.dboecd_test_drawbar_performance_gear_performance_block; +insert into archive.dboecd_test_drawbar_performance_selected_summary_block_archive select * from staging2.dboecd_test_drawbar_performance_selected_summary_block; +insert into archive.dboecd_test_engine_rpm_engine_to_pto_block_archive select * from staging2.dboecd_test_engine_rpm_engine_to_pto_block; +insert into archive.dboecd_test_engine_rpm_required_pull_block_archive select * from staging2.dboecd_test_engine_rpm_required_pull_block; +insert into archive.dboecd_test_engine_rpm_rpm_block_archive select * from staging2.dboecd_test_engine_rpm_rpm_block; +insert into archive.dboecd_test_engine_rpm_tyre_details_block_archive select * from staging2.dboecd_test_engine_rpm_tyre_details_block; +insert into archive.dboecd_test_engine_rpm_weight_block_archive select * from staging2.dboecd_test_engine_rpm_weight_block; +insert into archive.dboecd_test_h1_block_archive select * from staging2.dboecd_test_h1_block; +insert into archive.dboecd_test_measurement_uncertainty_block_archive select * from staging2.dboecd_test_measurement_uncertainty_block; +insert into archive.dboecd_test_remarks_block_archive select * from staging2.dboecd_test_remarks_block; +insert into archive.dboecd_test_remarks_footer_block_archive select * from staging2.dboecd_test_remarks_footer_block; +insert into archive.dboecd_test_test_condition_block_archive select * from staging2.dboecd_test_test_condition_block; +insert into archive.dboecd_test_test_equipment_used_block_archive select * from staging2.dboecd_test_test_equipment_used_block; +insert into archive.dboecd_test_tractor_specifications_cleaner_block_archive select * from staging2.dboecd_test_tractor_specifications_cleaner_block; +insert into archive.dboecd_test_tractor_specifications_cylinders_block_archive select * from staging2.dboecd_test_tractor_specifications_cylinders_block; +insert into archive.dboecd_test_tractor_specifications_engine_details_block_archive select * from staging2.dboecd_test_tractor_specifications_engine_details_block; +insert into archive.dboecd_test_tractor_specifications_fuel_and_injection_block select * from staging2.dboecd_test_tractor_specifications_fuel_and_injection_block; +insert into archive.dboecd_test_transmission_clutch_block_archive select * from staging2.dboecd_test_transmission_clutch_block; +insert into archive.dboecd_test_transmission_drawbar_block_archive select * from staging2.dboecd_test_transmission_drawbar_block; +insert into archive.dboecd_test_transmission_fuel_lubricant_block_archive select * from staging2.dboecd_test_transmission_fuel_lubricant_block; +insert into archive.dboecd_test_transmission_speed_chart_block_archive select * from staging2.dboecd_test_transmission_speed_chart_block; +insert into archive.dboecd_test_transmission_speed_chart_desc_block_archive select * from staging2.dboecd_test_transmission_speed_chart_desc_block; +insert into archive.dboecd_test_transmission_wheels_block_archive select * from staging2.dboecd_test_transmission_wheels_block; +insert into archive.dbstd_test_drawbar_performance_gear_performance_block_archive select * from staging2.dbstd_test_drawbar_performance_gear_performance_block; +insert into archive.dbstd_test_drawbar_performance_selected_summary_block_archive select * from staging2.dbstd_test_drawbar_performance_selected_summary_block; +insert into archive.dbstd_test_engine_rpm_engine_to_pto_block_archive select * from staging2.dbstd_test_engine_rpm_engine_to_pto_block; +insert into archive.dbstd_test_engine_rpm_required_pull_block_archive select * from staging2.dbstd_test_engine_rpm_required_pull_block; +insert into archive.dbstd_test_engine_rpm_rpm_block_archive select * from staging2.dbstd_test_engine_rpm_rpm_block; +insert into archive.dbstd_test_engine_rpm_tyre_details_block_archive select * from staging2.dbstd_test_engine_rpm_tyre_details_block; +insert into archive.dbstd_test_engine_rpm_weight_block_archive select * from staging2.dbstd_test_engine_rpm_weight_block; +insert into archive.dbstd_test_h1_block_archive select * from staging2.dbstd_test_h1_block; +insert into archive.dbstd_test_measurement_uncertainty_block_archive select * from staging2.dbstd_test_measurement_uncertainty_block; +insert into archive.dbstd_test_remarks_block_archive select * from staging2.dbstd_test_remarks_block; +insert into archive.dbstd_test_remarks_footer_block_archive select * from staging2.dbstd_test_remarks_footer_block; +insert into archive.dbstd_test_test_condition_block_archive select * from staging2.dbstd_test_test_condition_block; +insert into archive.dbstd_test_test_equipment_used_block_archive select * from staging2.dbstd_test_test_equipment_used_block; +insert into archive.dbstd_test_tractor_specifications_cleaner_block_archive select * from staging2.dbstd_test_tractor_specifications_cleaner_block; +insert into archive.dbstd_test_tractor_specifications_cylinders_block_archive select * from staging2.dbstd_test_tractor_specifications_cylinders_block; +insert into archive.dbstd_test_tractor_specifications_engine_details_block_archive select * from staging2.dbstd_test_tractor_specifications_engine_details_block; +insert into archive.dbstd_test_tractor_specifications_fuel_and_injection_block select * from staging2.dbstd_test_tractor_specifications_fuel_and_injection_block; +insert into archive.dbstd_test_transmission_clutch_block_archive select * from staging2.dbstd_test_transmission_clutch_block; +insert into archive.dbstd_test_transmission_drawbar_block_archive select * from staging2.dbstd_test_transmission_drawbar_block; +insert into archive.dbstd_test_transmission_fuel_lubricant_block_archive select * from staging2.dbstd_test_transmission_fuel_lubricant_block; +insert into archive.dbstd_test_transmission_speed_chart_block_archive select * from staging2.dbstd_test_transmission_speed_chart_block; +insert into archive.dbstd_test_transmission_speed_chart_desc_block_archive select * from staging2.dbstd_test_transmission_speed_chart_desc_block; +insert into archive.dbstd_test_transmission_wheels_block_archive select * from staging2.dbstd_test_transmission_wheels_block; +insert into archive.ftdry_sum_comments_by_block_archive select * from staging2.ftdry_sum_comments_by_block; +insert into archive.ftdry_sum_implement_block_archive select * from staging2.ftdry_sum_implement_block; +insert into archive.ftdry_sum_test_condition_1_block_archive select * from staging2.ftdry_sum_test_condition_1_block; +insert into archive.ftdry_sum_test_condition_2_block_archive select * from staging2.ftdry_sum_test_condition_2_block; +insert into archive.ftdry_sum_trac_h1_block_archive select * from staging2.ftdry_sum_trac_h1_block; +insert into archive.ftdry_trs_engine_rpm_block_archive select * from staging2.ftdry_trs_engine_rpm_block; +insert into archive.ftdry_trs_h1_block_archive select * from staging2.ftdry_trs_h1_block; +insert into archive.ftdry_trs_implement_block_archive select * from staging2.ftdry_trs_implement_block; +insert into archive.ftdry_trs_spec_block_archive select * from staging2.ftdry_trs_spec_block; +insert into archive.fthlg_sum_comments_by_block_archive select * from staging2.fthlg_sum_comments_by_block; +insert into archive.fthlg_sum_test_condition_1_block_archive select * from staging2.fthlg_sum_test_condition_1_block; +insert into archive.fthlg_sum_test_condition_2_block_archive select * from staging2.fthlg_sum_test_condition_2_block; +insert into archive.fthlg_sum_trac_h1_block_archive select * from staging2.fthlg_sum_trac_h1_block; +insert into archive.fthlg_sum_trail_type_block_archive select * from staging2.fthlg_sum_trail_type_block; +insert into archive.fthlg_trs_engine_rpm_block_archive select * from staging2.fthlg_trs_engine_rpm_block; +insert into archive.fthlg_trs_h1_block_archive select * from staging2.fthlg_trs_h1_block; +insert into archive.fthlg_trs_spec_block_archive select * from staging2.fthlg_trs_spec_block; +insert into archive.fthlg_trs_trailer_block_archive select * from staging2.fthlg_trs_trailer_block; +insert into archive.ftwet_sum_cage_wheel_block_archive select * from staging2.ftwet_sum_cage_wheel_block; +insert into archive.ftwet_sum_comments_by_block_archive select * from staging2.ftwet_sum_comments_by_block; +insert into archive.ftwet_sum_implement_block_archive select * from staging2.ftwet_sum_implement_block; +insert into archive.ftwet_sum_test_condition_block_archive select * from staging2.ftwet_sum_test_condition_block; +insert into archive.ftwet_sum_trac_h1_block_archive select * from staging2.ftwet_sum_trac_h1_block; +insert into archive.ftwet_trs_engine_rpm_block_archive select * from staging2.ftwet_trs_engine_rpm_block; +insert into archive.ftwet_trs_h1_block_archive select * from staging2.ftwet_trs_h1_block; +insert into archive.ftwet_trs_implement_block_archive select * from staging2.ftwet_trs_implement_block; +insert into archive.ftwet_trs_spec_block_archive select * from staging2.ftwet_trs_spec_block; +insert into archive.ihtbt30_bt30_footer_block_archive select * from staging2.ihtbt30_bt30_footer_block; +insert into archive.ihtbt30_bt30_h1_block_archive select * from staging2.ihtbt30_bt30_h1_block; +insert into archive.ihtbt30_bt30_test_condition_block_archive select * from staging2.ihtbt30_bt30_test_condition_block; +insert into archive.ihtbt30_bt30_test_res_1_block_archive select * from staging2.ihtbt30_bt30_test_res_1_block; +insert into archive.ihtbt30_bt30_test_res_2_block_archive select * from staging2.ihtbt30_bt30_test_res_2_block; +insert into archive.ihtbt30_bt30_test_res_3_block_archive select * from staging2.ihtbt30_bt30_test_res_3_block; +insert into archive.ihtbt30_bt30_test_res_4_block_archive select * from staging2.ihtbt30_bt30_test_res_4_block; +insert into archive.ihtbt30_bt30_tyre_details_block_archive select * from staging2.ihtbt30_bt30_tyre_details_block; +insert into archive.ihtbt30_bt30_weight_block_archive select * from staging2.ihtbt30_bt30_weight_block; +insert into archive.ihtbt50_bt50_footer_block_archive select * from staging2.ihtbt50_bt50_footer_block; +insert into archive.ihtbt50_bt50_h1_block_archive select * from staging2.ihtbt50_bt50_h1_block; +insert into archive.ihtbt50_bt50_test_condition_block_archive select * from staging2.ihtbt50_bt50_test_condition_block; +insert into archive.ihtbt50_bt50_test_res_1_block_archive select * from staging2.ihtbt50_bt50_test_res_1_block; +insert into archive.ihtbt50_bt50_test_res_2_block_archive select * from staging2.ihtbt50_bt50_test_res_2_block; +insert into archive.ihtbt50_bt50_test_res_3_block_archive select * from staging2.ihtbt50_bt50_test_res_3_block; +insert into archive.ihtbt50_bt50_test_res_4_block_archive select * from staging2.ihtbt50_bt50_test_res_4_block; +insert into archive.ihtbt50_bt50_tyre_details_block_archive select * from staging2.ihtbt50_bt50_tyre_details_block; +insert into archive.ihtbt50_bt50_weight_block_archive select * from staging2.ihtbt50_bt50_weight_block; +insert into archive.ihtbtd_btd_footer_block_archive select * from staging2.ihtbtd_btd_footer_block; +insert into archive.ihtbtd_btd_h1_block_archive select * from staging2.ihtbtd_btd_h1_block; +insert into archive.ihtbtd_btd_test_condition_block_archive select * from staging2.ihtbtd_btd_test_condition_block; +insert into archive.ihtbtd_btd_test_res_1_block_archive select * from staging2.ihtbtd_btd_test_res_1_block; +insert into archive.ihtbtd_btd_test_res_2_block_archive select * from staging2.ihtbtd_btd_test_res_2_block; +insert into archive.ihtbtd_btd_test_res_3_block_archive select * from staging2.ihtbtd_btd_test_res_3_block; +insert into archive.ihtbtd_btd_test_res_4_block_archive select * from staging2.ihtbtd_btd_test_res_4_block; +insert into archive.ihtbtd_btd_test_res_5_block_archive select * from staging2.ihtbtd_btd_test_res_5_block; +insert into archive.ihtbtd_btd_test_res_6_block_archive select * from staging2.ihtbtd_btd_test_res_6_block; +insert into archive.ihtbtd_btd_tyre_details_block_archive select * from staging2.ihtbtd_btd_tyre_details_block; +insert into archive.ihtbtd_btd_weight_block_archive select * from staging2.ihtbtd_btd_weight_block; +insert into archive.ihtcgm_cgm_footer_block_archive select * from staging2.ihtcgm_cgm_footer_block; +insert into archive.ihtcgm_cgm_h1_block_archive select * from staging2.ihtcgm_cgm_h1_block; +insert into archive.ihtcgm_cgm_lifting_block_archive select * from staging2.ihtcgm_cgm_lifting_block; +insert into archive.ihtcgm_cgm_results_block_archive select * from staging2.ihtcgm_cgm_results_block; +insert into archive.ihtcgm_cgm_tyre_details_block_archive select * from staging2.ihtcgm_cgm_tyre_details_block; +insert into archive.ihtcgm_cgm_weight_block_archive select * from staging2.ihtcgm_cgm_weight_block; +insert into archive.ihtcgm_cgm_wheel_block_archive select * from staging2.ihtcgm_cgm_wheel_block; +insert into archive.ihtemt_emt_brake_pedal_block_archive select * from staging2.ihtemt_emt_brake_pedal_block; +insert into archive.ihtemt_emt_footer_block_archive select * from staging2.ihtemt_emt_footer_block; +insert into archive.ihtemt_emt_h1_block_archive select * from staging2.ihtemt_emt_h1_block; +insert into archive.ihtemt_emt_pedal_block_archive select * from staging2.ihtemt_emt_pedal_block; +insert into archive.ihtemt_emt_steering_block_archive select * from staging2.ihtemt_emt_steering_block; +insert into archive.ihtemt_emt_tyre_details_block_archive select * from staging2.ihtemt_emt_tyre_details_block; +insert into archive.ihtemt_emt_weight_block_archive select * from staging2.ihtemt_emt_weight_block; +insert into archive.ihtemt_emt_wheel_block_archive select * from staging2.ihtemt_emt_wheel_block; +insert into archive.ihtemt_std_raw_data_block_archive select * from staging2.ihtemt_std_raw_data_block; +insert into archive.ihtham_ham_atmos_cond_block_archive select * from staging2.ihtham_ham_atmos_cond_block; +insert into archive.ihtham_ham_drawbar_block_archive select * from staging2.ihtham_ham_drawbar_block; +insert into archive.ihtham_ham_engine_rpm_block_archive select * from staging2.ihtham_ham_engine_rpm_block; +insert into archive.ihtham_ham_footer_block_archive select * from staging2.ihtham_ham_footer_block; +insert into archive.ihtham_ham_h1_block_archive select * from staging2.ihtham_ham_h1_block; +insert into archive.ihtham_ham_results_block_archive select * from staging2.ihtham_ham_results_block; +insert into archive.ihtham_ham_tractor_block_archive select * from staging2.ihtham_ham_tractor_block; +insert into archive.ihtham_ham_tyre_details_block_archive select * from staging2.ihtham_ham_tyre_details_block; +insert into archive.ihtham_ham_weight_block_archive select * from staging2.ihtham_ham_weight_block; +insert into archive.ihthls_hls_footer_block_archive select * from staging2.ihthls_hls_footer_block; +insert into archive.ihthls_hls_h1_block_archive select * from staging2.ihthls_hls_h1_block; +insert into archive.ihthls_hls_numeric_block_archive select * from staging2.ihthls_hls_numeric_block; +insert into archive.ihthls_hls_tyre_details_block_archive select * from staging2.ihthls_hls_tyre_details_block; +insert into archive.ihthls_hls_weight_block_archive select * from staging2.ihthls_hls_weight_block; +insert into archive.ihthls_hls_wheel_block_archive select * from staging2.ihthls_hls_wheel_block; +insert into archive.ihtnst_nst_atmos_cond_block_archive select * from staging2.ihtnst_nst_atmos_cond_block; +insert into archive.ihtnst_nst_engine_rpm_block_archive select * from staging2.ihtnst_nst_engine_rpm_block; +insert into archive.ihtnst_nst_footer_block_archive select * from staging2.ihtnst_nst_footer_block; +insert into archive.ihtnst_nst_h1_block_archive select * from staging2.ihtnst_nst_h1_block; +insert into archive.ihtnst_nst_oel_noise_block_archive select * from staging2.ihtnst_nst_oel_noise_block; +insert into archive.ihtnst_nst_oel_noise_load_block_archive select * from staging2.ihtnst_nst_oel_noise_load_block; +insert into archive.ihtnst_nst_stand_noise_block_archive select * from staging2.ihtnst_nst_stand_noise_block; +insert into archive.ihtnst_nst_tyre_details_block_archive select * from staging2.ihtnst_nst_tyre_details_block; +insert into archive.ihtnst_nst_weight_block_archive select * from staging2.ihtnst_nst_weight_block; +insert into archive.ihtsll_sll_footer_block_archive select * from staging2.ihtsll_sll_footer_block; +insert into archive.ihtsll_sll_forward_block_archive select * from staging2.ihtsll_sll_forward_block; +insert into archive.ihtsll_sll_h1_block_archive select * from staging2.ihtsll_sll_h1_block; +insert into archive.ihtsll_sll_lead_lag_block_archive select * from staging2.ihtsll_sll_lead_lag_block; +insert into archive.ihtsll_sll_reverse_block_archive select * from staging2.ihtsll_sll_reverse_block; +insert into archive.ihtsll_sll_tyre_details_block_archive select * from staging2.ihtsll_sll_tyre_details_block; +insert into archive.ihtsll_sll_weight_block_archive select * from staging2.ihtsll_sll_weight_block; +insert into archive.ihtsll_sll_wheel_block_archive select * from staging2.ihtsll_sll_wheel_block; +insert into archive.ptoben_gvg_performance_governing_trails_block_archive select * from staging2.ptoben_gvg_performance_governing_trails_block; +insert into archive.ptoben_mpm_performance_boost_natural_block_archive select * from staging2.ptoben_mpm_performance_boost_natural_block; +insert into archive.ptoben_prf_2hrs_max_power_natural_ambient_block_archive select * from staging2.ptoben_prf_2hrs_max_power_natural_ambient_block; +insert into archive.ptoben_prf_2hrs_max_power_test_high_ambient_block_archive select * from staging2.ptoben_prf_2hrs_max_power_test_high_ambient_block; +insert into archive.ptoben_prf_engine_oil_consumption_block_archive select * from staging2.ptoben_prf_engine_oil_consumption_block; +insert into archive.ptoben_prf_key_performance_parameters_block_archive select * from staging2.ptoben_prf_key_performance_parameters_block; +insert into archive.ptoben_prf_smoke_test_block_archive select * from staging2.ptoben_prf_smoke_test_block; +insert into archive.ptoben_prf_tractor_specs_block_archive select * from staging2.ptoben_prf_tractor_specs_block; +insert into archive.ptoben_prf_varying_load_rated_rpm_block_archive select * from staging2.ptoben_prf_varying_load_rated_rpm_block; +insert into archive.ptoben_prf_varying_load_std_pto_block_archive select * from staging2.ptoben_prf_varying_load_std_pto_block; +insert into archive.ptoben_prf_varying_speed_natural_ambient_block_archive select * from staging2.ptoben_prf_varying_speed_natural_ambient_block; +insert into archive.ptoben_prf_varying_speed_test_high_ambient_block_archive select * from staging2.ptoben_prf_varying_speed_test_high_ambient_block; + + + + + + update fw_core.fw_jobctl_runschedule_jobstep set end_status_note = 'archive_function_completed', end_status='success',end_time= now() where job_id=__jobid and step_id=__stepid and latest_runschedule_flag='1'; + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'Archive', 'fn_block_archive', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +EXCEPTION when OTHERS then +GET STACKED DIAGNOSTICS + err_state = returned_sqlstate, /* P0002 */ + err_msg = message_text, /* No Data in FTDRY */ + err_detail = pg_exception_detail, /* No data in table t_test_new */ + err_hint = pg_exception_hint, /* No data error capture */ + err_context = pg_exception_context; /* PL/pgSQL function staging2.fn_ftdry_trs_block(integer,integer,text,text,integer) line 69 at RAISE*/ + + update fw_core.fw_jobctl_runschedule_jobstep set end_status_note = 'archive function failed', end_status='error' ,end_time= now() where job_id=6 and step_id=1 and latest_runschedule_flag='1'; + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'archive', 'fn_block_archive', err_state, err_msg, err_detail, err_hint, err_context,'error'); + +end +$$ LANGUAGE plpgsql; diff --git a/onetime/archive/schema/drop.sql b/onetime/archive/schema/drop.sql new file mode 100755 index 0000000..70bd8f9 --- /dev/null +++ b/onetime/archive/schema/drop.sql @@ -0,0 +1 @@ +drop schema if exists archive cascade; diff --git a/onetime/commonfunctions/fn_check_count.sql b/onetime/commonfunctions/fn_check_count.sql new file mode 100644 index 0000000..7e86c3f --- /dev/null +++ b/onetime/commonfunctions/fn_check_count.sql @@ -0,0 +1,335 @@ + +--drop function if exists fw_core.fn_run_check_count(); + +CREATE or REPLACE FUNCTION fw_core.fn_run_check_count(p_client_id int,p_function_id int,p_job_id int,p_step_id int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + + declare p_date date := now() - INTERVAL '5min'; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text := null; + declare __file_sheet_mnemonic text :=null; + declare __file_syspk int := null; + declare __jobid int := p_job_id; + declare __stepid int := p_step_id; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + + + begin +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'budni_brake_perf_parking_brake_test_results',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.budni_brake_perf_parking_brake_test_results a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'budni_brake_perf_service_brake_test_results',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.budni_brake_perf_service_brake_test_results a where a.create_timestamp::timestamp >=p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'budni_centre_of_gravity_location',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.budni_centre_of_gravity_location a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'budni_drawbar_perf_results',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.budni_drawbar_perf_results a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'budni_field_perf_results',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.budni_field_perf_results a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'budni_haulage_perf_results',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.budni_haulage_perf_results a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'budni_hydraulic_lifting_capacity_test_results',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.budni_hydraulic_lifting_capacity_test_results a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'budni_hydraulic_maint_of_lift_load_results',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.budni_hydraulic_maint_of_lift_load_results a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'budni_hydraulic_power_test_results',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.budni_hydraulic_power_test_results a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'budni_noise_atmospheric_conditions',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.budni_noise_atmospheric_conditions a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'budni_noise_measurement_results',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.budni_noise_measurement_results a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'budni_pto_perf_results_details',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.budni_pto_perf_results_details a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'budni_pto_perf_results_summary',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.budni_pto_perf_results_summary a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'budni_test_observations',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.budni_test_observations a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'budni_vibration_measurement',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.budni_vibration_measurement a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'drawbar_perf_observations',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.drawbar_perf_observations a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'drawbar_perf_oecd_results',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.drawbar_perf_oecd_results a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'drawbar_perf_results',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.drawbar_perf_results a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'drawbar_perf_results_summary',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.drawbar_perf_results_summary a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'field_perf_summary',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.field_perf_summary a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +--insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'field_perf_summary_implement_info',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.field_perf_summary_implement_info a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'field_perf_summary_tractor_info',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.field_perf_summary_tractor_info a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +--insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'field_perf_summary_trailer_info',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.field_perf_summary_trailer_info a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'iht_brake_pedal_effort',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.iht_brake_pedal_effort a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'iht_brake_perf_test_condition',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.iht_brake_perf_test_condition a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'iht_brake_perf_test_results',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.iht_brake_perf_test_results a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'iht_cgm_lifting_angle_load_details',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.iht_cgm_lifting_angle_load_details a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'iht_cgm_results',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.iht_cgm_results a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'iht_clutch_pedal_effort',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.iht_clutch_pedal_effort a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'iht_gear_effort',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.iht_gear_effort a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'iht_gear_max_speed',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.iht_gear_max_speed a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'iht_hot_air_mapping_results',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.iht_hot_air_mapping_results a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'iht_hyd_lift_sensitivity',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.iht_hyd_lift_sensitivity a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'iht_noise_measurement_results',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.iht_noise_measurement_results a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'iht_noise_measurement_test',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.iht_noise_measurement_test a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'iht_pedal_effort',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.iht_pedal_effort a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'iht_speed_lead_lag_measurement',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.iht_speed_lead_lag_measurement a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'iht_steering_effort',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.iht_steering_effort a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'iht_steering_effort_raw_data',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.iht_steering_effort_raw_data a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'pto_engine_oil_consumption',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.pto_engine_oil_consumption a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'pto_key_perf_parameters',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.pto_key_perf_parameters a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'pto_multipoint_mapping',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.pto_multipoint_mapping a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'pto_perf_governing_graph',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.pto_perf_governing_graph a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'pto_perf_results',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.pto_perf_results a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'pto_smoke_test',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.pto_smoke_test a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'test_instance',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.test_instance a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'test_instance_atmospheric_info',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.test_instance_atmospheric_info a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'test_instance_drawbar_info',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.test_instance_drawbar_info a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'test_instance_engine_info',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.test_instance_engine_info a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'test_instance_equipment_info',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.test_instance_equipment_info a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'test_instance_fuel_lubricant_info',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.test_instance_fuel_lubricant_info a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'test_instance_gear_speed_chart',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.test_instance_gear_speed_chart a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +--insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'test_instance_images',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.test_instance_images a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +--insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'test_instance_implement_info',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.test_instance_implement_info a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'test_instance_measurement_uncertainty',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.test_instance_measurement_uncertainty a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'test_instance_tractor_info',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.test_instance_tractor_info a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'test_instance_tractor_info_misc',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.test_instance_tractor_info_misc a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +--insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'test_instance_trailer_info',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.test_instance_trailer_info a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'test_instance_tyre_info',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.test_instance_tyre_info a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'test_instance_weight_reaction',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.test_instance_weight_reaction a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; +insert into fw_core.check_model_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,tractor_name,row_count) select 'test_instance_wheels_info',file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model,count(*) from transactional.test_instance_wheels_info a where a.create_timestamp::timestamp >= p_date group by file_syspk,file_mnemonic,file_sheet_mnemonic,tractor_model; + + + +insert into fw_core.check_mnemonic_count(table_name,syspks,file_mnemonic,file_sheet_mnemonic,row_count) +SELECT table_name, syspks, file_mnemonic, file_sheet_mnemonic,sum(row_count) +FROM fw_core.check_model_count +where create_timestamp::timestamp >= p_date +group by table_name, syspks, file_mnemonic, file_sheet_mnemonic; + + + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_arc_perf_atmos_meas_test_block',count(*) from staging2.budni_arc_perf_atmos_meas_test_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_arc_spec_h1_block',count(*) from staging2.budni_arc_spec_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_arc_test_obs_summary_block',count(*) from staging2.budni_arc_test_obs_summary_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_brk_other_observations_block',count(*) from staging2.budni_brk_other_observations_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_brk_parking_barke_test_block',count(*) from staging2.budni_brk_parking_barke_test_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_brk_service_cold_ballasted_25kmph_block',count(*) from staging2.budni_brk_service_cold_ballasted_25kmph_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_brk_service_cold_ballasted_maximum_block',count(*) from staging2.budni_brk_service_cold_ballasted_maximum_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_brk_service_cold_standard_25kmph_block',count(*) from staging2.budni_brk_service_cold_standard_25kmph_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_brk_service_cold_standard_maximum_block',count(*) from staging2.budni_brk_service_cold_standard_maximum_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_brk_service_fade_ballasted_25kmph_block',count(*) from staging2.budni_brk_service_fade_ballasted_25kmph_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_brk_service_fade_standard_maximum_block',count(*) from staging2.budni_brk_service_fade_standard_maximum_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_brk_spec_h1_block',count(*) from staging2.budni_brk_spec_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_brk_test_obs_summary_block',count(*) from staging2.budni_brk_test_obs_summary_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_dbp_drawbar_perf_block',count(*) from staging2.budni_dbp_drawbar_perf_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_dbp_spec_h1_block',count(*) from staging2.budni_dbp_spec_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_fld_cage_wheel_block',count(*) from staging2.budni_fld_cage_wheel_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_fld_impl_test_block',count(*) from staging2.budni_fld_impl_test_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_fld_spec_h1_block',count(*) from staging2.budni_fld_spec_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_fld_sum_perf_test_block',count(*) from staging2.budni_fld_sum_perf_test_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_fld_test_obs_summary_block',count(*) from staging2.budni_fld_test_obs_summary_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_hdl_lifting_capacity_test_block',count(*) from staging2.budni_hdl_lifting_capacity_test_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_hdl_maintenance_of_lift_load_block',count(*) from staging2.budni_hdl_maintenance_of_lift_load_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_hdl_power_test_block',count(*) from staging2.budni_hdl_power_test_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_hdl_spec_h1_block',count(*) from staging2.budni_hdl_spec_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_hdl_test_obs_summary_block',count(*) from staging2.budni_hdl_test_obs_summary_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_hlg_perf_test_block',count(*) from staging2.budni_hlg_perf_test_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_hlg_spec_h1_block',count(*) from staging2.budni_hlg_spec_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_hlg_test_obs_summary_block',count(*) from staging2.budni_hlg_test_obs_summary_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_lcg_gravity_test_block',count(*) from staging2.budni_lcg_gravity_test_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_lcg_spec_h1_block',count(*) from staging2.budni_lcg_spec_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_nmt_atmos_cond_2_block',count(*) from staging2.budni_nmt_atmos_cond_2_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_nmt_meas_results_1_block',count(*) from staging2.budni_nmt_meas_results_1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_nmt_meas_results_2_block',count(*) from staging2.budni_nmt_meas_results_2_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_nmt_noise_at_bystander_position_block',count(*) from staging2.budni_nmt_noise_at_bystander_position_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_nmt_noise_at_operator_ear_level_block',count(*) from staging2.budni_nmt_noise_at_operator_ear_level_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_nmt_spec_h1_block',count(*) from staging2.budni_nmt_spec_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_nmt_test_obs_summary_block',count(*) from staging2.budni_nmt_test_obs_summary_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_pto_mmtkeyword1_block',count(*) from staging2.budni_pto_mmtkeyword1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_pto_mmtkeyword2_block',count(*) from staging2.budni_pto_mmtkeyword2_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_pto_perf_report_block',count(*) from staging2.budni_pto_perf_report_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_pto_spec_h1_block',count(*) from staging2.budni_pto_spec_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_pto_summary_block',count(*) from staging2.budni_pto_summary_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_vmt_perf_meas_test_block',count(*) from staging2.budni_vmt_perf_meas_test_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_vmt_spec_h1_block',count(*) from staging2.budni_vmt_spec_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','budni_vmt_test_obs_summary_block',count(*) from staging2.budni_vmt_test_obs_summary_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dboecd_test_drawbar_performance_fuel_consumption_block',count(*) from staging2.dboecd_test_drawbar_performance_fuel_consumption_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dboecd_test_drawbar_performance_gear_performance_block',count(*) from staging2.dboecd_test_drawbar_performance_gear_performance_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dboecd_test_drawbar_performance_selected_summary_block',count(*) from staging2.dboecd_test_drawbar_performance_selected_summary_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dboecd_test_engine_rpm_engine_to_pto_block',count(*) from staging2.dboecd_test_engine_rpm_engine_to_pto_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dboecd_test_engine_rpm_required_pull_block',count(*) from staging2.dboecd_test_engine_rpm_required_pull_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dboecd_test_engine_rpm_rpm_block',count(*) from staging2.dboecd_test_engine_rpm_rpm_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dboecd_test_engine_rpm_tyre_details_block',count(*) from staging2.dboecd_test_engine_rpm_tyre_details_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dboecd_test_engine_rpm_weight_block',count(*) from staging2.dboecd_test_engine_rpm_weight_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dboecd_test_h1_block',count(*) from staging2.dboecd_test_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dboecd_test_measurement_uncertainty_block',count(*) from staging2.dboecd_test_measurement_uncertainty_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dboecd_test_remarks_block',count(*) from staging2.dboecd_test_remarks_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dboecd_test_remarks_footer_block',count(*) from staging2.dboecd_test_remarks_footer_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dboecd_test_test_condition_block',count(*) from staging2.dboecd_test_test_condition_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dboecd_test_test_equipment_used_block',count(*) from staging2.dboecd_test_test_equipment_used_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dboecd_test_tractor_specifications_cleaner_block',count(*) from staging2.dboecd_test_tractor_specifications_cleaner_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dboecd_test_tractor_specifications_cylinders_block',count(*) from staging2.dboecd_test_tractor_specifications_cylinders_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dboecd_test_tractor_specifications_engine_details_block',count(*) from staging2.dboecd_test_tractor_specifications_engine_details_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dboecd_test_tractor_specifications_fuel_and_injection_block',count(*) from staging2.dboecd_test_tractor_specifications_fuel_and_injection_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dboecd_test_transmission_clutch_block',count(*) from staging2.dboecd_test_transmission_clutch_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dboecd_test_transmission_drawbar_block',count(*) from staging2.dboecd_test_transmission_drawbar_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dboecd_test_transmission_fuel_lubricant_block',count(*) from staging2.dboecd_test_transmission_fuel_lubricant_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dboecd_test_transmission_speed_chart_block',count(*) from staging2.dboecd_test_transmission_speed_chart_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dboecd_test_transmission_speed_chart_desc_block',count(*) from staging2.dboecd_test_transmission_speed_chart_desc_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dboecd_test_transmission_wheels_block',count(*) from staging2.dboecd_test_transmission_wheels_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dbstd_test_drawbar_performance_gear_performance_block',count(*) from staging2.dbstd_test_drawbar_performance_gear_performance_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dbstd_test_drawbar_performance_selected_summary_block',count(*) from staging2.dbstd_test_drawbar_performance_selected_summary_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dbstd_test_engine_rpm_engine_to_pto_block',count(*) from staging2.dbstd_test_engine_rpm_engine_to_pto_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dbstd_test_engine_rpm_required_pull_block',count(*) from staging2.dbstd_test_engine_rpm_required_pull_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dbstd_test_engine_rpm_rpm_block',count(*) from staging2.dbstd_test_engine_rpm_rpm_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dbstd_test_engine_rpm_tyre_details_block',count(*) from staging2.dbstd_test_engine_rpm_tyre_details_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dbstd_test_engine_rpm_weight_block',count(*) from staging2.dbstd_test_engine_rpm_weight_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dbstd_test_h1_block',count(*) from staging2.dbstd_test_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dbstd_test_measurement_uncertainty_block',count(*) from staging2.dbstd_test_measurement_uncertainty_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dbstd_test_remarks_block',count(*) from staging2.dbstd_test_remarks_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dbstd_test_remarks_footer_block',count(*) from staging2.dbstd_test_remarks_footer_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dbstd_test_test_condition_block',count(*) from staging2.dbstd_test_test_condition_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dbstd_test_test_equipment_used_block',count(*) from staging2.dbstd_test_test_equipment_used_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dbstd_test_tractor_specifications_cleaner_block',count(*) from staging2.dbstd_test_tractor_specifications_cleaner_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dbstd_test_tractor_specifications_cylinders_block',count(*) from staging2.dbstd_test_tractor_specifications_cylinders_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dbstd_test_tractor_specifications_engine_details_block',count(*) from staging2.dbstd_test_tractor_specifications_engine_details_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dbstd_test_tractor_specifications_fuel_and_injection_block',count(*) from staging2.dbstd_test_tractor_specifications_fuel_and_injection_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dbstd_test_transmission_clutch_block',count(*) from staging2.dbstd_test_transmission_clutch_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dbstd_test_transmission_drawbar_block',count(*) from staging2.dbstd_test_transmission_drawbar_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dbstd_test_transmission_fuel_lubricant_block',count(*) from staging2.dbstd_test_transmission_fuel_lubricant_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dbstd_test_transmission_speed_chart_block',count(*) from staging2.dbstd_test_transmission_speed_chart_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dbstd_test_transmission_speed_chart_desc_block',count(*) from staging2.dbstd_test_transmission_speed_chart_desc_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','dbstd_test_transmission_wheels_block',count(*) from staging2.dbstd_test_transmission_wheels_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ftdry_sum_comments_by_block',count(*) from staging2.ftdry_sum_comments_by_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ftdry_sum_implement_block',count(*) from staging2.ftdry_sum_implement_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ftdry_sum_test_condition_1_block',count(*) from staging2.ftdry_sum_test_condition_1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ftdry_sum_test_condition_2_block',count(*) from staging2.ftdry_sum_test_condition_2_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ftdry_sum_trac_h1_block',count(*) from staging2.ftdry_sum_trac_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ftdry_trs_engine_rpm_block',count(*) from staging2.ftdry_trs_engine_rpm_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ftdry_trs_h1_block',count(*) from staging2.ftdry_trs_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ftdry_trs_implement_block',count(*) from staging2.ftdry_trs_implement_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ftdry_trs_spec_block',count(*) from staging2.ftdry_trs_spec_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','fthlg_sum_comments_by_block',count(*) from staging2.fthlg_sum_comments_by_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','fthlg_sum_test_condition_1_block',count(*) from staging2.fthlg_sum_test_condition_1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','fthlg_sum_test_condition_2_block',count(*) from staging2.fthlg_sum_test_condition_2_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','fthlg_sum_trac_h1_block',count(*) from staging2.fthlg_sum_trac_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','fthlg_sum_trail_type_block',count(*) from staging2.fthlg_sum_trail_type_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','fthlg_trs_engine_rpm_block',count(*) from staging2.fthlg_trs_engine_rpm_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','fthlg_trs_h1_block',count(*) from staging2.fthlg_trs_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','fthlg_trs_spec_block',count(*) from staging2.fthlg_trs_spec_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','fthlg_trs_trailer_block',count(*) from staging2.fthlg_trs_trailer_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ftwet_sum_cage_wheel_block',count(*) from staging2.ftwet_sum_cage_wheel_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ftwet_sum_comments_by_block',count(*) from staging2.ftwet_sum_comments_by_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ftwet_sum_implement_block',count(*) from staging2.ftwet_sum_implement_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ftwet_sum_test_condition_block',count(*) from staging2.ftwet_sum_test_condition_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ftwet_sum_trac_h1_block',count(*) from staging2.ftwet_sum_trac_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ftwet_trs_engine_rpm_block',count(*) from staging2.ftwet_trs_engine_rpm_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ftwet_trs_h1_block',count(*) from staging2.ftwet_trs_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ftwet_trs_implement_block',count(*) from staging2.ftwet_trs_implement_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ftwet_trs_spec_block',count(*) from staging2.ftwet_trs_spec_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbt30_bt30_footer_block',count(*) from staging2.ihtbt30_bt30_footer_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbt30_bt30_h1_block',count(*) from staging2.ihtbt30_bt30_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbt30_bt30_test_condition_block',count(*) from staging2.ihtbt30_bt30_test_condition_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbt30_bt30_test_res_1_block',count(*) from staging2.ihtbt30_bt30_test_res_1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbt30_bt30_test_res_2_block',count(*) from staging2.ihtbt30_bt30_test_res_2_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbt30_bt30_test_res_3_block',count(*) from staging2.ihtbt30_bt30_test_res_3_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbt30_bt30_test_res_4_block',count(*) from staging2.ihtbt30_bt30_test_res_4_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbt30_bt30_tyre_details_block',count(*) from staging2.ihtbt30_bt30_tyre_details_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbt30_bt30_weight_block',count(*) from staging2.ihtbt30_bt30_weight_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbt50_bt50_footer_block',count(*) from staging2.ihtbt50_bt50_footer_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbt50_bt50_h1_block',count(*) from staging2.ihtbt50_bt50_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbt50_bt50_test_condition_block',count(*) from staging2.ihtbt50_bt50_test_condition_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbt50_bt50_test_res_1_block',count(*) from staging2.ihtbt50_bt50_test_res_1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbt50_bt50_test_res_2_block',count(*) from staging2.ihtbt50_bt50_test_res_2_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbt50_bt50_test_res_3_block',count(*) from staging2.ihtbt50_bt50_test_res_3_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbt50_bt50_test_res_4_block',count(*) from staging2.ihtbt50_bt50_test_res_4_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbt50_bt50_tyre_details_block',count(*) from staging2.ihtbt50_bt50_tyre_details_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbt50_bt50_weight_block',count(*) from staging2.ihtbt50_bt50_weight_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbtd_btd_footer_block',count(*) from staging2.ihtbtd_btd_footer_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbtd_btd_h1_block',count(*) from staging2.ihtbtd_btd_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbtd_btd_test_condition_block',count(*) from staging2.ihtbtd_btd_test_condition_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbtd_btd_test_res_1_block',count(*) from staging2.ihtbtd_btd_test_res_1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbtd_btd_test_res_2_block',count(*) from staging2.ihtbtd_btd_test_res_2_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbtd_btd_test_res_3_block',count(*) from staging2.ihtbtd_btd_test_res_3_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbtd_btd_test_res_4_block',count(*) from staging2.ihtbtd_btd_test_res_4_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbtd_btd_test_res_5_block',count(*) from staging2.ihtbtd_btd_test_res_5_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbtd_btd_test_res_6_block',count(*) from staging2.ihtbtd_btd_test_res_6_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbtd_btd_tyre_details_block',count(*) from staging2.ihtbtd_btd_tyre_details_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtbtd_btd_weight_block',count(*) from staging2.ihtbtd_btd_weight_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtcgm_cgm_footer_block',count(*) from staging2.ihtcgm_cgm_footer_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtcgm_cgm_h1_block',count(*) from staging2.ihtcgm_cgm_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtcgm_cgm_lifting_block',count(*) from staging2.ihtcgm_cgm_lifting_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtcgm_cgm_results_block',count(*) from staging2.ihtcgm_cgm_results_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtcgm_cgm_tyre_details_block',count(*) from staging2.ihtcgm_cgm_tyre_details_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtcgm_cgm_weight_block',count(*) from staging2.ihtcgm_cgm_weight_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtcgm_cgm_wheel_block',count(*) from staging2.ihtcgm_cgm_wheel_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtemt_emt_brake_pedal_block',count(*) from staging2.ihtemt_emt_brake_pedal_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtemt_emt_footer_block',count(*) from staging2.ihtemt_emt_footer_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtemt_emt_h1_block',count(*) from staging2.ihtemt_emt_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtemt_emt_pedal_block',count(*) from staging2.ihtemt_emt_pedal_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtemt_emt_steering_block',count(*) from staging2.ihtemt_emt_steering_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtemt_emt_tyre_details_block',count(*) from staging2.ihtemt_emt_tyre_details_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtemt_emt_weight_block',count(*) from staging2.ihtemt_emt_weight_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtemt_emt_wheel_block',count(*) from staging2.ihtemt_emt_wheel_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtemt_std_raw_data_block',count(*) from staging2.ihtemt_std_raw_data_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtham_ham_atmos_cond_block',count(*) from staging2.ihtham_ham_atmos_cond_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtham_ham_drawbar_block',count(*) from staging2.ihtham_ham_drawbar_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtham_ham_engine_rpm_block',count(*) from staging2.ihtham_ham_engine_rpm_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtham_ham_footer_block',count(*) from staging2.ihtham_ham_footer_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtham_ham_h1_block',count(*) from staging2.ihtham_ham_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtham_ham_results_block',count(*) from staging2.ihtham_ham_results_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtham_ham_tractor_block',count(*) from staging2.ihtham_ham_tractor_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtham_ham_tyre_details_block',count(*) from staging2.ihtham_ham_tyre_details_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtham_ham_weight_block',count(*) from staging2.ihtham_ham_weight_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihthls_hls_footer_block',count(*) from staging2.ihthls_hls_footer_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihthls_hls_h1_block',count(*) from staging2.ihthls_hls_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihthls_hls_numeric_block',count(*) from staging2.ihthls_hls_numeric_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihthls_hls_tyre_details_block',count(*) from staging2.ihthls_hls_tyre_details_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihthls_hls_weight_block',count(*) from staging2.ihthls_hls_weight_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihthls_hls_wheel_block',count(*) from staging2.ihthls_hls_wheel_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtnst_nst_atmos_cond_block',count(*) from staging2.ihtnst_nst_atmos_cond_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtnst_nst_engine_rpm_block',count(*) from staging2.ihtnst_nst_engine_rpm_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtnst_nst_footer_block',count(*) from staging2.ihtnst_nst_footer_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtnst_nst_h1_block',count(*) from staging2.ihtnst_nst_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtnst_nst_oel_noise_block',count(*) from staging2.ihtnst_nst_oel_noise_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtnst_nst_oel_noise_load_block',count(*) from staging2.ihtnst_nst_oel_noise_load_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtnst_nst_stand_noise_block',count(*) from staging2.ihtnst_nst_stand_noise_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtnst_nst_tyre_details_block',count(*) from staging2.ihtnst_nst_tyre_details_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtnst_nst_weight_block',count(*) from staging2.ihtnst_nst_weight_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtsll_sll_footer_block',count(*) from staging2.ihtsll_sll_footer_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtsll_sll_forward_block',count(*) from staging2.ihtsll_sll_forward_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtsll_sll_h1_block',count(*) from staging2.ihtsll_sll_h1_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtsll_sll_lead_lag_block',count(*) from staging2.ihtsll_sll_lead_lag_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtsll_sll_reverse_block',count(*) from staging2.ihtsll_sll_reverse_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtsll_sll_tyre_details_block',count(*) from staging2.ihtsll_sll_tyre_details_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtsll_sll_weight_block',count(*) from staging2.ihtsll_sll_weight_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ihtsll_sll_wheel_block',count(*) from staging2.ihtsll_sll_wheel_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ptoben_gvg_performance_governing_trails_block',count(*) from staging2.ptoben_gvg_performance_governing_trails_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ptoben_mpm_performance_boost_natural_block',count(*) from staging2.ptoben_mpm_performance_boost_natural_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ptoben_prf_2hrs_max_power_natural_ambient_block',count(*) from staging2.ptoben_prf_2hrs_max_power_natural_ambient_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ptoben_prf_2hrs_max_power_test_high_ambient_block',count(*) from staging2.ptoben_prf_2hrs_max_power_test_high_ambient_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ptoben_prf_engine_oil_consumption_block',count(*) from staging2.ptoben_prf_engine_oil_consumption_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ptoben_prf_key_performance_parameters_block',count(*) from staging2.ptoben_prf_key_performance_parameters_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ptoben_prf_smoke_test_block',count(*) from staging2.ptoben_prf_smoke_test_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ptoben_prf_tractor_specs_block',count(*) from staging2.ptoben_prf_tractor_specs_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ptoben_prf_varying_load_rated_rpm_block',count(*) from staging2.ptoben_prf_varying_load_rated_rpm_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ptoben_prf_varying_load_std_pto_block',count(*) from staging2.ptoben_prf_varying_load_std_pto_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ptoben_prf_varying_speed_natural_ambient_block',count(*) from staging2.ptoben_prf_varying_speed_natural_ambient_block where create_time::timestamp >= p_date; + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) select 'staging2','ptoben_prf_varying_speed_test_high_ambient_block',count(*) from staging2.ptoben_prf_varying_speed_test_high_ambient_block where create_time::timestamp >= p_date; + + insert into fw_core.check_table_stg_trx_count(schema_name,table_name,row_count) + select 'transactional',table_name, sum(row_count) + from fw_core.check_model_count + where create_timestamp::timestamp >= p_date + group by table_name; + + + + + update fw_core.fw_jobctl_runschedule_jobstep set end_status_note = 'check_count_completed', end_status='success',end_time= now() where job_id=__jobid and step_id=__stepid and latest_runschedule_flag='1'; +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'Check_Count', 'fn_check_count', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +EXCEPTION when OTHERS then + + err_state = returned_sqlstate, /* P0002 */ + err_msg = message_text, /* No Data in FTDRY */ + err_detail = pg_exception_detail, /* No data in table t_test_new */ + err_hint = pg_exception_hint, /* No data error capture */ + err_context = pg_exception_context; /* PL/pgSQL function staging2.fn_ftdry_trs_block(integer,integer,text,text,integer) line 69 at RAISE*/ + + update fw_core.fw_jobctl_runschedule_jobstep set end_status_note = 'check count failed', end_status='error' ,end_time= now() where job_id=__jobid and step_id=__stepid and latest_runschedule_flag='1'; + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'Check_Count', 'fn_check_count', err_state, err_msg, err_detail, err_hint, err_context,'error'); + + + +end +$function$ +; + + diff --git a/onetime/commonfunctions/fn_db_exception.sql b/onetime/commonfunctions/fn_db_exception.sql new file mode 100755 index 0000000..b043d4a --- /dev/null +++ b/onetime/commonfunctions/fn_db_exception.sql @@ -0,0 +1,61 @@ +drop function if exists fw_core.fn_get_function_exception; +CREATE OR REPLACE FUNCTION fw_core.fn_get_function_exception(p_function_name text) + RETURNS void + LANGUAGE plpgsql +AS $function$ + + declare __client_id int ; + declare __function_id int ; + declare __file_mnemonic text ; + declare __file_sheet_mnemonic text ; + declare __file_syspk int ; + declare __fname text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare function_query text; + declare err_function text; + declare v_function_parameter text; + declare v_function_name text; + declare v_function_name_len int; + declare v_pos_ind int; + +begin + +function_query := 'select ' || p_function_name; +select length(p_function_name) into v_function_name_len; +select position('(' in p_function_name) into v_pos_ind; +select substring(p_function_name,0, v_pos_ind) into v_function_name; +select substring(p_function_name, v_pos_ind + 1, v_function_name_len - v_pos_ind - 1) into v_function_parameter; + +select SPLIT_PART(v_function_parameter,',',1) into __client_id; +select SPLIT_PART(v_function_parameter,',',2) into __function_id; +select SPLIT_PART(v_function_parameter,',',3) into __file_mnemonic; +select SPLIT_PART(v_function_parameter,',',4) into __file_sheet_mnemonic; +select SPLIT_PART(v_function_parameter,',',5) into __file_syspk; +select trim('''' from __file_mnemonic) into __file_mnemonic; +select trim('''' from __file_sheet_mnemonic) into __file_sheet_mnemonic; + +execute function_query; +/* staging2.fn_FTDRY_TRS_Block(20,1,'FTDRY','FTDRY_TRS',100) */ + +EXCEPTION when OTHERS then + +GET STACKED DIAGNOSTICS + err_state = returned_sqlstate, /* P0002 */ + err_msg = message_text, /* No Data in FTDRY */ + err_detail = pg_exception_detail, /* No data in table t_test_new */ + err_hint = pg_exception_hint, /* No data error capture */ + err_context = pg_exception_context; /* PL/pgSQL function staging2.fn_ftdry_trs_block(integer,integer,text,text,integer) line 69 at RAISE +SQL statement "select staging2.fn_FTDRY_TRS_Block(20,1,'FTDRY','FTDRY_TRS',100)" +PL/pgSQL function trx.fn_get_function_exception(character varying) line 36 at EXECUTE */ + +if v_function_name like '%Block%' then +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,v_function_name,'stg2', null, err_state, err_msg, err_detail, err_hint, err_context,'error'); +else +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,v_function_name,'trx', null, err_state, err_msg, err_detail, err_hint, err_context,'error'); +end if; +END; +$function$ \ No newline at end of file diff --git a/onetime/commonfunctions/fn_db_status.sql b/onetime/commonfunctions/fn_db_status.sql new file mode 100755 index 0000000..19f29e5 --- /dev/null +++ b/onetime/commonfunctions/fn_db_status.sql @@ -0,0 +1,25 @@ +DROP FUNCTION IF EXISTS fw_core.fn_insert_DB_error; + CREATE OR REPLACE FUNCTION fw_core.fn_insert_db_error( clientId int, functionId int, userId int, userName varchar, fileSyspk int, + fileFormat varchar,sheetMnemonic varchar,blockName varchar,stagType varchar, eFunction varchar, eState varchar, eMessage varchar, eDetail varchar, eHint varchar,eContext varchar, sta varchar) + RETURNS text AS $$ + DECLARE + _message_text text; + _returned_sqlstate text; + BEGIN + BEGIN + INSERT INTO fw_core.DB_Run_Status ( client_Id, function_id, user_id, user_name, file_syspk, file_mnemonic, file_sheet_mnemonic, block_name, staging_type, error_function, error_state, error_message, error_detail, error_hint, error_context,status) + values ( clientId, functionId, userID, userName, fileSyspk, fileFormat, sheetMnemonic, blockName, stagType, eFunction, eState, eMessage, eDetail, eHInt, eContext, sta ); + + EXCEPTION when OTHERS THEN + _message_text := ''; + _returned_sqlstate := ''; + + GET STACKED DIAGNOSTICS + _message_text = MESSAGE_TEXT, + _returned_sqlstate = RETURNED_SQLSTATE; + + RETURN 'Failed: DB Error Creation : ' || _returned_sqlstate || ' : ' || _message_text; + END; + RETURN 'Success: DB Error Creation '; + END + $$ LANGUAGE plpgsql; diff --git a/onetime/commonfunctions/fn_info_column_dq.sql b/onetime/commonfunctions/fn_info_column_dq.sql new file mode 100755 index 0000000..08ce73c --- /dev/null +++ b/onetime/commonfunctions/fn_info_column_dq.sql @@ -0,0 +1,69 @@ +--drop function if exists fn_info_column_dq(); + +CREATE OR REPLACE function fn_info_column_dq(schemaname text) + RETURNS void AS $$ + declare + statements text; + begin +/************************************************************ +Function Name:fn_info_column_dq +Function Desc: This function populates data into given schema. This function creates temporary table which stores SQL queires + and later through for loop each temporary sql statement is executed. +Function concept: uses concat method to create a insert statement, 2 different statements are provided (choose any). +Creation Date: 06-June-2021 +Updation Date: +Author: compegence team +Function Call: select fn_info_column_dq('transactional'); +Data Access: select * from info_column_dq; +***************************************************************/ + -- Accessing information from information_schema and computing the required data + -- Storing the data in config db table + -- Execute this if the table does not exits or when the db is new +execute 'SET search_path to '''||schemaname||''''; + + DROP table if exists info_column_dq; + create table info_column_dq ( + table_schema text null, + table_name text NULL, + column_name text NULL, + column_data_type text NULL, + column_unique_count int null, + column_min_value text null, + column_max_value text null, + column_null_count int null, + create_timestamp timestamp not NULL DEFAULT CURRENT_TIMESTAMP +); +-- Temporary table to store queries : create + --drop table if exists queries; + create temp table queries (sqlquery text null); +-- Temporary table to store queries : insert data + insert into queries(sqlquery) + select +-- without using time-stamp::Date: + concat('insert into info_column_dq(table_schema,table_name,column_name,column_data_type,column_unique_count,column_min_value,column_max_value,column_null_count) select ''',c.table_schema,''',''',c.table_name,''',''', c.column_name,''',''', c.data_type,''',','count(distinct ',c.column_name,'),','min(',c.column_name,'),','max(',c.column_name,'),','SUM(CASE WHEN ',c.column_name ,' IS NULL THEN 1 ELSE 0 END) from ',c.table_schema,'.',c.table_name,';') +-- with using time-stamp::Date: + --concat('insert into info_column_dq(table_schema,table_name,column_name,column_data_type,column_unique_count,column_min_value,column_max_value,column_null_count) select ''',c.table_schema,''',''',c.table_name,''',''', c.column_name,''',''', c.data_type,''',','count(distinct ',c.column_name,'),','min(',c.column_name,'),','max(',c.column_name,'),','SUM(CASE WHEN ',c.column_name ,' IS NULL THEN 1 ELSE 0 END) from ',c.table_schema,'.',c.table_name,' where create_timestamp :: date >= now() ::Date;') + from information_schema."columns" c + where c.table_schema in (''||schemaname||'') + and c.table_name != 'info_column_dq' + and not c.data_type in ('bytea','boolean'); + --and c.table_name !='test_instance_images' + --and not c.column_name in ('create_timestamp','update_timestamp'); +-- executing the stored queries from temporary queries table: Loop the column data and execute each statement + for statements in select sqlquery from queries + loop + execute(statements); + end loop; +end; +$$ LANGUAGE plpgsql; + + + + + +/* +select fn_info_column_dq('transactional'); +select * from info_column_dq; +--gives error +--insert into fw_core.info_column_dq(table_schema,table_name,column_name,column_data_type,column_unique_count,column_min_value,column_max_value) select 'transactional','test_instance_images','image','bytea',count(distinct image),min(image),max(image) from transactional.test_instance_images; +*/ \ No newline at end of file diff --git a/onetime/commonfunctions/fn_jobctl_block_begin.sql b/onetime/commonfunctions/fn_jobctl_block_begin.sql new file mode 100755 index 0000000..30f66bf --- /dev/null +++ b/onetime/commonfunctions/fn_jobctl_block_begin.sql @@ -0,0 +1,14 @@ +drop function if exists fw_core.fn_jobctl_block_begin; +CREATE OR REPLACE FUNCTION fw_core.fn_jobctl_block_begin(p_client_id int,p_function_id int,p_file_syspk int,p_block_table_name text,p_file_mnemonic text,p_file_sheet_mnemonic text,p_block_seq int) + RETURNS void AS $$ +begin + +/************************* +select staging2.fn_jobctrl_block_begin(1,2,255,'block1','file','sheet',1) +***********************/ + +execute 'insert into fw_core.fw_jobctl_file_sheet_block_run_schedule +(client_id,function_id,file_syspk,block_table_name,file_mnemonic,file_sheet_mnemonic,begin_status,block_table_load_seq,start_time) + select '||p_client_id||', '||p_function_id||', '''||p_file_syspk||''','''||p_block_table_name||''','''||p_file_mnemonic||''','''||p_file_sheet_mnemonic||''',1,'||p_block_seq||',current_timestamp'; +end +$$ LANGUAGE plpgsql; diff --git a/onetime/commonfunctions/fn_jobctl_block_end.sql b/onetime/commonfunctions/fn_jobctl_block_end.sql new file mode 100755 index 0000000..eeb6d6f --- /dev/null +++ b/onetime/commonfunctions/fn_jobctl_block_end.sql @@ -0,0 +1,14 @@ +drop function if exists fw_core.fn_jobctl_block_end; +CREATE OR REPLACE FUNCTION fw_core.fn_jobctl_block_end(p_file_syspk int,p_block_table_name text) + RETURNS void AS $$ +begin + +/********************************* +select staging2.fn_jobctrl_block_end(255,'block1') +*********************************/ + +execute 'update fw_core.fw_jobctl_file_sheet_block_run_schedule set end_status=1 , end_time=now(), end_status_note=''completed'' +where file_syspk='''||p_file_syspk||'''and block_table_name='''||p_block_table_name||''''; + +end +$$ LANGUAGE plpgsql; diff --git a/onetime/commonfunctions/fn_run_post_generic_validation.sql b/onetime/commonfunctions/fn_run_post_generic_validation.sql new file mode 100755 index 0000000..a042154 --- /dev/null +++ b/onetime/commonfunctions/fn_run_post_generic_validation.sql @@ -0,0 +1,142 @@ +drop function if exists fw_core.fn_run_post_generic_validation; +CREATE OR REPLACE FUNCTION fw_core.fn_run_post_generic_validation(p_client_id int,p_function_id int,p_job_id int,p_step_id int) + RETURNS void AS $$ + declare + f record; + trx_record_count int; + keyword_match_count int; + missing_sheet_count int; + success_sum int; + + w_job_id int := p_job_id; + w_step_id int := p_step_id; +-- validate file already loaded in the Transactional DB : + + begin + for f in select distinct file_syspk from fw_core.fw_jobctl_file_runschedule + where latest_runschedule_flag = '1' and end_status != 'error' and end_status_note = 'stg1_completed' + loop + select count(*) from transactional.test_instance where file_syspk = f.file_syspk into trx_record_count; + if trx_record_count > 0 then + update fw_core.fw_jobctl_file_runschedule set end_status_note ='generic_validation_failed', end_status='error', staging_type = 'stg1',end_time = now() where file_syspk = f.file_syspk; + update fw_core.fw_jobctl_file_sheet_runschedule set end_status_note = 'file_syspk exists', end_status='error', staging_type = 'stg1',end_time = now() where file_syspk = f.file_syspk; + end if; + + update fw_core.fw_jobctl_file_runschedule set end_status_note ='generic_validation_completed', end_status='success', staging_type = 'stg1',end_time = now() where file_syspk = f.file_syspk; + update fw_core.fw_jobctl_file_sheet_runschedule set end_status_note = 'generic_validation_completed', end_status='success', staging_type = 'stg1',end_time = now() where file_syspk = f.file_syspk and file_sheet_mnemonic is not null; + + end loop; + +SELECT SUM (case WHEN end_status = 'success' THEN 1 + ELSE 0 END) AS "Error Sum" FROM fw_core.fw_jobctl_file_sheet_runschedule where latest_runschedule_flag = '1' INTO success_sum; + if (success_sum >0 or success_sum is null) then + update fw_core.fw_jobctl_runschedule_jobstep set end_status_note = 'generic_validation_completed', end_status='success' , end_time= now() where job_id = w_job_id and step_id = w_step_id and latest_runschedule_flag = '1'; +else + update fw_core.fw_jobctl_runschedule_jobstep set end_status_note = 'generic_validation_failed', end_status='error', end_time= now() where job_id = w_job_id and step_id = w_step_id and latest_runschedule_flag = '1'; + return ; + end if; + +--insert into fw_core.track_jobstep select *,'file_syspk' from fw_core.fw_jobctl_runschedule_jobstep; +--insert into fw_core.track_file select *,'file_syspk' from fw_core.fw_jobctl_file_runschedule; +--insert into fw_core.track_file_sheet select * ,'file_syspk' from fw_core.fw_jobctl_file_sheet_runschedule; + +-- validate sheet names for a given file: + + for f in select distinct file_syspk,file_mnemonic,file_sheet_mnemonic from fw_core.fw_jobctl_file_sheet_runschedule + where file_sheet_mnemonic is not null + and end_status != 'error' and end_status_note = 'generic_validation_completed' and latest_runschedule_flag = '1' + loop + select count(distinct sheet_name) from fw_core.test_file_sheet_format_master + where sheet_name not in + (select distinct sheet_name from fw_core.fw_jobctl_file_sheet_runschedule where file_mnemonic in (f.file_mnemonic) and file_sheet_mnemonic is not null and file_syspk=f.file_syspk) + and file_mnemonic in (f.file_mnemonic) + into missing_sheet_count; + + if missing_sheet_count = 0 then + + update fw_core.fw_jobctl_file_sheet_runschedule set end_status_note = 'generic_validation_completed', end_status='success', staging_type = 'stg1',end_time = now() where + file_syspk = f.file_syspk and file_sheet_mnemonic=f.file_sheet_mnemonic; + update fw_core.fw_jobctl_file_runschedule set end_status_note ='generic_validation_completed', end_status='success', staging_type = 'stg1',end_time = now() where file_syspk = f.file_syspk; + + else + update fw_core.fw_jobctl_file_sheet_runschedule set end_status_note = 'stg1_sheet_missing', end_status='error', staging_type = 'stg1',end_time = now() where + file_syspk = f.file_syspk and file_sheet_mnemonic=f.file_sheet_mnemonic; + update fw_core.fw_jobctl_file_runschedule set end_status_note ='generic_validation_failed', end_status='error', staging_type = 'stg1',end_time = now() where file_syspk = f.file_syspk; +end if; + end loop; + + SELECT SUM (case WHEN end_status = 'success' THEN 1 + ELSE 0 END) AS "Error Sum" FROM fw_core.fw_jobctl_file_sheet_runschedule where latest_runschedule_flag = '1' INTO success_sum; + if ((success_sum > 0) or (success_sum is null)) then + update fw_core.fw_jobctl_runschedule_jobstep set end_status_note = 'generic_validation_completed', end_status='success', end_time=now() where job_id = w_job_id and step_id = w_step_id and latest_runschedule_flag = '1'; +else + update fw_core.fw_jobctl_runschedule_jobstep set end_status_note = 'generic_validation_failed', end_status='error', end_time=now() where job_id = w_job_id and step_id = w_step_id and latest_runschedule_flag = '1'; + return ; +end if; + + + + +insert into fw_core.track_jobstep select *,'missing_sheet' from fw_core.fw_jobctl_runschedule_jobstep; +insert into fw_core.track_file select *,'missing_sheet' from fw_core.fw_jobctl_file_runschedule; +insert into fw_core.track_file_sheet select * ,'missing_sheet' from fw_core.fw_jobctl_file_sheet_runschedule; + +-- validate keywords for a given file: + + for f in select distinct file_syspk,file_mnemonic,file_sheet_mnemonic + from fw_core.fw_jobctl_file_sheet_runschedule where file_sheet_mnemonic !='' + and end_status != 'error' and end_status_note = 'generic_validation_completed' + order by file_syspk + loop + select case + when file_sheet_mnemonic in ('FTDRY_SUM','FTHLG_SUM')then count(trim(column2))-2 + when file_sheet_mnemonic in ('FTWET_SUM')then count(trim(column2))-1 + else count(trim(column2)) end + from staging1.staging_generic_table where column2 + in (select trim(f1_keyword) from transactional.source_config a + where a.file_mnemonic=f.file_mnemonic and a.file_sheet_mnemonic=f.file_sheet_mnemonic ) + and file_mnemonic=f.file_mnemonic and file_sheet_mnemonic=f.file_sheet_mnemonic and file_syspk = f.file_syspk group by file_sheet_mnemonic into keyword_match_count; + + if keyword_match_count != (select count(f1_keyword) from transactional.source_config a + where a.file_mnemonic=f.file_mnemonic and a.file_sheet_mnemonic=f.file_sheet_mnemonic) + then + update fw_core.fw_jobctl_file_sheet_runschedule set end_status_note = 'stg1_keyword_validation_failed', end_status='error', staging_type = 'stg1',end_time = now() where + file_syspk = f.file_syspk and file_sheet_mnemonic=f.file_sheet_mnemonic; + else + update fw_core.fw_jobctl_file_sheet_runschedule set end_status_note = 'generic_validation_completed', end_status='success', staging_type = 'stg1',end_time = now() where + file_syspk = f.file_syspk and file_sheet_mnemonic=f.file_sheet_mnemonic; + end if; + end loop; + + -- update fw_jobctl_file_runschedule table. + + +--insert into fw_core.track_jobstep select *,'keyword_' from fw_core.fw_jobctl_runschedule_jobstep; +--insert into fw_core.track_file select *,'keyword_' from fw_core.fw_jobctl_file_runschedule; +--insert into fw_core.track_file_sheet select *,'keyword_' from fw_core.fw_jobctl_file_sheet_runschedule; + +--, staging_type = 'stg1' + + update fw_core.fw_jobctl_file_runschedule set end_status_note = 'generic_validation_completed', end_status='success', end_time=now() from fw_core.fw_jobctl_file_sheet_runschedule a + where a.latest_runschedule_flag = '1' and a.end_status = 'success' and a.end_status_note ='generic_validation_completed' and fw_core.fw_jobctl_file_runschedule.file_syspk = a.file_syspk; + + update fw_core.fw_jobctl_file_runschedule set end_status_note = 'generic_validation_failed' , end_status='error',end_time=now() from fw_core.fw_jobctl_file_sheet_runschedule a + where a.latest_runschedule_flag = '1' and a.end_status = 'error' and a.end_status_note = 'stg1_keyword_validation_failed' and fw_core.fw_jobctl_file_runschedule.file_syspk = a.file_syspk; + + update fw_core.fw_jobctl_file_sheet_runschedule set end_status='error',end_status_note = 'stg1_keyword_validation_failed',end_time=now() from fw_core.fw_jobctl_file_runschedule a + where file_sheet_mnemonic is not null and a.latest_runschedule_flag = '1' and a.end_status = 'error' and a.end_status_note = 'generic_validation_failed' and fw_core.fw_jobctl_file_sheet_runschedule.file_syspk = a.file_syspk; + + SELECT SUM (case WHEN end_status = 'success' THEN 1 + ELSE 0 END) AS "Error Sum" FROM fw_core.fw_jobctl_file_runschedule where latest_runschedule_flag = '1' INTO success_sum; + if (success_sum >0 or success_sum is null) then + update fw_core.fw_jobctl_runschedule_jobstep set end_status_note = 'generic_validation_completed', end_status='success', end_time=now() where job_id = w_job_id and step_id = w_step_id and latest_runschedule_flag = '1'; + else + update fw_core.fw_jobctl_runschedule_jobstep set end_status_note = 'generic_validation_failed', end_status= 'error', end_time=now() where job_id = w_job_id and step_id = w_step_id and latest_runschedule_flag = '1'; + end if; + +--insert into fw_core.track_jobstep select *,'keyword_missing' from fw_core.fw_jobctl_runschedule_jobstep; +--insert into fw_core.track_file select *,'keyword_missing' from fw_core.fw_jobctl_file_runschedule; +--insert into fw_core.track_file_sheet select *,'keyword_missing' from fw_core.fw_jobctl_file_sheet_runschedule; + +end; +$$ LANGUAGE plpgsql; diff --git a/onetime/commonfunctions/fn_run_post_trx_validation.sql b/onetime/commonfunctions/fn_run_post_trx_validation.sql new file mode 100644 index 0000000..57d8182 --- /dev/null +++ b/onetime/commonfunctions/fn_run_post_trx_validation.sql @@ -0,0 +1,34 @@ +drop function if exists fw_core.fn_run_trx_post_validation; +CREATE OR REPLACE FUNCTION fw_core.fn_run_trx_post_validation(p_client_id int,p_function_id int,p_job_id int,p_step_id int) + RETURNS void AS $$ + declare + f record; + trx_record_count int; + w_job_id int := p_job_id; + w_step_id int := p_step_id; + + +-- validate Trx data record loading: + begin + + for f in select distinct file_syspk from fw_core.fw_jobctl_file_runschedule + where latest_runschedule_flag = '1' and end_status != 'error' and end_status_note = 'TRX_completed' + loop + select count(*) from transactional.test_instance where file_syspk = f.file_syspk into trx_record_count; + if (trx_record_count = 0) then + update fw_core.fw_jobctl_runschedule_jobstep set end_status_note = 'trx_post_validation_failed', end_status='error', end_time= now() where job_id = w_job_id and step_id = w_step_id and latest_runschedule_flag = '1'; + update fw_core.fw_jobctl_file_sheet_runschedule set end_status_note = 'trx_post_validation_failed', end_status='error', end_time= now() where file_syspk=f.file_syspk; + update fw_core.fw_jobctl_file_runschedule set end_status_note = 'trx_post_validation_failed', end_status='error', end_time= now() where file_syspk=f.file_syspk; + else + update fw_core.fw_jobctl_runschedule_jobstep set end_status_note = 'TRX_completed', end_status='success' , end_time= now() where job_id = w_job_id and step_id = w_step_id and latest_runschedule_flag = '1'; + update fw_core.fw_jobctl_file_sheet_runschedule set end_status_note = 'TRX_completed', end_status='success', end_time= now() where file_syspk=f.file_syspk; + update fw_core.fw_jobctl_file_runschedule set end_status_note = 'TRX_completed', end_status='success', end_time= now() where file_syspk=f.file_syspk; + end if; + end loop; +/* +--insert into fw_core.track_jobstep select *,'trx_validation' from fw_core.fw_jobctl_runschedule_jobstep; +--insert into fw_core.track_file select *,'trx_validation' from fw_core.fw_jobctl_file_runschedule; +--insert into fw_core.track_file_sheet select *,'trx_validation' from fw_core.fw_jobctl_file_sheet_runschedule; +*/ +end; +$$ LANGUAGE plpgsql; \ No newline at end of file diff --git a/onetime/commonfunctions/fn_run_trx_rollback.sql b/onetime/commonfunctions/fn_run_trx_rollback.sql new file mode 100755 index 0000000..c27e3d5 --- /dev/null +++ b/onetime/commonfunctions/fn_run_trx_rollback.sql @@ -0,0 +1,174 @@ +drop function if exists fw_core.fn_run_trx_rollback; +CREATE OR REPLACE FUNCTION fw_core.fn_run_trx_rollback(p_client_id int,p_function_id int,p_job_id int,p_step_id int) + RETURNS void AS $$ + declare + f record; + begin + for f in select file_syspk,file_mnemonic + from fw_core.fw_jobctl_file_runschedule where latest_runschedule_flag = '1' and end_status = 'error' + and end_status_note in ('stg2_failed','TRX_failed') + order by file_syspk + loop + if f.file_mnemonic = 'FTDRY' then + + delete from transactional.test_instance where file_syspk = f.file_syspk; + delete from transactional.test_instance_engine_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_implement_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_tractor_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_trailer_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_tyre_info where file_syspk = f.file_syspk; + delete from transactional.field_perf_summary where file_syspk = f.file_syspk; + delete from transactional.field_perf_summary_implement_info where file_syspk = f.file_syspk; + delete from transactional.field_perf_summary_tractor_info where file_syspk = f.file_syspk; + + elsif f.file_mnemonic = 'FTWET' then + delete from transactional.test_instance where file_syspk = f.file_syspk; + delete from transactional.test_instance_engine_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_implement_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_tractor_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_trailer_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_tyre_info where file_syspk = f.file_syspk; + delete from transactional.field_perf_summary where file_syspk = f.file_syspk; + delete from transactional.field_perf_summary_implement_info where file_syspk = f.file_syspk; + delete from transactional.field_perf_summary_tractor_info where file_syspk = f.file_syspk; + elsif f.file_mnemonic = 'FTHLG' then + delete from transactional.test_instance where file_syspk = f.file_syspk; + delete from transactional.test_instance_engine_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_implement_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_tractor_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_trailer_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_tyre_info where file_syspk = f.file_syspk; + delete from transactional.field_perf_summary where file_syspk = f.file_syspk; + delete from transactional.field_perf_summary_implement_info where file_syspk = f.file_syspk; + delete from transactional.field_perf_summary_tractor_info where file_syspk = f.file_syspk; + delete from transactional.field_perf_summary_trailer_info where file_syspk = f.file_syspk; + elsif f.file_mnemonic = 'DBSTD' then + delete from transactional.test_instance where file_syspk = f.file_syspk; + delete from transactional.test_instance_engine_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_tractor_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_drawbar_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_tyre_info where file_syspk = f.file_syspk; + delete from transactional.drawbar_perf_results_summary where file_syspk = f.file_syspk; + delete from transactional.drawbar_perf_results where file_syspk = f.file_syspk; + delete from transactional.test_instance_equipment_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_measurement_uncertainty where file_syspk = f.file_syspk; + delete from transactional.test_instance_tractor_info_misc where file_syspk = f.file_syspk; + delete from transactional.test_instance_gear_speed_chart where file_syspk = f.file_syspk; + delete from transactional.Test_instance_wheels_info where file_syspk = f.file_syspk; + delete from transactional.Test_instance_fuel_lubricant_info where file_syspk = f.file_syspk; + delete from transactional.drawbar_perf_observations where file_syspk = f.file_syspk; + elsif f.file_mnemonic = 'DBOECD' then + delete from transactional.test_instance where file_syspk = f.file_syspk; + delete from transactional.test_instance_engine_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_tractor_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_drawbar_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_tyre_info where file_syspk = f.file_syspk; + delete from transactional.drawbar_perf_results_summary where file_syspk = f.file_syspk; + delete from transactional.drawbar_perf_results where file_syspk = f.file_syspk; + delete from transactional.drawbar_perf_oecd_results where file_syspk = f.file_syspk; + delete from transactional.test_instance_equipment_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_measurement_uncertainty where file_syspk = f.file_syspk; + delete from transactional.test_instance_tractor_info_misc where file_syspk = f.file_syspk; + delete from transactional.test_instance_gear_speed_chart where file_syspk = f.file_syspk; + delete from transactional.Test_instance_wheels_info where file_syspk = f.file_syspk; + delete from transactional.Test_instance_fuel_lubricant_info where file_syspk = f.file_syspk; + delete from transactional.drawbar_perf_observations where file_syspk = f.file_syspk; + elsif f.file_mnemonic = 'PTOBEN' then + delete from transactional.pto_engine_oil_consumption where file_syspk = f.file_syspk; + delete from transactional.pto_key_perf_parameters where file_syspk = f.file_syspk; + delete from transactional.pto_multipoint_mapping where file_syspk = f.file_syspk; + delete from transactional.pto_perf_governing_graph where file_syspk = f.file_syspk; + delete from transactional.pto_perf_results where file_syspk = f.file_syspk; + delete from transactional.pto_smoke_test where file_syspk = f.file_syspk; + delete from transactional.test_instance where file_syspk = f.file_syspk; + delete from transactional.test_instance_tractor_info where file_syspk = f.file_syspk; + elsif f.file_mnemonic = 'PTOSTD' then + delete from transactional.pto_engine_oil_consumption where file_syspk = f.file_syspk; + delete from transactional.pto_key_perf_parameters where file_syspk = f.file_syspk; + delete from transactional.pto_multipoint_mapping where file_syspk = f.file_syspk; + delete from transactional.pto_perf_governing_graph where file_syspk = f.file_syspk; + delete from transactional.pto_perf_results where file_syspk = f.file_syspk; + delete from transactional.pto_smoke_test where file_syspk = f.file_syspk; + delete from transactional.test_instance where file_syspk = f.file_syspk; + delete from transactional.test_instance_tractor_info where file_syspk = f.file_syspk; + elsif f.file_mnemonic = 'BUDNI' then + delete from transactional.test_instance where file_syspk = f.file_syspk; + delete from transactional.test_instance_engine_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_tractor_info where file_syspk = f.file_syspk; + delete from transactional.budni_air_cleaner_perf_results where file_syspk = f.file_syspk; + delete from transactional.budni_test_observations where file_syspk = f.file_syspk; + delete from transactional.budni_brake_perf_parking_brake_test_results where file_syspk = f.file_syspk; + delete from transactional.budni_brake_perf_service_brake_test_results where file_syspk = f.file_syspk; + delete from transactional.budni_drawbar_perf_results where file_syspk = f.file_syspk; + delete from transactional.test_instance_implement_info where file_syspk = f.file_syspk; + delete from transactional.budni_field_perf_results where file_syspk = f.file_syspk; + delete from transactional.test_instance_tractor_info_misc where file_syspk = f.file_syspk; + delete from transactional.budni_hydraulic_maint_of_lift_load_results where file_syspk = f.file_syspk; + delete from transactional.budni_hydraulic_power_test_results where file_syspk = f.file_syspk; + delete from transactional.budni_hydraulic_lifting_capacity_test_results where file_syspk = f.file_syspk; + delete from transactional.budni_centre_of_gravity_location where file_syspk = f.file_syspk; + delete from transactional.budni_noise_atmospheric_conditions where file_syspk = f.file_syspk; + delete from transactional.budni_noise_measurement_results where file_syspk = f.file_syspk; + delete from transactional.budni_pto_perf_results_summary where file_syspk = f.file_syspk; + delete from transactional.budni_pto_perf_results_details where file_syspk = f.file_syspk; + delete from transactional.budni_vibration_measurement where file_syspk = f.file_syspk; + elsif f.file_mnemonic = 'IHT' then + delete from transactional.test_instance where file_syspk = f.file_syspk; + delete from transactional.test_instance_engine_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_tyre_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_atmospheric_info where file_syspk = f.file_syspk; + delete from transactional.iht_noise_measurement_results where file_syspk = f.file_syspk; + delete from transactional.test_instance_tractor_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_drawbar_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_weight_reaction where file_syspk = f.file_syspk; + delete from transactional.iht_brake_perf_test_condition where file_syspk = f.file_syspk; + delete from transactional.iht_brake_perf_test_results where file_syspk = f.file_syspk; + delete from transactional.iht_cgm_lifting_angle_load_details where file_syspk = f.file_syspk; + delete from transactional.iht_cgm_results where file_syspk = f.file_syspk; + delete from transactional.iht_steering_effort where file_syspk = f.file_syspk; + delete from transactional.iht_pedal_effort where file_syspk = f.file_syspk; + delete from transactional.iht_clutch_pedal_effort where file_syspk = f.file_syspk; + delete from transactional.iht_brake_pedal_effort where file_syspk = f.file_syspk; + delete from transactional.iht_gear_effort where file_syspk = f.file_syspk; + delete from transactional.iht_hyd_lift_sensitivity where file_syspk = f.file_syspk; + delete from transactional.iht_noise_measurement_test where file_syspk = f.file_syspk; + delete from transactional.iht_gear_max_speed where file_syspk = f.file_syspk; + delete from transactional.iht_speed_lead_lag_measurement where file_syspk = f.file_syspk; + delete from transactional.iht_steering_effort_raw_data where file_syspk = f.file_syspk; + delete from transactional.iht_hot_air_mapping_results where file_syspk = f.file_syspk; + else + delete from transactional.test_instance where file_syspk = f.file_syspk; + delete from transactional.test_instance_engine_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_tyre_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_atmospheric_info where file_syspk = f.file_syspk; + delete from transactional.iht_noise_measurement_results where file_syspk = f.file_syspk; + delete from transactional.test_instance_tractor_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_drawbar_info where file_syspk = f.file_syspk; + delete from transactional.test_instance_weight_reaction where file_syspk = f.file_syspk; + delete from transactional.iht_brake_perf_test_condition where file_syspk = f.file_syspk; + delete from transactional.iht_brake_perf_test_results where file_syspk = f.file_syspk; + delete from transactional.iht_cgm_lifting_angle_load_details where file_syspk = f.file_syspk; + delete from transactional.iht_cgm_results where file_syspk = f.file_syspk; + delete from transactional.iht_steering_effort where file_syspk = f.file_syspk; + delete from transactional.iht_pedal_effort where file_syspk = f.file_syspk; + delete from transactional.iht_clutch_pedal_effort where file_syspk = f.file_syspk; + delete from transactional.iht_brake_pedal_effort where file_syspk = f.file_syspk; + delete from transactional.iht_gear_effort where file_syspk = f.file_syspk; + delete from transactional.iht_hyd_lift_sensitivity where file_syspk = f.file_syspk; + delete from transactional.iht_noise_measurement_test where file_syspk = f.file_syspk; + delete from transactional.iht_gear_max_speed where file_syspk = f.file_syspk; + delete from transactional.iht_speed_lead_lag_measurement where file_syspk = f.file_syspk; + delete from transactional.iht_steering_effort_raw_data where file_syspk = f.file_syspk; + delete from transactional.iht_hot_air_mapping_results where file_syspk = f.file_syspk; + end if; +end loop; +update fw_core.fw_jobctl_runschedule_jobstep set end_status_note = 'rollback completed', end_status='success', end_time=now() where job_id = p_job_id and step_id = p_step_id and latest_runschedule_flag = '1'; + + + +--insert into fw_core.track_jobstep select *,'roll_back' from fw_core.fw_jobctl_runschedule_jobstep; +--insert into fw_core.track_file select *,'roll_back' from fw_core.fw_jobctl_file_runschedule; +--insert into fw_core.track_file_sheet select *,'roll_back' from fw_core.fw_jobctl_file_sheet_runschedule; + +end; +$$ LANGUAGE plpgsql; \ No newline at end of file diff --git a/onetime/commonfunctions/fn_update_generic.sql b/onetime/commonfunctions/fn_update_generic.sql new file mode 100755 index 0000000..e56d956 --- /dev/null +++ b/onetime/commonfunctions/fn_update_generic.sql @@ -0,0 +1,74 @@ + + + +CREATE OR REPLACE FUNCTION fw_core.fn_update_NA(filesyspk integer) + RETURNS void + LANGUAGE plpgsql +AS $function$ + /*********** + select fw_core.fn_update_NA() + ********/ +declare + __n integer:=0; + __na_sql text; + __space_sql text; + __div_sql text; + __ref_sql text; + __hyphen_sql text; +__hyphen_3_sql text; +__not_applicable text; +__NR text; +__Dots_1 text; +__Dots_2 text; +__trail_trim_columns text; +__lead_trim_columns text; +__Dots_3 text; +__inverted_comma text; +__underscore text; +begin + loop + exit when __n=53; + __n := __n+1; + __na_sql := 'update staging1.staging_generic_table set '|| concat('column',__n)||' =null + where '||concat('column',__n)||'=''NA'' and file_syspk=' ||filesyspk; + __space_sql := 'update staging1.staging_generic_table set '|| concat('column',__n)||' =null + where '||concat('column',__n)||'='''' and file_syspk=' ||filesyspk; + __div_sql := 'update staging1.staging_generic_table set '|| concat('column',__n)||' =null + where '||concat('column',__n)||'=''#REF!'' and file_syspk=' ||filesyspk; + __ref_sql := 'update staging1.staging_generic_table set '|| concat('column',__n)||' =null + where '||concat('column',__n)||'=''#DIV/0!'' and file_syspk=' ||filesyspk; + __hyphen_sql := 'update staging1.staging_generic_table set '|| concat('column',__n)||' =null + where '||concat('column',__n)||'=''-'' and file_syspk=' ||filesyspk; + __hyphen_3_sql := 'update staging1.staging_generic_table set '|| concat('column',__n)||' =null + where '||concat('column',__n)||'=''---'' and file_syspk=' ||filesyspk; + __not_applicable := 'update staging1.staging_generic_table set '|| concat('column',__n)||' =null + where '||concat('column',__n)||'=''Not Applicable '' and file_syspk=' ||filesyspk; + __NR := 'update staging1.staging_generic_table set '|| concat('column',__n)||' =null + where '||concat('column',__n)||'=''NR'' and file_syspk=' ||filesyspk; + __Dots_1 := 'update staging1.staging_generic_table set '|| concat('column',__n)||' =null + where '||concat('column',__n)||'=''u..'' and file_syspk=' ||filesyspk; + __Dots_2 := 'update staging1.staging_generic_table set '|| concat('column',__n)||' =null + where '||concat('column',__n)||'=''u.'' and file_syspk=' ||filesyspk; + __Dots_3 := 'update staging1.staging_generic_table set '|| concat('column',__n)||' =null + where '||concat('column',__n)||'=''.'' and file_syspk=' ||filesyspk; + __inverted_comma := 'update staging1.staging_generic_table set '|| concat('column',__n)||' =null + where '||concat('column',__n)||'=''`'' and file_syspk=' ||filesyspk; + __trail_trim_columns:='update staging1.staging_generic_table set '|| concat('column',__n)||' = trim(trailing from '|| concat('column',__n)||')'; + __lead_trim_columns:='update staging1.staging_generic_table set '|| concat('column',__n)||' = trim(leading from '|| concat('column',__n)||')'; + __underscore := 'update staging1.staging_generic_table set '|| concat('column',__n)||' =null + where '||concat('column',__n)||'=''_'' and file_syspk=' ||filesyspk; + execute __na_sql; + execute __space_sql; + execute __div_sql; + execute __ref_sql; + execute __hyphen_sql; + execute __not_applicable; + execute __NR; + execute __Dots_1; + execute __Dots_2; + execute __trail_trim_columns; + execute __lead_trim_columns; + execute __underscore; + end loop; +end; +$function$ \ No newline at end of file diff --git a/onetime/configentries/BUDNI_config.sql b/onetime/configentries/BUDNI_config.sql new file mode 100755 index 0000000..d2927e7 --- /dev/null +++ b/onetime/configentries/BUDNI_config.sql @@ -0,0 +1,100 @@ +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('BUDNI','BUDNI_DBP','BUDNI_DBP_Spec_H1','Test Tractor Specifiactions','Test Tractor Specifiactions'), +('BUDNI','BUDNI_DBP','BUDNI_DBP_Drawbar_Perf','Tractor Drawbar Performance Report.','Tractor Drawbar Performance Report.'); + + +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('BUDNI','BUDNI_NMT','BUDNI_NMT_Spec_H1','Test Tractor Specifiactions','Test Tractor Specifiactions'), +('BUDNI','BUDNI_NMT','BUDNI_NMT_ Noise at bystander’s position', 'Noise at bystander''’s position: Noise Measurement Test', 'Noise at bystander''’s position: Noise Measurement Test'), +('BUDNI','BUDNI_NMT','BUDNI_NMT_ Noise at operator’s ear level','Noise at operator''’s ear level: Noise Measurement Test','Noise at operator''’s ear level: Noise Measurement Test'), +('BUDNI','BUDNI_NMT','BUDNI_NMT_Test_Obs_Summary','Noise Measurement Test Observations Summary','Noise Measurement Test Observations Summary'); + +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('BUDNI','BUDNI_LCG','BUDNI_LCG_Spec_H1','Test Tractor Specifiactions','Test Tractor Specifiactions'), +('BUDNI','BUDNI_LCG','BUDNI_LCG_Gravity_Test','Location of centre of Gravity Test','Location of centre of Gravity Test'); + +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('BUDNI','BUDNI_PTO','BUDNI_PTO_Spec_H1','Test Tractor Specifiactions','Test Tractor Specifiactions'), +('BUDNI','BUDNI_PTO','BUDNI_PTO_Report','PTO Performance Report','PTO Performance Report'), +('BUDNI','BUDNI_PTO','BUDNI_PTO_MMTKeyword1','MMTKeyword1','MMTKeyword1'), +('BUDNI','BUDNI_PTO','BUDNI_PTO_MMTKeyword2','MMTKeyword2','MMTKeyword2'), +('BUDNI','BUDNI_PTO','BUDNI_PTO_Summary','PTO Performance Test Observations Summary','PTO Performance Test Observations Summary'); + +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('BUDNI','BUDNI_HDL','BUDNI_HDL_Spec_H1','Test Tractor Specifiactions','Test Tractor Specifiactions'), +('BUDNI','BUDNI_HDL','BUDNI_HDL_Power_Test','A) Hydraulic power test:','A) Hydraulic power test:'), +('BUDNI','BUDNI_HDL','BUDNI_HDL_Lifting_Capacity_Test','B) Lifting Capacity Test','B) Lifting Capacity Test'), +('BUDNI','BUDNI_HDL','BUDNI_HDL_Maintenance_Of_Lift_Load','C) Maintenance of lift load:','C) Maintenance of lift load:'), +('BUDNI','BUDNI_HDL','BUDNI_HDL_Test_Obs_Summary','Power Lift and Hydraulic Pump Performance Test Observations Summary','Power Lift and Hydraulic Pump Performance Test Observations Summary'); + + + +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('BUDNI','BUDNI_HLG','BUDNI_HLG_Spec_H1','Test Tractor Specifiactions','Test Tractor Specifiactions'), +('BUDNI','BUDNI_HLG','BUDNI_HLG_Perf_Test','Haulage performance Test','Haulage performance Test'), +('BUDNI','BUDNI_HLG','BUDNI_HLG_Test_Obs_Summary','Haulage Performance Test Observations Summary','Haulage Performance Test Observations Summary'); + + + + +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('BUDNI','BUDNI_FLD','BUDNI_FLD_Spec_H1','Test Tractor Specifiactions','Test Tractor Specifiactions'), +('BUDNI','BUDNI_FLD','BUDNI_FLD_Impl_Test','BRIEF SPECIFICATION OF IMPLEMENTS USED DURING FIELD TEST','BRIEF SPECIFICATION OF IMPLEMENTS USED DURING FIELD TEST'), +('BUDNI','BUDNI_FLD','BUDNI_FLD_Sum_Perf_Test','SUMMARY OF FIELD PERFORMANCE TEST','SUMMARY OF FIELD PERFORMANCE TEST'), +('BUDNI','BUDNI_FLD','BUDNI_FLD_Test_Obs_Summary','Field Performance Test Observations Summary','Field Performance Test Observations Summary'); + + + + + +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('BUDNI','BUDNI_ARC','BUDNI_ARC_Spec_H1','Test Tractor Specifiactions','Test Tractor Specifiactions'), +('BUDNI','BUDNI_ARC','BUDNI_ARC_Perf_Atmos_Meas_Test','Atmospheric conditions:','Atmospheric conditions:'), +('BUDNI','BUDNI_ARC','BUDNI_ARC_Test_Obs_Summary','AIR CLEANER OIL PULL OVER TEST Observations Summary','AIR CLEANER OIL PULL OVER TEST Observations Summary'); + + + + +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('BUDNI','BUDNI_VMT','BUDNI_VMT_Spec_H1','Test Tractor Specifiactions','Test Tractor Specifiactions'), +('BUDNI','BUDNI_VMT','BUDNI_VMT_Perf_Meas_Test','Machanical Vibration Measurement Test','Machanical Vibration Measurement Test'), +('BUDNI','BUDNI_VMT','BUDNI_VMT_Test_Obs_Summary','Noise Measurement Test Observations Summary','Noise Measurement Test Observations Summary'); + + + +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('BUDNI','BUDNI_BRK','BUDNI_BRK_Spec_H1','Test Tractor Specifiactions','Test Tractor Specifiactions'), +('BUDNI','BUDNI_BRK','BUDNI_BRK_Service_Barke_Test','1) Service Barke Testing','1) Service Barke Testing'), +('BUDNI','BUDNI_BRK','BUDNI_BRK_Parking_Brake_Test','2) Parking Brake Test','2) Parking Brake Test'), +('BUDNI','BUDNI_BRK','BUDNI_BRK_Test_Obs_Summary','Brake Performance Test Observations Summary','Brake Performance Test Observations Summary'); + + + + + + + + + + + diff --git a/onetime/configentries/DBOECD_config.sql b/onetime/configentries/DBOECD_config.sql new file mode 100755 index 0000000..e30ff6f --- /dev/null +++ b/onetime/configentries/DBOECD_config.sql @@ -0,0 +1,14 @@ +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values ('DBOECD','DBOECD_TEST','DBOECD_Test_H1','Test Request no.','Test Request no.'), +('DBOECD','DBOECD_TEST','DBOECD_test_engine_RPM','Engine (RPM)','Engine (RPM)'), +('DBOECD','DBOECD_TEST','DBOECD_test_test_condition','Test condition','Test condition'), +('DBOECD','DBOECD_TEST','DBOECD_test_drawbar_performance_selected_summary','Drawbar Performance Test Results (Selected Summary)','Drawbar Performance Test Results (Selected Summary)'), +('DBOECD','DBOECD_TEST','DBOECD_test_drawbar_performance_gear_performance','Drawbar Performance Test Results (Gear Performance Test)','Drawbar Performance Test Results (Gear Performance Test)'), +('DBOECD','DBOECD_TEST','DBOECD_test_fuel_consumption','3.3.2','3.3.2'), +('DBOECD','DBOECD_TEST','DBOECD_test_test_equipment','Test equipment’s used','Test equipment’s used'), +('DBOECD','DBOECD_TEST','DBOECD_test_tractor_specifications','Tractor specification','Tractor specification'), +('DBOECD','DBOECD_TEST','DBOECD_test_transmission','Transmission','Transmission'), +('DBOECD','DBOECD_TEST','DBOECD_test_graphical_data','GRAPHICAL DATA','GRAPHICAL DATA'), +('DBOECD','DBOECD_TEST','DBOECD_test_photos','PHOTOS','PHOTOS'), +('DBOECD','DBOECD_TEST','DBOECD_test_remarks','Remarks:','Remarks:'); \ No newline at end of file diff --git a/onetime/configentries/DBSTD_config.sql b/onetime/configentries/DBSTD_config.sql new file mode 100755 index 0000000..2e48705 --- /dev/null +++ b/onetime/configentries/DBSTD_config.sql @@ -0,0 +1,13 @@ +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values ('DBSTD','DBSTD_TEST','DBSTD_Test_H1','Test Request no.','Test Request no.'), +('DBSTD','DBSTD_TEST','DBSTD_test_engine_RPM','Engine (RPM)','Engine (RPM)'), +('DBSTD','DBSTD_TEST','DBSTD_test_test_condition','Test condition','Test condition'), +('DBSTD','DBSTD_TEST','DBSTD_test_drawbar_performance_selected_summary','Drawbar Performance Test Results (Selected Summary)','Drawbar Performance Test Results (Selected Summary)'), +('DBSTD','DBSTD_TEST','DBSTD_test_drawbar_performance_gear_performance','Drawbar Performance Test Results (Gear Performance Test)','Drawbar Performance Test Results (Gear Performance Test)'), +('DBSTD','DBSTD_TEST','DBSTD_test_test_equipment','Test equipment’s used','Test equipment’s used'), +('DBSTD','DBSTD_TEST','DBSTD_test_tractor_specifications','Tractor specification','Tractor specification'), +('DBSTD','DBSTD_TEST','DBSTD_test_transmission','Transmission','Transmission'), +('DBSTD','DBSTD_TEST','DBSTD_test_graphical_data','GRAPHICAL DATA','GRAPHICAL DATA'), +('DBSTD','DBSTD_TEST','DBSTD_test_photos','PHOTOS','PHOTOS'), +('DBSTD','DBSTD_TEST','DBSTD_test_remarks','Remarks','Remarks'); \ No newline at end of file diff --git a/onetime/configentries/FTDRY_config.sql b/onetime/configentries/FTDRY_config.sql new file mode 100755 index 0000000..46eedea --- /dev/null +++ b/onetime/configentries/FTDRY_config.sql @@ -0,0 +1,21 @@ +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('FTDRY','FTDRY_TRS','FTDRY_TRS_H1','Tractor Specifications Sheet','Tractor Specifications Sheet'), +('FTDRY','FTDRY_TRS','FTDRY_TRS_SPEC','Tractor Specifications','Tractor Specifications'), +('FTDRY','FTDRY_TRS','FTDRY_TRS_Engine_RPM','Engine RPM Data:','Engine RPM Data:'), +('FTDRY','FTDRY_TRS','FTDRY_TRS_Implement','Implement Details','Implement Details') +; + +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('FTDRY','FTDRY_SUM','FTDRY_SUM_Trac_H1','Tractor Model','Tractor Model'), +('FTDRY','FTDRY_SUM','FTDRY_SUM_Implement','Make of Implement','Make of Implement'), +('FTDRY','FTDRY_SUM','FTDRY_SUM_Test_Condition_1','Test Condition_1:','Test Condition:'), +('FTDRY','FTDRY_SUM','FTDRY_SUM_Engineer_Comments_1','Test Engineer Comments_1','Test Engineer Comments'), +('FTDRY','FTDRY_SUM','FTDRY_SUM_Manager_Comments_1','Test Manager Comments_1','Test Manager Comments'), +('FTDRY','FTDRY_SUM','FTDRY_SUM_Test_Condition_2','Test Condition_2:','Test Condition:'), +('FTDRY','FTDRY_SUM','FTDRY_SUM_Engineer_Comments_2','Test Engineer Comments_2','Test Engineer Comments'), +('FTDRY','FTDRY_SUM','FTDRY_SUM_Manager_Comments_2','Test Manager Comments_2','Test Manager Comments') +; \ No newline at end of file diff --git a/onetime/configentries/FTHLG_config.sql b/onetime/configentries/FTHLG_config.sql new file mode 100755 index 0000000..c12c093 --- /dev/null +++ b/onetime/configentries/FTHLG_config.sql @@ -0,0 +1,21 @@ +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('FTHLG','FTHLG_TRS','FTHLG_TRS_H1','Tractor specifications sheet','Tractor specifications sheet'), +('FTHLG','FTHLG_TRS','FTHLG_TRS_SPEC','Tractor Specifications','Tractor Specifications'), +('FTHLG','FTHLG_TRS','FTHLG_TRS_Engine_RPM','Engine RPM Data:','Engine RPM Data:'), +('FTHLG','FTHLG_TRS','FTHLG_TRS_Trailer','Trailer Details','Trailer Details') +; + +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('FTHLG','FTHLG_SUM','FTHLG_SUM_Trac_H1','Tractor Model','Tractor Model'), +('FTHLG','FTHLG_SUM','FTHLG_SUM_Trail_Type','Trailer Type','Trailer Type'), +('FTHLG','FTHLG_SUM','FTHLG_SUM_Test_Condition_1','Test Condition_1:','Test Condition:'), +('FTHLG','FTHLG_SUM','FTHLG_SUM_Engineer_Comments_1','Test Engineer Comments_1','Test Engineer Comments'), +('FTHLG','FTHLG_SUM','FTHLG_SUM_Manager_Comments_1','Test Manager Comments_1','Test Manager Comments'), +('FTHLG','FTHLG_SUM','FTHLG_SUM_Test_Condition_2','Test Condition_2:','Test Condition:'), +('FTHLG','FTHLG_SUM','FTHLG_SUM_Engineer_Comments_2','Test Engineer Comments_2','Test Engineer Comments'), +('FTHLG','FTHLG_SUM','FTHLG_SUM_Manager_Comments_2','Test Manager Comments_2','Test Manager Comments') +; \ No newline at end of file diff --git a/onetime/configentries/FTWET_config.sql b/onetime/configentries/FTWET_config.sql new file mode 100755 index 0000000..8da3c3a --- /dev/null +++ b/onetime/configentries/FTWET_config.sql @@ -0,0 +1,18 @@ +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('FTWET','FTWET_TRS','FTWET_TRS_H1','Tractor Specifications Sheet','Tractor Specifications Sheet'), +('FTWET','FTWET_TRS','FTWET_TRS_SPEC','Tractor Specifications','Tractor Specifications'), +('FTWET','FTWET_TRS','FTWET_TRS_Engine_RPM','Engine RPM Data:','Engine RPM Data:'), +('FTWET','FTWET_TRS','FTWET_TRS_Implement','Implement Details','Implement Details') +; + +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('FTWET','FTWET_SUM','FTWET_SUM_Trac_H1','Tractor Model','Tractor Model'), +('FTWET','FTWET_SUM','FTWET_SUM_Impement','Make of Implement','Make of Implement'), +('FTWET','FTWET_SUM','FTWET_SUM_Cage_Wheel','Type of Cage Wheel','Type of Cage Wheel'), +('FTWET','FTWET_SUM','FTWET_SUM_Test_Condition','Test Condition:','Test Condition:'), +('FTWET','FTWET_SUM','FTWET_SUM_Manager_Comment','Test Manager Comments','Test Manager Comments') +; \ No newline at end of file diff --git a/onetime/configentries/IHT_config.sql b/onetime/configentries/IHT_config.sql new file mode 100755 index 0000000..2ef093f --- /dev/null +++ b/onetime/configentries/IHT_config.sql @@ -0,0 +1,101 @@ +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('IHTNST','IHTNST_NST','IHTNST_NST_H1','Test Request No','Test Request No'), +('IHTNST','IHTNST_NST','IHTNST_NST_Tyre_Details','Tyre Details','Tyre Details'), +('IHTNST','IHTNST_NST','IHTNST_NST_Engine_RPM_Atmos','Engine RPM','Engine RPM'), +('IHTNST','IHTNST_NST','IHTNST_NST_STAND_Noise','BY STANDER’S NOISE','BY STANDER’S NOISE'), +('IHTNST','IHTNST_NST','IHTNST_NST_OEL_Noise','OEL Noise without Load','OEL Noise without Load'), +('IHTNST','IHTNST_NST','IHTNST_NST_OEL_Noise_Load','OEL Noise with Load','OEL Noise with Load'), +('IHTNST','IHTNST_NST','IHTNST_NST_Footer','Prepared by','Prepared by'); + + +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('IHTHLS','IHTHLS_HLS','IHTHLS_HLS_H1','Test Request no.','Test Request no.'), +('IHTHLS','IHTHLS_HLS','IHTHLS_HLS_Weight_Tyre','Weight Reaction','Weight Reaction'), +('IHTHLS','IHTHLS_HLS','IHTHLS_HLS_Numeric','Numerical data','Numerical data'), +('IHTHLS','IHTHLS_HLS','IHTHLS_HLS_Footer','Prepared By','Prepared By'); + +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('IHTBTD','IHTBTD_BTD','IHTBTD_BTD_H1','Test Request No','Test Request No'), +('IHTBTD','IHTBTD_BTD','IHTBTD_BTD_Test_Res_1','Un-Ballast cold','Un-Ballast cold'), +('IHTBTD','IHTBTD_BTD','IHTBTD_BTD_Test_Res_2','Road Ballast cold','Road Ballast cold'), +('IHTBTD','IHTBTD_BTD','IHTBTD_BTD_Test_Res_3','Road Ballast Hot','Road Ballast Hot'), +('IHTBTD','IHTBTD_BTD','IHTBTD_BTD_Test_Res_4','Max Ballast cold','Max Ballast cold'), +('IHTBTD','IHTBTD_BTD','IHTBTD_BTD_Test_Res_5','Max Ballast Hot','Max Ballast Hot'), +('IHTBTD','IHTBTD_BTD','IHTBTD_BTD_Test_Res_6','Date- 04-July-2019','Date- 04-July-2019'), +('IHTBTD','IHTBTD_BTD','IHTBTD_BTD_Weight_Tyre','Weight (kg)','Weight (kg)'), +('IHTBTD','IHTBTD_BTD','IHTBTD_BTD_Footer','Prepared by','Prepared by'); + +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('IHTBT50','IHTBT50_BT50','IHTBT50_BT50_H1','Test Request No','Test Request No'), +('IHTBT50','IHTBT50_BT50','IHTBT50_BT50_Test_Res_1','Un-Ballast cold','Un-Ballast cold'), +('IHTBT50','IHTBT50_BT50','IHTBT50_BT50_Test_Res_2','Ballast cold','Ballast cold'), +('IHTBT50','IHTBT50_BT50','IHTBT50_BT50_Test_Res_3','Fade Performance','Fade Performance'), +('IHTBT50','IHTBT50_BT50','IHTBT50_BT50_Test_Res_4','Recovery Performance','Recovery Performance'), +('IHTBT50','IHTBT50_BT50','IHTBT50_BT50_Weight_Tyre','Weight (kg)','Weight (kg)'), +('IHTBT50','IHTBT50_BT50','IHTBT50_BT50_Footer','Prepared by','Prepared by'); + + +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('IHTBT30','IHTBT30_BT30','IHTBT30_BT30_H1','Test Request No','Test Request No'), +('IHTBT30','IHTBT30_BT30','IHTBT30_BT30_Test_Res_1','Un-Ballast cold','Un-Ballast cold'), +('IHTBT30','IHTBT30_BT30','IHTBT30_BT30_Test_Res_2','Ballast cold','Ballast cold'), +('IHTBT30','IHTBT30_BT30','IHTBT30_BT30_Test_Res_3','Fade Performance','Fade Performance'), +('IHTBT30','IHTBT30_BT30','IHTBT30_BT30_Test_Res_4','Recovery Performance','Recovery Performance'), +('IHTBT30','IHTBT30_BT30','IHTBT30_BT30_Weight_Tyre','Weight (kg)','Weight (kg)'), +('IHTBT30','IHTBT30_BT30','IHTBT30_BT30_Footer','Prepared by','Prepared by'); + + +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('IHTSLL','IHTSLL_SLL','IHTSLL_SLL_H1','Test Request No','Test Request No'), +('IHTSLL','IHTSLL_SLL','IHTSLL_SLL_Weight_Tyre','Weight Reaction','Weight Reaction'), +('IHTSLL','IHTSLL_SLL','IHTSLL_SLL_Forward','K2-4WD HST EACH GEAR MAX SPEED - FORWARD','K2-4WD HST EACH GEAR MAX SPEED - FORWARD'), +('IHTSLL','IHTSLL_SLL','IHTSLL_SLL_Reverse','K2- 4WD HST EACH GEAR MAX SPEED REVERSE','K2- 4WD HST EACH GEAR MAX SPEED REVERSE'), +('IHTSLL','IHTSLL_SLL','IHTSLL_SLL_Lead_Lag','Lead / Lag Measurement on K2 4WD HST','Lead / Lag Measurement on K2 4WD HST'), +('IHTSLL','IHTSLL_SLL','IHTSLL_SLL_Footer','Prepared by','Prepared by'); + +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('IHTEMT','IHTEMT_EMT','IHTEMT_EMT_H1','Test Request no.','Test Request no.'), +('IHTEMT','IHTEMT_EMT','IHTEMT_EMT_Weight_Tyre','Weight Reaction','Weight Reaction'), +('IHTEMT','IHTEMT_EMT','IHTEMT_EMT_Steering','Steering effort','Steering effort'), +('IHTEMT','IHTEMT_EMT','IHTEMT_EMT_Pedal','Pedal Effort','Pedal Effort'), +('IHTEMT','IHTEMT_EMT','IHTEMT_EMT_Brake_Pedal','Brake Pedal Effort','Brake Pedal Effort'), +('IHTEMT','IHTEMT_EMT','IHTEMT_EMT_Footer','Prepared by','Prepared by'); + +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('IHTEMT','IHTEMT_STD','IHTEMT_STD_RAW_Data','Steering effort RAW data','Steering effort RAW data'); + +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('IHTCGM','IHTCGM_CGM','IHTCGM_CGM_H1','Test Request no.','Test Request no.'), +('IHTCGM','IHTCGM_CGM','IHTCGM_CGM_Weight_Tyre','Weight Reaction','Weight Reaction'), +('IHTCGM','IHTCGM_CGM','IHTCGM_CGM_Lifting','Lifting Angle & Load','Lifting Angle & Load'), +('IHTCGM','IHTCGM_CGM','IHTCGM_CGM_Footer','Prepared by','Prepared by'); + +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values +('IHTHAM','IHTHAM_HAM','IHTHAM_HAM_H1','Test Request no.','Test Request no.'), +('IHTHAM','IHTHAM_HAM','IHTHAM_HAM_Engine_Tyre_Weight','Engine (RPM)','Engine (RPM)'), +('IHTHAM','IHTHAM_HAM','IHTHAM_HAM_Atmos_Cond','Atmospheric condition','Atmospheric condition'), +('IHTHAM','IHTHAM_HAM','IHTHAM_HAM_Results','Gear','Gear'), +('IHTHAM','IHTHAM_HAM','IHTHAM_HAM_Footer','Prepared By','Prepared By'); + + + diff --git a/onetime/configentries/PTO_config.sql b/onetime/configentries/PTO_config.sql new file mode 100755 index 0000000..df99231 --- /dev/null +++ b/onetime/configentries/PTO_config.sql @@ -0,0 +1,51 @@ +insert into transactional.source_config +(file_mnemonic,file_sheet_mnemonic,block_tag,f1_modified,f1_keyword) +values ('PTOBEN','PTOBEN_PRFN','PTOBEN_PRF_Key_Performance_Parameters','Key Performance Parameters','Key Performance Parameters'), +('PTOBEN','PTOBEN_PRFN','PTOBEN_PRF_varying_speed_test_natural_ambient','Varying Speed Test / Full Throttle Performance @ Natural Ambient','Varying Speed Test / Full Throttle Performance @ Natural Ambient'), +('PTOBEN','PTOBEN_PRFN','PTOBEN_PRF_2hrs_max_power_natural_ambient','2Hrs Max Power Test @ Natural Ambient','2Hrs Max Power Test @ Natural Ambient'), +('PTOBEN','PTOBEN_PRFN','PTOBEN_PRF_varying_load_rated_rpm',' Varying loads @ Rated RPM @ Natural Ambient',' Varying loads @ Rated RPM @ Natural Ambient'), +('PTOBEN','PTOBEN_PRFN','PTOBEN_PRF_varying_load_std_pto','Varying load @ STD. PTO @ Natural Ambient','Varying load @ STD. PTO @ Natural Ambient'), +('PTOBEN','PTOBEN_PRFN','PTOBEN_PRF_smoke_test','Smoke Test @ Natural Ambient','Smoke Test @ Natural Ambient'), +('PTOBEN','PTOBEN_PRFN','PTOBEN_PRF_varying_speed_test_high_ambient','Varying Speed Test / Full Throttle Performance @ High Ambient','Varying Speed Test / Full Throttle Performance @ High Ambient'), +('PTOBEN','PTOBEN_PRFN','PTOBEN_PRF_2hrs_max_power_high_ambient','2Hrs Max Power Test @ High Ambient','2Hrs Max Power Test @ High Ambient'), +('PTOBEN','PTOBEN_PRFN','PTOBEN_PRF_engine_oil_consumption','Engine Oil Consumption @ High Ambient','Engine Oil Consumption @ High Ambient'), + +('PTOBEN','PTOBEN_PRFB','PTOBEN_PRF_Key_Performance_Parameters','Key Performance Parameters','Key Performance Parameters'), +('PTOBEN','PTOBEN_PRFB','PTOBEN_PRF_varying_speed_test_natural_ambient','Varying Speed Test / Full Throttle Performance @ Natural Ambient','Varying Speed Test / Full Throttle Performance @ Natural Ambient'), +('PTOBEN','PTOBEN_PRFB','PTOBEN_PRF_2hrs_max_power_natural_ambient','2Hrs Max Power Test @ Natural Ambient','2Hrs Max Power Test @ Natural Ambient'), +('PTOBEN','PTOBEN_PRFB','PTOBEN_PRF_varying_load_rated_rpm',' Varying loads @ Rated RPM @ Natural Ambient',' Varying loads @ Rated RPM @ Natural Ambient'), +('PTOBEN','PTOBEN_PRFB','PTOBEN_PRF_varying_load_std_pto','Varying load @ STD. PTO @ Natural Ambient','Varying load @ STD. PTO @ Natural Ambient'), +('PTOBEN','PTOBEN_PRFB','PTOBEN_PRF_smoke_test','Smoke Test @ Natural Ambient','Smoke Test @ Natural Ambient'), +('PTOBEN','PTOBEN_PRFB','PTOBEN_PRF_varying_speed_test_high_ambient','Varying Speed Test / Full Throttle Performance @ High Ambient','Varying Speed Test / Full Throttle Performance @ High Ambient'), +('PTOBEN','PTOBEN_PRFB','PTOBEN_PRF_2hrs_max_power_high_ambient','2Hrs Max Power Test @ High Ambient','2Hrs Max Power Test @ High Ambient'), +('PTOBEN','PTOBEN_PRFB','PTOBEN_PRF_engine_oil_consumption','Engine Oil Consumption @ High Ambient','Engine Oil Consumption @ High Ambient'), + +('PTOBEN','PTOBEN_PRFE','PTOBEN_PRF_Key_Performance_Parameters','Key Performance Parameters','Key Performance Parameters'), +('PTOBEN','PTOBEN_PRFE','PTOBEN_PRF_varying_speed_test_natural_ambient','Varying Speed Test / Full Throttle Performance @ Natural Ambient','Varying Speed Test / Full Throttle Performance @ Natural Ambient'), +('PTOBEN','PTOBEN_PRFE','PTOBEN_PRF_2hrs_max_power_natural_ambient','2Hrs Max Power Test @ Natural Ambient','2Hrs Max Power Test @ Natural Ambient'), +('PTOBEN','PTOBEN_PRFE','PTOBEN_PRF_varying_load_rated_rpm',' Varying loads @ Rated RPM @ Natural Ambient',' Varying loads @ Rated RPM @ Natural Ambient'), +('PTOBEN','PTOBEN_PRFE','PTOBEN_PRF_varying_load_std_pto','Varying load @ STD. PTO @ Natural Ambient','Varying load @ STD. PTO @ Natural Ambient'), +('PTOBEN','PTOBEN_PRFE','PTOBEN_PRF_smoke_test','Smoke Test @ Natural Ambient','Smoke Test @ Natural Ambient'), +('PTOBEN','PTOBEN_PRFE','PTOBEN_PRF_varying_speed_test_high_ambient','Varying Speed Test / Full Throttle Performance @ High Ambient','Varying Speed Test / Full Throttle Performance @ High Ambient'), +('PTOBEN','PTOBEN_PRFE','PTOBEN_PRF_2hrs_max_power_high_ambient','2Hrs Max Power Test @ High Ambient','2Hrs Max Power Test @ High Ambient'), +('PTOBEN','PTOBEN_PRFE','PTOBEN_PRF_engine_oil_consumption','Engine Oil Consumption @ High Ambient','Engine Oil Consumption @ High Ambient'), + +('PTOSTD','PTOSTD_PRF','PTOBEN_PRF_Key_Performance_Parameters','Key Performance Parameters','Key Performance Parameters'), +('PTOSTD','PTOSTD_PRF','PTOBEN_PRF_varying_speed_test_natural_ambient','Varying Speed Test / Full Throttle Performance @ Natural Ambient','Varying Speed Test / Full Throttle Performance @ Natural Ambient'), +('PTOSTD','PTOSTD_PRF','PTOBEN_PRF_2hrs_max_power_natural_ambient','2Hrs Max Power Test @ Natural Ambient','2Hrs Max Power Test @ Natural Ambient'), +('PTOSTD','PTOSTD_PRF','PTOBEN_PRF_varying_load_rated_rpm',' Varying loads @ Rated RPM @ Natural Ambient',' Varying loads @ Rated RPM @ Natural Ambient'), +('PTOSTD','PTOSTD_PRF','PTOBEN_PRF_varying_load_std_pto','Varying load @ STD. PTO @ Natural Ambient','Varying load @ STD. PTO @ Natural Ambient'), +('PTOSTD','PTOSTD_PRF','PTOBEN_PRF_smoke_test','Smoke Test @ Natural Ambient','Smoke Test @ Natural Ambient'), +('PTOSTD','PTOSTD_PRF','PTOBEN_PRF_varying_speed_test_high_ambient','Varying Speed Test / Full Throttle Performance @ High Ambient','Varying Speed Test / Full Throttle Performance @ High Ambient'), +('PTOSTD','PTOSTD_PRF','PTOBEN_PRF_2hrs_max_power_high_ambient','2Hrs Max Power Test @ High Ambient','2Hrs Max Power Test @ High Ambient'), +('PTOSTD','PTOSTD_PRF','PTOBEN_PRF_engine_oil_consumption','Engine Oil Consumption @ High Ambient','Engine Oil Consumption @ High Ambient'), + +('PTOBEN','PTOBEN_MPM','PTOBEN_MPM_data_inputs','Data Inputs','Data Inputs'), +('PTOSTD','PTOSTD_MPM','PTOBEN_MPM_data_inputs','Data Inputs','Data Inputs'), + +('PTOBEN','PTOBEN_GVG','PTOBEN_GVG_data_inputs','Data Inputs','Data Inputs'), +('PTOBEN','PTOBEN_GVG','PTOBEN_GVG_graphs','Graphs - for Example','Graphs - for Example'), + + +('PTOSTD','PTOSTD_GVG','PTOBEN_GVG_data_inputs','Data Inputs','Data Inputs'), +('PTOSTD','PTOSTD_GVG','PTOBEN_GVG_graphs','Graphs - for Example','Graphs - for Example') diff --git a/onetime/configentries/control-master.sql b/onetime/configentries/control-master.sql new file mode 100755 index 0000000..a2a0934 --- /dev/null +++ b/onetime/configentries/control-master.sql @@ -0,0 +1,19 @@ + +INSERT INTO fw_core.fw_jobctl_jobstep_master +(client_id, function_id, run_frequency, job_scheduling_day, sch_day_of_month, sch_day_of_week, sch_hour_of_day, sch_minute_of_hour, job_id, step_id, job_step_run_dependency_seuqence, active_flag, +job_name, step_name, job_script_type, job_step_script_name, job_fun_param_array, job_scope, job_scope_qualifier_array, sme_entering, extract_field_name, job_step_description, job_step_objective, created_by, updated_by, create_timestamp, update_timestamp) +values +(21, 1, 'daily', '', '', '', '00:00:00', '00:00:00', 1, 1, 9001, true, 'file_check', 'check_duplicate_files', 'shell_script', '/home/compegence/customer/MMT/sql/scripts/check_duplicate_file.sh', '{}', '', '{}', '', '', '', '', 'Admin', 'Admin', now(), now()) +,(21, 1, 'daily', '', '', '', '00:00:00', '00:00:00', 2, 1, 9002, true, 'stg1_load', 'stg1_load_to_generic_table', 'java', '/home/compegence/customer/MMT/java/generic_table/target/ex1-1.0-SNAPSHOT-shaded.jar', '{}', '', '{}', '', '', '', '', 'Admin', 'Admin', now(), now()) +,(21, 1, 'daily', '', '', '', '00:00:00', '00:00:00', 2, 2, 9003, true, 'stg1_load', 'post_stg1_load_validation', 'sql_fn', 'fw_core.fn_run_post_generic_validation', '{}', '', '{}', '', '', '', '', 'Admin', 'Admin', now(), now()) +,(21, 1, 'daily', '', '', '', '00:00:00', '00:00:00', 3, 1, 9004, true, 'txn_load', 'run_wrapper_txn', 'sql_fn', 'fw_core.fn_run_master_wrapper', '{}', '', '{}', '', '', '', '', 'Admin', 'Admin', now(), now()) +,(21, 1, 'daily', '', '', '', '00:00:00', '00:00:00', 3, 2, 9005, true, 'txn_load', 'txn_load_validations', 'sql_fn', 'fw_core.fn_run_trx_post_validation', '{}', '', '{}', '', '', '', '', 'Admin', 'Admin', now(), now()) +,(21, 1, 'daily', '', '', '', '00:00:00', '00:00:00', 3, 3, 9006, true, 'roll_back', 'roll_back', 'sql_fn', 'fw_core.fn_run_trx_rollback', '{}', '', '{}', '', '', '', '', 'Admin', 'Admin', now(), now()) +,(21, 1, 'daily', '', '', '', '00:00:00', '00:00:00', 3, 4, 9007, true, 'reporting_ods_load', 'reporting_ods_load', 'sql_fn', 'fw_ods.fn_fw_ods_load', '{}', '', '{}', '', '', '', '', 'Admin', 'Admin', now(), now()) +,(21, 1, 'daily', '', '', '', '00:00:00', '00:00:00', 4, 1, 9008, true, 'file_cleanup', 'move_the_files', 'shell_script', '/home/compegence/customer/MMT/sql/scripts/file_move.sh', '{}', '', '{}', '', '', '', '', 'Admin', 'Admin', now(), now()) +--,(21, 1, 'daily', '', '', '', '00:00:00', '00:00:00', 5, 1, 9009, true, 'final_checks', 'final checks before marking runschedule status as success', 'sql', 'ex2.sql', '{}', '', '{}', '', '', '', '', 'Admin', 'Admin', now(), now()) +,(21, 1, 'daily', '', '', '', '00:00:00', '00:00:00', 5, 1, 9009, true, 'archival', 'Archival of satging2 block tables', 'sql_fn', 'fw_core.fn_run_block_archive', '{}', '', '{}', '', '', '', '', 'Admin', 'Admin', now(), now()) +,(21, 1, 'daily', '', '', '', '00:00:00', '00:00:00', 6, 1, 9010, true, 'check counts', 'chech count in fw_core schema', 'sql_fn', 'fw_core.fn_run_check_count', '{}', '', '{}', '', '', '', '', 'Admin', 'Admin', now(), now()) +; + + diff --git a/onetime/configentries/mmt_file_sheet_format.sql b/onetime/configentries/mmt_file_sheet_format.sql new file mode 100755 index 0000000..35321a7 --- /dev/null +++ b/onetime/configentries/mmt_file_sheet_format.sql @@ -0,0 +1,45 @@ +SET search_path TO fw_code; +INSERT INTO fw_core.test_file_sheet_format_master (client_id,function_id,test_type,test_name,file_mnemonic,sheet_name,sheet_format,file_sheet_mnemonic,sheet_format_mnemonic,stg2_function,trx_function,created_by,create_timestamp,updated_by,update_timestamp) VALUES +(20,1,'Field','Field Dry Performance','FTDRY','Tractor specifications','Field_Dry_TractorSpecs','FTDRY_TRS','FTDRY_TRS',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'Field','Field Dry Performance','FTDRY','Summary','Field_Dry_Summary','FTDRY_SUM','FTDRY_SUM',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'Field','Field wet Performance','FTWET','Tractor specifications','Field_Wet_TractorSpecs','FTWET_TRS','FTWET_TRS',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'Field','Field wet Performance','FTWET','Summary','Field_Wet_Summary','FTWET_SUM','FTWET_SUM',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'Field','Field Haulage Performance','FTHLG','Tractor specifications','Field_Haulage_TractorSpecs','FTHLG_TRS','FTHLG_TRS',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'Field','Field Haulage Performance','FTHLG','Summary','Field_Haulage_Summary','FTHLG_SUM','FTHLG_SUM',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'Drawbar','Drawbar Standard Performance','DBSTD','Test Results','Drawbar_Test_Results','DBSTD_TEST','DBSTD_TEST',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'Drawbar','Drawbar OECD Performance','DBOECD','Test Results','Drawbar_Test_Results','DBOECD_TEST','DBOECD_TEST',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'Budni','PTO Performance','BUDNI','PTO Perf','Budni_PTO_Perf','BUDNI_PTO','BUDNI_PTO',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'Budni','Drawbar performance','BUDNI','Drawbar perf','Budni_Drawbar_Perf','BUDNI_DBP','BUDNI_DBP',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +; +INSERT INTO fw_core.test_file_sheet_format_master (client_id,function_id,test_type,test_name,file_mnemonic,sheet_name,sheet_format,file_sheet_mnemonic,sheet_format_mnemonic,stg2_function,trx_function,created_by,create_timestamp,updated_by,update_timestamp) VALUES +(20,1,'Budni','Hydraulic test','BUDNI','Hydraulic test','Budni_Hydraulic_Test','BUDNI_HDL','BUDNI_HDL',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'Budni','Vibration measurement','BUDNI','Vibration measurement','Budni_Vibration_Measurement','BUDNI_VMT','BUDNI_VMT',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'Budni','Location Of CG','BUDNI','Location Of CG','Budni_Location_of_CG','BUDNI_LCG','BUDNI_LCG',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'Budni','Field Performance Test','BUDNI','Field Perf. Test','Budni_Field_Perf','BUDNI_FLD','BUDNI_FLD',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'Budni','Haulage Performance Test','BUDNI','Haulage Perf. Test','Budni_Haulage_Perf','BUDNI_HLG','BUDNI_HLG',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'Budni','Noise Measurement','BUDNI','Noise Measurement','Budni_Noise_Measurement','BUDNI_NMT','BUDNI_NMT',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'In house','Noise Test','IHTNST','Noise Test','InHouse_NoiseTest','IHTNST_NST','IHTNST_NST',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'In house','Brake Test ASEBA 30','IHTBT30','Brake Test','inHouse_BrakeTest30','IHTBT30_BT30','IHTBT30_BT30',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'In house','Brake Test ASEBA 50 ','IHTBT50','Brake Test','inHouse_BrakeTest50','IHTBT50_BT50','IHTBT50_BT50',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'In house','Hot Air Mapping','IHTHAM','Hot Air Mapping','inHouse_HotAirMap','IHTHAM_HAM','IHTHAM_HAM',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +; +INSERT INTO fw_core.test_file_sheet_format_master (client_id,function_id,test_type,test_name,file_mnemonic,sheet_name,sheet_format,file_sheet_mnemonic,sheet_format_mnemonic,stg2_function,trx_function,created_by,create_timestamp,updated_by,update_timestamp) VALUES +(20,1,'In house','Speed and Lead Lag Measurement','IHTSLL','Speed and lead lag measurement','inHouse_SpeedandLeadLagMeasurement','IHTSLL_SLL','IHTSLL_SLL',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'In house','Effort Measurement','IHTEMT','Effort measurement','inHouse_EffortMeasurement','IHTEMT_EMT','IHTEMT_EMT',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'In house','Effort Measurement','IHTEMT','Steering data','inHouse_SteeringData','IHTEMT_STD','IHTEMT_STD',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'In house','CG Measurement','IHTCGM','CG Measurement','inHouse_CGMeasurement','IHTCGM_CGM','IHTCGM_CGM',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'In house','Brake Test Domestic','IHTBTD','Brake Test domestic','inHouse_BrakeTestDomestic','IHTBTD_BTD','IHTBTD_BTD',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'In house','Hyd lift sensitivity','IHTHLS','Hyd lift sensitivity','inHouse_HydLiftSensitivity','IHTHLS_HLS','IHTHLS_HLS',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'PTO','PTO BEN Performance','PTOBEN','Performance -BOOST MODE','PTO_Performance_Boost','PTOBEN_PRFB','PTO_PRF',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'PTO','PTO BEN Performance','PTOBEN','Performance -ECO MODE','PTO_Performance_Eco','PTOBEN_PRFE','PTO_PRF',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'PTO','PTO BEN Performance','PTOBEN','Multipoint Mapping','PTO_MultipointMap_BEN','PTOBEN_MPM','PTO_MPM',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'PTO','PTO BEN Performance','PTOBEN','Governing Graph','PTO_GoverningGraph_BEN','PTOBEN_GVG','PTO_GVG',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +; +INSERT INTO fw_core.test_file_sheet_format_master (client_id,function_id,test_type,test_name,file_mnemonic,sheet_name,sheet_format,file_sheet_mnemonic,sheet_format_mnemonic,stg2_function,trx_function,created_by,create_timestamp,updated_by,update_timestamp) VALUES +(20,1,'PTO','PTO Standard Peformance','PTOSTD','Performance -STANDARD MODE','PTO_Performance_Standard','PTOSTD_PRF','PTO_PRF',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'Budni','Brake Performance Test','BUDNI','Brake Perf Test','Budni_Brake_Perf','BUDNI_BRK','BUDNI_BRK',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'Budni','Air Cleaner Performance Test','BUDNI','Air Cleaner Perf Test','Budni_Air_Cleaner_Perf','BUDNI_ARC','BUDNI_ARC',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'PTO','PTO Standard Peformance','PTOSTD','Multipoint Mapping','PTO_MultipointMap_Standard','PTOSTD_MPM','PTO_MPM',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'PTO','PTO Standard Peformance','PTOSTD','Governing Graph','PTO_GoverningGraph_Standard','PTOSTD_GVG','PTO_GVG',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +,(20,1,'PTO','PTO BEN Performance','PTOBEN','Performance -NORMAL MODE','PTO_Performance_Normal','PTOBEN_PRFN','PTO_PRF',NULL,NULL,CURRENT_USER,NOW(),NULL,NULL) +; diff --git a/onetime/configentries/test_lab_data.sql b/onetime/configentries/test_lab_data.sql new file mode 100755 index 0000000..3d32236 --- /dev/null +++ b/onetime/configentries/test_lab_data.sql @@ -0,0 +1,30 @@ +--select * from test_master + +SET search_path TO transactional; +INSERT INTO transactional.test_master (client_id,function_id,test_name,test_type,test_description,created_by,create_timestamp) VALUES +(20,1,'Field Performance','Field','Field Performance Test', current_user,now()) +,(20,1,'Drawbar Performance','Drawbar','Drawbar Performance Test', current_user,now()) +,(20,1,'PTO Performance','PTO','PTO Performance Test', current_user,now()) +,(20,1,'In House Performance','In House','In House Performance Test', current_user , now()) +,(20,1,'Budni Performance','Budni','Budni Performance Test', current_user,now()) +; + +--select * from test_lab_location_master tllm + +INSERT INTO transactional.test_lab_location_master (client_id,function_id,location_name,soil_type,created_by,create_timestamp) VALUES +(20,1,'Jetsar',NULL,current_user,now()) +,(20,1,'Shivpuri',NULL,current_user,now()) +,(20,1,'Akola',NULL,current_user,now()) +,(20,1,'Sindhnoor',NULL,current_user,now()) +,(20,1,'Tindivanam',NULL,current_user,now()) +,(20,1,'Kumbakonam',NULL,current_user,now()) +,(20,1,'Tadepalligudem',NULL,current_user,now()) +,(20,1,'Punjab',NULL,current_user,now()) +,(20,1,'Other',NULL,current_user,now()) +,(20,1,'Suratgarh (Jetsar)',NULL,current_user,now()) +; +INSERT INTO transactional.test_lab_location_master (client_id,function_id,location_name,soil_type,created_by,create_timestamp) VALUES +(20,1,'Sardargarh (Jetsar)',NULL,current_user,now()) +,(20,1,'Budni',NULL,current_user,now()) +,(20,1,'MRV FD Test Track',NULL,current_user,now()) +; diff --git a/onetime/createtables/common/common_tables.sql b/onetime/createtables/common/common_tables.sql new file mode 100755 index 0000000..62fdfe0 --- /dev/null +++ b/onetime/createtables/common/common_tables.sql @@ -0,0 +1,80 @@ +drop table if exists fw_core.db_run_status; + +drop table if exists fw_core.Test_file_sheet_format_master; + +CREATE TABLE fw_core.test_file_sheet_format_master ( + syspk serial NOT NULL, -- PK + client_id int4 NOT NULL, -- UKA1 + function_id int4 NOT NULL, -- UKA2 + test_type text NOT NULL, -- UKA3 + test_name text NOT NULL, -- UKA4 + file_mnemonic text NOT NULL, -- UKA5 + sheet_name text NOT NULL, + sheet_format text NOT NULL, + file_sheet_mnemonic text NOT NULL, -- UKA6 + sheet_format_mnemonic text NULL, + stg2_function text NULL, + trx_function text NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + + +CREATE TABLE fw_core.db_run_status + ( syspk bigserial NOT NULL, + client_id int, + function_id int, + user_id int, + user_name text, + file_syspk int, + file_mnemonic text, + file_sheet_mnemonic text, + block_name text, + staging_type text, + error_function text, + error_state text, + error_message text, + error_detail text, + error_hint text, + error_context text, + status text, + error_timestamp timestamp default now(), + CONSTRAINT mmt_DB_error_pkey PRIMARY KEY (syspk) + ); + + + +drop table if exists fw_core.check_table_stg_trx_count; +create table fw_core.check_table_stg_trx_count +( +schema_name text, +table_name text, +row_count int, +create_time timestamp DEFAULT CURRENT_TIMESTAMP + +); + +drop table if exists fw_core.check_mnemonic_count; +create table fw_core.check_mnemonic_count +( +table_name text, +syspks text, +file_mnemonic text, +file_sheet_mnemonic text, +row_count int, +create_time timestamp DEFAULT current_timestamp +); + + +DROP TABLE if exists fw_core.check_model_count; +CREATE TABLE fw_core.check_model_count( + table_name text NULL, + syspks text NULL, + file_mnemonic text NULL, + file_sheet_mnemonic text NULL, + tractor_name text NULL, + row_count int4 NULL, + create_timestamp timestamp DEFAULT CURRENT_TIMESTAMP +); diff --git a/onetime/createtables/common/create_config.sql b/onetime/createtables/common/create_config.sql new file mode 100755 index 0000000..449e778 --- /dev/null +++ b/onetime/createtables/common/create_config.sql @@ -0,0 +1,19 @@ +drop table if exists transactional.source_config; +CREATE TABLE transactional.source_config ( + syspk serial NOT NULL, + file_mnemonic varchar(100) NULL, + file_sheet_mnemonic varchar(100) NULL, + block_tag varchar(100) NULL, + f1_source varchar(100) NULL, + f1_modified varchar(100) NULL, + f1_keyword varchar(100) NULL, + row_number_start int4 NULL, + row_previous_number int4 NULL, + row_read_end int4 NULL, + run_time timestamp NULL, + action varchar(50) NULL, + run_date date NULL, + keyword_status int4 NULL DEFAULT 0, + CONSTRAINT source_config_pkey PRIMARY KEY (syspk) +); +CREATE UNIQUE INDEX i_file_mnemonic_source_config ON transactional.source_config (file_mnemonic, file_sheet_mnemonic, f1_modified); diff --git a/onetime/createtables/common/extension.sql b/onetime/createtables/common/extension.sql new file mode 100755 index 0000000..6f66eaf --- /dev/null +++ b/onetime/createtables/common/extension.sql @@ -0,0 +1,3 @@ +SET search_path To staging2; +drop extension tablefunc; +create extension tablefunc; \ No newline at end of file diff --git a/onetime/createtables/control/control_tables.sql b/onetime/createtables/control/control_tables.sql new file mode 100755 index 0000000..589193b --- /dev/null +++ b/onetime/createtables/control/control_tables.sql @@ -0,0 +1,314 @@ +SET search_path To fw_core; + +CREATE DOMAIN fw_flag_bool AS BOOL; + +CREATE DOMAIN fw_flag_YN AS BPCHAR; + +CREATE DOMAIN fw_date AS DATE; + +CREATE DOMAIN fw_num_dimid AS INTEGER; + +CREATE DOMAIN fw_num_bigid AS BIGINT; + +CREATE DOMAIN fw_num_metric AS DECIMAL(12,4); + +CREATE DOMAIN fw_num_array AS INTEGER ARRAY; + +CREATE DOMAIN fw_alphnum AS TEXT; + +CREATE DOMAIN fw_text_array AS TEXT ARRAY; + +CREATE DOMAIN fw_timestamp AS TIMESTAMP; + +CREATE DOMAIN fw_time AS TIME; + +CREATE DOMAIN fw_json AS JSON; + + + +-- Drop table + +DROP TABLE if Exists fw_core.fw_jobctl_jobstep_master; + +CREATE TABLE fw_core.fw_jobctl_jobstep_master ( + syspk bigserial NOT NULL, + client_id fw_core.fw_num_dimid NOT NULL, + function_id fw_core.fw_num_dimid NOT NULL, + run_frequency fw_core.fw_alphnum NOT NULL, + job_scheduling_day fw_core.fw_alphnum NOT NULL, + sch_day_of_month fw_core.fw_alphnum NOT NULL, + sch_day_of_week fw_core.fw_alphnum NOT NULL, + sch_hour_of_day fw_core.fw_time NOT NULL, + sch_minute_of_hour fw_core.fw_time NOT NULL, + job_id fw_core.fw_num_dimid NOT NULL, + step_id fw_core.fw_num_dimid NOT NULL, + job_step_run_dependency_seuqence fw_core.fw_num_dimid NOT NULL, + active_flag fw_core.fw_flag_bool NOT NULL DEFAULT true, + job_name fw_core.fw_alphnum NULL, + step_name fw_core.fw_alphnum NULL, + job_script_type fw_core.fw_alphnum NOT NULL, + job_step_script_name fw_core.fw_alphnum NOT NULL, + job_fun_param_array fw_core.fw_text_array NULL, + job_scope fw_core.fw_alphnum NULL, + job_scope_qualifier_array fw_core.fw_text_array NULL, + sme_entering fw_core.fw_alphnum NULL, + extract_field_name fw_core.fw_alphnum NULL, + job_step_description fw_core.fw_alphnum NULL, + job_step_objective fw_core.fw_alphnum NULL, + created_by fw_core.fw_alphnum NOT NULL, + updated_by fw_core.fw_alphnum NOT NULL, + create_timestamp fw_core.fw_timestamp NOT NULL DEFAULT now(), + update_timestamp fw_core.fw_timestamp NOT NULL DEFAULT now(), + CONSTRAINT fw_jobctl_jobstep_master_pkey PRIMARY KEY (syspk), + CONSTRAINT unique_jobctl_jobstep_master UNIQUE (client_id, function_id, run_frequency, job_id, step_id) +); + +-- Drop table + +DROP TABLE if Exists fw_core.fw_jobctl_jobstep_master; + +CREATE TABLE fw_core.fw_jobctl_jobstep_master ( + syspk bigserial NOT NULL, + client_id fw_core.fw_num_dimid NOT NULL, + function_id fw_core.fw_num_dimid NOT NULL, + run_frequency fw_core.fw_alphnum NOT NULL, + job_scheduling_day fw_core.fw_alphnum NOT NULL, + sch_day_of_month fw_core.fw_alphnum NOT NULL, + sch_day_of_week fw_core.fw_alphnum NOT NULL, + sch_hour_of_day fw_core.fw_time NOT NULL, + sch_minute_of_hour fw_core.fw_time NOT NULL, + job_id fw_core.fw_num_dimid NOT NULL, + step_id fw_core.fw_num_dimid NOT NULL, + job_step_run_dependency_seuqence fw_core.fw_num_dimid NOT NULL, + active_flag fw_core.fw_flag_bool NOT NULL DEFAULT true, + job_name fw_core.fw_alphnum NULL, + step_name fw_core.fw_alphnum NULL, + job_script_type fw_core.fw_alphnum NOT NULL, + job_step_script_name fw_core.fw_alphnum NOT NULL, + job_fun_param_array fw_core.fw_text_array NULL, + job_scope fw_core.fw_alphnum NULL, + job_scope_qualifier_array fw_core.fw_text_array NULL, + sme_entering fw_core.fw_alphnum NULL, + extract_field_name fw_core.fw_alphnum NULL, + job_step_description fw_core.fw_alphnum NULL, + job_step_objective fw_core.fw_alphnum NULL, + created_by fw_core.fw_alphnum NOT NULL, + updated_by fw_core.fw_alphnum NOT NULL, + create_timestamp fw_core.fw_timestamp NOT NULL DEFAULT now(), + update_timestamp fw_core.fw_timestamp NOT NULL DEFAULT now(), + CONSTRAINT fw_jobctl_jobstep_master_pkey PRIMARY KEY (syspk), + CONSTRAINT unique_jobctl_jobstep_master UNIQUE (client_id, function_id, run_frequency, job_id, step_id) +); + +drop table if exists fw_core.fw_jobctl_runschedule; + +CREATE table fw_core.fw_jobctl_runschedule ( +syspk bigserial NOT NULL, +client_id fw_num_dimid NOT NULL, +function_id fw_num_dimid NOT NULL, +latest_runschedule_flag fw_flag_bool NOT NULL DEFAULT '1', +run_schedule_id bigserial NOT NULL, +run_frequency fw_alphnum NOT NULL, +run_schedule_timestamp fw_timestamp NOT NULL , +begin_status fw_alphnum NULL, +end_status fw_alphnum NULL DEFAULT NULL, +end_status_note fw_alphnum null DEFAULT NULL, +object_count fw_num_dimid NULL, +start_time fw_timestamp NULL, +end_time fw_timestamp NULL, +created_by fw_alphnum NOT NULL, +updated_by fw_alphnum NOT NULL, +create_timestamp fw_timestamp NOT NULL DEFAULT now(), +update_timestamp fw_timestamp NOT NULL DEFAULT now(), +CONSTRAINT fw_jobctl_runschedule_pkey PRIMARY KEY (syspk), +CONSTRAINT unique_jobctl_runschedule UNIQUE (client_id, function_id, run_schedule_id, run_frequency)); + +drop table if Exists fw_core.fw_jobctl_runschedule_jobstep ; + +CREATE table fw_core.fw_jobctl_runschedule_jobstep ( +syspk bigserial NOT NULL, +client_id fw_num_dimid NOT NULL, +function_id fw_num_dimid NOT NULL, +latest_runschedule_flag fw_flag_bool NOT NULL DEFAULT '1', +run_schedule_id fw_num_dimid NULL, +run_frequency fw_alphnum NOT NULL, +run_schedule_timestamp fw_timestamp NOT NULL, +job_id fw_num_dimid NOT NULL, +step_id fw_num_dimid NOT NULL, +job_step_run_dependency_seuqence fw_num_dimid NOT NULL, +job_script_type fw_alphnum NOT NULL, +job_step_script_name fw_alphnum NOT NULL, +job_fun_param_array fw_text_array NULL, +job_scope fw_alphnum NULL, +job_scope_qualifier_array fw_text_array NULL, +job_name fw_alphnum NULL, +step_name fw_alphnum NULL, +begin_status fw_alphnum null default NULL, +end_status fw_alphnum null default NULL, +end_status_note fw_alphnum null default NULL, +start_time fw_timestamp NULL, +end_time fw_timestamp NULL, +created_by fw_alphnum NULL, +updated_by fw_alphnum NULL, +create_timestamp fw_timestamp NOT NULL DEFAULT now(), +update_timestamp fw_timestamp NOT NULL DEFAULT now(), +CONSTRAINT fw_jobctl_runschedule_jobstep_pkey PRIMARY KEY (syspk), +CONSTRAINT unique_jobctl_runschedule_jobstep UNIQUE (client_id, function_id, run_schedule_id, run_frequency, job_id, step_id)); + +drop table if exists fw_core.fw_jobctl_file_runschedule; + +CREATE TABLE fw_core.fw_jobctl_file_runschedule ( +syspk bigserial NOT NULL, +client_id fw_num_dimid NOT NULL, +function_id fw_num_dimid NOT NULL, +latest_runschedule_flag fw_flag_bool NOT NULL DEFAULT '1', +run_schedule_id fw_num_dimid NULL, +job_id fw_num_dimid NULL, +step_id fw_num_dimid NULL, +file_syspk fw_num_dimid NOT NULL, +file_name fw_alphnum NOT NULL, +file_mnemonic fw_alphnum NOT NULL, +file_landing_date date NOT NULL, +staging_type fw_alphnum NULL, +begin_status fw_alphnum null default NULL, +end_status fw_alphnum null default NULL, +end_status_note fw_alphnum null default NULL, +start_time fw_timestamp NULL, +end_time fw_timestamp NULL, +created_by fw_alphnum NULL, +updated_by fw_alphnum NULL, +create_timestamp fw_timestamp NOT NULL DEFAULT now(), +update_timestamp fw_timestamp NOT NULL DEFAULT now(), +CONSTRAINT fw_jobctl_file_runschedule_pkey PRIMARY KEY (syspk), +CONSTRAINT unique_fw_jobctl_file_runschedule UNIQUE (client_id, function_id, run_schedule_id,file_syspk)); + +-- Drop table + +DROP TABLE if exists fw_core.fw_jobctl_file_sheet_runschedule; + +CREATE TABLE fw_core.fw_jobctl_file_sheet_runschedule ( + syspk bigserial NOT NULL, + client_id fw_core.fw_num_dimid NOT NULL, + function_id fw_core.fw_num_dimid NOT NULL, + latest_runschedule_flag fw_core.fw_flag_bool NOT NULL DEFAULT true, + run_schedule_id fw_core.fw_num_dimid NULL, + job_id fw_core.fw_num_dimid NULL, + step_id fw_core.fw_num_dimid NULL, + file_syspk fw_core.fw_num_dimid NOT NULL, + sheet_id fw_core.fw_num_dimid NOT NULL, + sheet_name fw_core.fw_alphnum NOT NULL, + file_mnemonic fw_core.fw_alphnum NOT NULL, + sheet_format_mnemonic fw_core.fw_alphnum NULL, + file_sheet_mnemonic fw_core.fw_alphnum NULL, + staging_type fw_alphnum NULL, + begin_status fw_core.fw_alphnum NULL DEFAULT NULL, + end_status fw_core.fw_alphnum NULL DEFAULT NULL, + end_status_note fw_core.fw_alphnum NULL DEFAULT NULL, + start_time fw_core.fw_timestamp NULL, + end_time fw_core.fw_timestamp NULL, + created_by fw_core.fw_alphnum NULL, + updated_by fw_core.fw_alphnum NULL, + create_timestamp fw_core.fw_timestamp NOT NULL DEFAULT now(), + update_timestamp fw_core.fw_timestamp NOT NULL DEFAULT now(), + CONSTRAINT fw_jobctrl_file_sheet_runschedule_pkey PRIMARY KEY (syspk), + CONSTRAINT unique_fw_jobctrl_file_sheet_runschedule UNIQUE (client_id, function_id, file_syspk, sheet_id) +); +-- Drop table + +DROP TABLE if exists fw_core.fw_jobctl_file_sheet_block_run_schedule; + +CREATE TABLE fw_core.fw_jobctl_file_sheet_block_run_schedule ( + syspk bigserial NOT NULL, + client_id fw_core.fw_num_dimid NOT NULL, + function_id fw_core.fw_num_dimid NOT NULL, + latest_runschedule_flag fw_core.fw_flag_bool NOT NULL DEFAULT true, + run_schedule_id fw_core.fw_num_dimid NULL, + file_syspk fw_core.fw_num_dimid NULL, + sheet_id fw_core.fw_num_dimid NULL, + block_table_load_seq fw_core.fw_num_dimid NULL, + block_table_name text NULL, + file_mnemonic fw_core.fw_alphnum NOT NULL, + sheet_format_mnemonic fw_core.fw_alphnum NULL, + file_sheet_mnemonic fw_core.fw_alphnum NOT NULL, + begin_status fw_core.fw_alphnum NULL DEFAULT NULL, + end_status fw_core.fw_alphnum NULL DEFAULT NULL, + end_status_note fw_core.fw_alphnum NULL DEFAULT NULL, + start_time fw_core.fw_timestamp NULL, + end_time fw_core.fw_timestamp NULL, + created_by fw_core.fw_alphnum NULL, + updated_by fw_core.fw_alphnum NULL, + create_timestamp fw_core.fw_timestamp NOT NULL DEFAULT now(), + update_timestamp fw_core.fw_timestamp NOT NULL DEFAULT now(), + CONSTRAINT fw_jobctl_file_sheet_block_run_schedule_pkey PRIMARY KEY (syspk), + CONSTRAINT unique_fw_jobctrl_file_sheet_block_run_schedule UNIQUE (client_id, function_id, file_syspk, sheet_id, block_table_load_seq) +); +-- Drop table + + DROP TABLE if exists staging1.staging_generic_table; + +CREATE TABLE staging1.staging_generic_table ( + syspk int8 NULL, + file_syspk int4 NULL, + file_name varchar(1024) NULL, + file_prefix_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_id int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format_mnemonic varchar(1024) NULL, + file_sheet_mnemonic varchar(1024) NULL, + "row_number" int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL +); diff --git a/onetime/createtables/ods/.sql b/onetime/createtables/ods/.sql new file mode 100755 index 0000000..fb6acbe --- /dev/null +++ b/onetime/createtables/ods/.sql @@ -0,0 +1,180 @@ +drop table if exists trx.trx; + +CREATE TABLE trx.trx ( + syspk serial NOT NULL, + client_id int4 NOT NULL, + function_id int4 NOT NULL, + test_file_mnemonic text NULL, + test_file_sheet_mnemonic text NULL, + test_file_id int4 NULL, + test_file_name text NULL, + test_instance_id int4 NULL, + tractor_make text NULL, + tractor_model text NULL, + tractor_engine_hp int4 NULL, + wheel_drive_type text NULL, + "configuration" text NULL, + test_instance_tractor_id int4 NULL, + season text NULL, + test_date date NULL, + test_date_year int4 NULL, + test_date_quarter int4 NULL, + test_date_month int4 NULL, + test_date_dayofmonth int2 NULL, + test_date_dayofweek int2 NULL, + test_mode text NULL, + test_type text NULL, + test_sub_type text NULL, + test_condition text NULL, + test_purpose text NULL, + test_iteration_number int4 NULL, + test_ambient text NULL, + test_tractor_yn text null, + mahindra_model_yn text null, + location_name text NULL, + name_of_implement text NULL, + type_of_implement text NULL, + implement_weight_kg int4 NULL, + tyre_size text NULL, + tyre_ply_rating int4 NULL, + tyre_pressure_kg_per_cm2 numeric NULL, + engine_speed_var int4 NULL, + engine_load_pct_var int4 NULL, + gear_used text NULL, + gear_used_up_slope_1 text NULL, + gear_used_up_slope_2 text NULL, + gear_used_down_slope text NULL, + gear_forward_reverse text NULL, + gear_pedal_effort_parameters text NULL, + sensor_body_location text NULL, + effort_type text NULL, + engine_rpm_type text NULL, + fuel_consumption_lit_per_hr numeric NULL, + fuel_consumption_lit_per_acr numeric NULL, + area_covered_acr_per_hr numeric NULL, + speed_kmph numeric NULL, + wheel_slippage_pct numeric NULL, + field_efficiency_pct numeric NULL, + productivity numeric NULL, + erpmdrop_straight_1stpass_low int4 NULL, + erpmdrop_straight_1stpass_high int4 NULL, + erpmdrop_straight_2ndpass_low int4 NULL, + erpmdrop_straight_2ndpass_high int4 NULL, + erpmdrop_straight_3rdpass_low int4 NULL, + erpmdrop_straight_3rdpass_high int4 NULL, + erpmdrop_turn_1stpass_low int4 NULL, + erpmdrop_turn_1stpass_high int4 NULL, + erpmdrop_turn_2ndpass_low int4 NULL, + erpmdrop_turn_2ndpass_high int4 NULL, + erpmdrop_turn_3rdpass_low int4 NULL, + erpmdrop_turn_3rdpass_high int4 NULL, + no_of_passes int4 NULL, + depth_of_cut_cm_low numeric NULL, + depth_of_cut_cm_high numeric NULL, + total_dist_travelled_km numeric NULL, + mileage_kmpl numeric NULL, + power_kw numeric NULL, + pull_kgf numeric NULL, + pull_KN numeric NULL, + effort_kg numeric NULL, + power_hp numeric NULL, + torque_kg_m numeric NULL, + torque_Nm numeric NULL, + sfc_g_per_kwh numeric NULL, + sfc_gms_per_hp_hr numeric NULL, + fuelling_mm3_per_stroke_per_cyl numeric NULL, + specific_energy_kWh_per_ltr numeric NULL, + temp_engine_oil_c int4 NULL, + temp_engine_oil_high_c int4 NULL, + temp_trans_oil_c int4 NULL, + temp_trans_oil_high_c int4 NULL, + temp_coolant_c int4 NULL, + temp_coolant_high_c int4 NULL, + temp_fuel_in_c int4 NULL, + temp_fuel_high_c int4 NULL, + temp_fuel_out_c int4 NULL, + temp_water_outlet_c int4 NULL, + temp_exhaust_c int4 NULL, + temp_fuel_temp_c int4 NULL, + pct_of_backup_torque int4 NULL, + equ_cblock_row_number_torque_nm numeric NULL, + max_equ_crankshaft_torque_nm numeric NULL, + load_pct int4 NULL, + load_kg numeric NULL, + required_stopping_distance_m numeric NULL, + actual_stopping_distance_m numeric NULL, + decceleartoin_m_per_s2 numeric NULL, + lifting_time_sec int4 NULL, + lowering_time_sec int4 NULL, + speed_on_high_rpm_kmph numeric NULL, + speed_on_low_rpm_kmph numeric NULL, + speed_on_rated_rpm_kmph numeric NULL, + body_location_temperature int4 NULL, + speed_pto_rpm int4 NULL, + brake_pedal_travel_lh_in_mm int4 NULL, + brake_pedal_travel_rh_in_mm int4 NULL, + brake_pedal_travel_latched_in_mm int4 NULL, + pedal_travel_in_mm int4 null, + noise_dba numeric NULL, + test_file_load_date timestamp NULL, + updated_by text NULL DEFAULT CURRENT_USER, + created_by text NULL DEFAULT CURRENT_USER, + update_timestamp timestamp NULL, + create_timestamp timestamp NULL DEFAULT now(), + CONSTRAINT fw_ads_pkey PRIMARY KEY (syspk) +); + +DROP TABLE if exists trx.trx_detailed; +CREATE TABLE trx.trx_detailed ( + syspk serial NOT NULL, + client_id int4 NOT NULL, + function_id int4 NOT NULL, + test_file_mnemonic text NULL, + test_file_sheet_mnemonic text NULL, + test_file_id int4 NULL, + test_file_name text NULL, + test_instance_id int4 NULL, + tractor_make text NULL, + tractor_model text NULL, + tractor_engine_hp int4 NULL, + wheel_drive_type text NULL, + "configuration" text NULL, + test_insance_tractor_id int4 NULL, + season text NULL, + test_date date NULL, + test_date_year int4 NULL, + test_date_quarter int4 NULL, + test_date_month int4 NULL, + test_date_dayofmonth int2 NULL, + test_date_dayofweek int2 NULL, + test_mode text NULL, + test_type text NULL, + test_sub_type text NULL, + test_condition text NULL, + location_name text NULL, + test_detail_type text NULL, + time_sec numeric NULL, + steering_angle_degree numeric NULL, + effort_kg numeric NULL, + test_file_load_date timestamp NULL, + updated_by text NULL DEFAULT CURRENT_USER, + created_by text NULL DEFAULT CURRENT_USER, + update_timestamp timestamp NULL DEFAULT now(), + create_timestamp timestamp NULL DEFAULT now() +); + +drop table if exists trx.trx_tractor_specifications; +create table trx.trx_tractor_specifications ( + syspk serial NOT NULL, -- PK + Client_Id INT NOT NULL, + Function_Id INT NOT NULL, + Test_file_name text NOT NULL, + Tractor_model text, + Tractor_Spec_group text, + Tractor_spec_parameter text, + Tractor_spec_param_value text, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); \ No newline at end of file diff --git a/onetime/createtables/ods/create_table_fw_ods.sql b/onetime/createtables/ods/create_table_fw_ods.sql new file mode 100755 index 0000000..a5e89cf --- /dev/null +++ b/onetime/createtables/ods/create_table_fw_ods.sql @@ -0,0 +1,426 @@ + +/*********************************************************************************** +Name: Create_table_fw_ods +Desc : Script creates the FW Datatypes and the fw_ods tables which store the final dim and measures and creates the following tables + fw_ods - Stores all the dim and measures for all the test types + fw_ods_detailed - stores the large sets of data such as steering data from IHT. + fw_ods_tractor_specifications - tractor specifications which will be loaded manually +Version Rev: v0.6 +Create Date: 15 April 2021 +Version History: + v0.1 - Base Version + v0.5 - ADDED FW DATA types + v0.6 - Added the fw_ods_detailed and fw_ods_tractor_specifications tables + +*************************************************************************************/ + +set search_path to fw_ods; +-- Create FW DATA TYPEs to ensure there is no data issues. + +-- SERIAL and BIGSERIAL datatypes are used from syspk columns in dim and fact tables. +-- AS UDTs can't be defined on SERIAL data type. + + +CREATE DOMAIN fw_flag_bool AS + BOOL; + + +CREATE DOMAIN fw_flag_YN AS + BPCHAR; + + +CREATE DOMAIN fw_date AS + DATE; + + +CREATE DOMAIN fw_num_dimid AS + INTEGER; + +CREATE DOMAIN fw_num_bigid AS +BIGINT; + + +CREATE DOMAIN fw_num_metric AS + DECIMAL(15,4); + + +CREATE DOMAIN fw_num_array AS + INTEGER ARRAY; + + + CREATE DOMAIN fw_text AS + TEXT; + + +CREATE DOMAIN fw_alphanum AS + TEXT; + + +CREATE DOMAIN fw_text_array AS + TEXT ARRAY; + + +CREATE DOMAIN fw_timestamp AS + TIMESTAMP; + + +CREATE DOMAIN fw_json AS + JSON; + +-- fw_ods table stores all relevant dim and metric/measures. + +drop table if exists fw_ods.fw_ods; + +CREATE TABLE fw_ods.fw_ods ( + syspk bigserial NOT NULL, + client_id fw_num_dimid NOT NULL, + function_id fw_num_dimid NOT NULL, + test_file_mnemonic fw_text NULL, + test_sheet_mnemonic fw_text NULL, + test_name fw_text NULL, + test_file_id fw_num_dimid NULL, + test_file_name fw_text NULL, + test_instance_id fw_num_dimid NULL, + tractor_make fw_text NULL, + tractor_model fw_text NULL, + tractor_engine_hp fw_num_dimid NULL, + wheel_drive_type fw_text NULL, + "configuration" fw_text NULL, + test_instance_tractor_id fw_num_dimid NULL, + season fw_text NULL, + test_date fw_date NULL, + test_date_year fw_num_dimid NULL, + test_date_quarter fw_num_dimid NULL, + test_date_month fw_num_dimid NULL, + test_date_dayofmonth int2 NULL, + test_date_dayofweek int2 NULL, + test_mode fw_text NULL, + test_type fw_text NULL, + test_sub_type fw_text NULL, + test_condition fw_text NULL, + test_purpose fw_text NULL, + test_iteration_number fw_num_dimid NULL, + test_ambient fw_text NULL, + test_tractor_yn fw_text NULL, + mahindra_model_yn fw_text NULL, + location_name fw_text NULL, + type_of_soil fw_text NULL, + name_of_implement fw_text NULL, + type_of_implement fw_text NULL, + implement_weight_kg fw_num_dimid NULL, + tyre_size fw_text NULL, + tyre_ply_rating fw_num_dimid NULL, + tyre_pressure_kg_per_cm2 fw_num_metric NULL, + engine_speed_var fw_num_dimid NULL, + engine_load_pct_var fw_num_dimid NULL, + gear_used fw_text NULL, + gear_used_up_slope_1 fw_text NULL, + gear_used_up_slope_2 fw_text NULL, + gear_used_down_slope fw_text NULL, + gear_forward_reverse fw_text NULL, + gear_pedal_effort_parameters fw_text NULL, + sensor_body_location fw_text NULL, + effort_type fw_text NULL, + engine_rpm_type fw_text NULL, + fuel_consumption_lit_per_hr fw_num_metric NULL, + fuel_consumption_lit_per_acr fw_num_metric NULL, + area_covered_acr_per_hr fw_num_metric NULL, + speed_kmph fw_num_metric NULL, + wheel_slippage_pct fw_num_metric NULL, + field_efficiency_pct fw_num_metric NULL, + productivity fw_num_metric NULL, + erpmdrop_straight_1stpass_low fw_num_dimid NULL, + erpmdrop_straight_1stpass_high fw_num_dimid NULL, + erpmdrop_straight_2ndpass_low fw_num_dimid NULL, + erpmdrop_straight_2ndpass_high fw_num_dimid NULL, + erpmdrop_straight_3rdpass_low fw_num_dimid NULL, + erpmdrop_straight_3rdpass_high fw_num_dimid NULL, + erpmdrop_turn_1stpass_low fw_num_dimid NULL, + erpmdrop_turn_1stpass_high fw_num_dimid NULL, + erpmdrop_turn_2ndpass_low fw_num_dimid NULL, + erpmdrop_turn_2ndpass_high fw_num_dimid NULL, + erpmdrop_turn_3rdpass_low fw_num_dimid NULL, + erpmdrop_turn_3rdpass_high fw_num_dimid NULL, + no_of_passes fw_num_dimid NULL, + depth_of_cut_cm_low fw_num_metric NULL, + depth_of_cut_cm_high fw_num_metric NULL, + total_dist_travelled_km fw_num_metric NULL, + mileage_kmpl fw_num_metric NULL, + power_kw fw_num_metric NULL, + power_hp fw_num_metric NULL, + pull_kgf fw_num_metric NULL, + pull_kn fw_num_metric NULL, + effort_kg fw_num_metric NULL, + torque_kg_m fw_num_metric NULL, + torque_nm fw_num_metric NULL, + sfc_gms_per_hp_hr fw_num_metric NULL, + sfc_g_per_kwh fw_num_metric NULL, + fuelling_mm3_per_stroke_per_cyl fw_num_metric NULL, + specific_energy_kwh_per_ltr fw_num_metric NULL, + temp_engine_oil_c fw_num_dimid NULL, + temp_engine_oil_high_c fw_num_dimid NULL, + temp_trans_oil_c fw_num_dimid NULL, + temp_trans_oil_high_c fw_num_dimid NULL, + temp_coolant_c fw_num_dimid NULL, + temp_coolant_high_c fw_num_dimid NULL, + temp_fuel_in_c fw_num_dimid NULL, + temp_fuel_high_c fw_num_dimid NULL, + temp_fuel_out_c fw_num_dimid NULL, + temp_water_outlet_c fw_num_dimid NULL, + temp_exhaust_c fw_num_dimid NULL, + temp_fuel_temp_c fw_num_dimid NULL, + pct_of_backup_torque fw_num_dimid NULL, + equ_crank_torque_nm fw_num_metric NULL, + max_equ_crankshaft_torque_nm fw_num_metric NULL, + load_pct fw_num_dimid NULL, + load_kg fw_num_metric NULL, + required_stopping_distance_m fw_num_metric NULL, + actual_stopping_distance_m fw_num_metric NULL, + decceleartoin_m_per_s2 fw_num_metric NULL, + lifting_time_sec fw_num_dimid NULL, + lowering_time_sec fw_num_dimid NULL, + speed_on_high_rpm_kmph fw_num_metric NULL, + speed_on_low_rpm_kmph fw_num_metric NULL, + speed_on_rated_rpm_kmph fw_num_metric NULL, + body_location_temperature fw_num_dimid NULL, + speed_pto_rpm fw_num_dimid NULL, + brake_pedal_travel_lh_in_mm fw_num_dimid NULL, + brake_pedal_travel_rh_in_mm fw_num_dimid NULL, + brake_pedal_travel_latched_in_mm fw_num_dimid NULL, + pedal_travel_in_mm fw_num_dimid NULL, + noise_dba fw_num_metric NULL, + test_file_load_date fw_timestamp NULL, + updated_by fw_text NULL , + created_by fw_text NULL DEFAULT CURRENT_USER, + update_timestamp fw_timestamp NULL, + create_timestamp fw_timestamp NULL DEFAULT now(), + CONSTRAINT fw_ods_pkey PRIMARY KEY (syspk) +); + + +-- fw_ods_detailed table is used to store all big data, for example 6k records of stearing data from sensors. +DROP TABLE if exists fw_ods.fw_ods_detailed; +CREATE TABLE fw_ods.fw_ods_detailed ( + syspk serial NOT NULL, + client_id fw_num_dimid NOT NULL, + function_id fw_num_dimid NOT NULL, + test_file_mnemonic fw_num_dimid NULL, + test_sheet_mnemonic fw_num_dimid NULL, + test_file_id fw_num_dimid NULL, + test_file_name fw_text NULL, + test_instance_id fw_num_dimid NULL, + tractor_make fw_text NULL, + tractor_model fw_text NULL, + tractor_engine_hp fw_num_dimid NULL, + wheel_drive_type fw_text NULL, + "configuration" fw_text NULL, + test_insance_tractor_id fw_num_dimid NULL, + season fw_text NULL, + test_date fw_date NULL, + test_date_year fw_num_dimid NULL, + test_date_quarter fw_num_dimid NULL, + test_date_month fw_num_dimid NULL, + test_date_dayofmonth fw_num_dimid NULL, + test_date_dayofweek fw_num_dimid NULL, + test_mode fw_text NULL, + test_type fw_text NULL, + test_sub_type fw_text NULL, + test_condition fw_text NULL, + location_name fw_text NULL, + test_detail_type fw_text NULL, + time_sec fw_num_metric NULL, + steering_angle_degree fw_num_metric NULL, + effort_kg fw_num_metric NULL, + test_file_load_date fw_timestamp NULL, + updated_by text NULL , + created_by text NULL DEFAULT CURRENT_USER, + update_timestamp timestamp NULL , + create_timestamp timestamp NULL DEFAULT now() +); + + +-- fw_ids_tractor_specifications table is used to store all tractor specifications created before mmt testing project starts. +-- the data into table will uploaded by the user manually. + +drop table if exists fw_ods.fw_ods_tractor_specifications; +create table fw_ods.fw_ods_tractor_specifications ( + syspk serial NOT NULL, -- PK + Client_Id fw_num_dimid NOT NULL, + Function_Id fw_num_dimid NOT NULL, + Test_file_name fw_text NOT NULL, + Tractor_model fw_text, + Tractor_Spec_group fw_text, + Tractor_spec_parameter fw_text, + Tractor_spec_param_value fw_text, + Created_By fw_text NULL DEFAULT current_user, + Updated_by fw_text NULL, + Create_timestamp fw_timestamp NULL DEFAULT now(), + update_timestamp fw_TIMESTAMP NULL +); + + +-- fw_ods.fw_ods_comments definition + +-- Drop table + +DROP TABLE if exists fw_ods.fw_ods_comments; + +CREATE TABLE fw_ods.fw_ods_comments ( + syspk bigserial NOT NULL, + client_id fw_ods."fw_num_dimid" NULL, + function_id fw_ods."fw_num_dimid" NULL, + test_file_mnemonic fw_ods."fw_text" NULL, + test_sheet_mnemonic fw_ods."fw_text" NULL, + test_file_id fw_ods."fw_num_dimid" NULL, + test_file_name fw_ods."fw_text" NULL, + test_instance_id fw_ods."fw_num_dimid" NULL, + tractor_make fw_ods."fw_text" NULL, + tractor_model fw_ods."fw_text" NULL, + test_iteration_number fw_ods."fw_num_dimid" NULL, + users fw_ods."fw_text" NULL, + "role" fw_ods."fw_text" NULL, + role_level fw_ods."fw_num_dimid" NULL, + note_or_title fw_ods."fw_text" NULL, + "timestamp" fw_ods."fw_timestamp" NULL, + "sequence" fw_ods."fw_text" NULL, + note_or_comment fw_ods."fw_text" NULL, + created_by fw_ods."fw_text" NULL DEFAULT CURRENT_USER, + updated_by fw_ods."fw_text" NULL, + create_timestamp fw_ods."fw_timestamp" NULL DEFAULT now(), + update_timestamp fw_ods."fw_timestamp" NULL, + old_test_file_name text NULL, + platform text NULL, + benchmark_yn text NULL, + wheel_drive_type text NULL, + tractor_engine_hp int4 NULL, + name_of_implement fw_ods."fw_text" NULL, + type_of_implement fw_ods."fw_text" NULL, + season fw_ods."fw_text" NULL +); + + +-- fw_ods.fw_ods_drawbar_performance definition + +-- Drop table + +DROP TABLE if exists fw_ods.fw_ods_drawbar_performance; + +CREATE TABLE fw_ods.fw_ods_drawbar_performance ( + syspk serial NOT NULL, + client_id fw_ods."fw_num_dimid" NOT NULL, + function_id fw_ods."fw_num_dimid" NOT NULL, + test_file_mnemonic fw_ods."fw_text" NULL, + test_sheet_mnemonic fw_ods."fw_text" NULL, + test_file_id fw_ods."fw_num_dimid" NULL, + test_file_name fw_ods."fw_text" NULL, + test_name fw_ods."fw_text" NULL, + test_instance_id fw_ods."fw_num_dimid" NULL, + tractor_make fw_ods."fw_text" NULL, + tractor_model fw_ods."fw_text" NULL, + tractor_engine_hp fw_ods."fw_num_dimid" NULL, + wheel_drive_type fw_ods."fw_text" NULL, + "configuration" fw_ods."fw_text" NULL, + test_instance_tractor_id fw_ods."fw_num_dimid" NULL, + season fw_ods."fw_text" NULL, + test_date fw_ods."fw_date" NULL, + test_date_year fw_ods."fw_num_dimid" NULL, + test_date_quarter fw_ods."fw_num_dimid" NULL, + test_date_month fw_ods."fw_num_dimid" NULL, + test_date_dayofmonth int2 NULL, + test_date_dayofweek int2 NULL, + test_mode fw_ods."fw_text" NULL, + test_type fw_ods."fw_text" NULL, + test_sub_type fw_ods."fw_text" NULL, + test_condition fw_ods."fw_text" NULL, + test_purpose fw_ods."fw_text" NULL, + test_iteration_number fw_ods."fw_num_dimid" NULL, + test_ambient fw_ods."fw_text" NULL, + test_tractor_yn fw_ods."fw_text" NULL, + mahindra_model_yn fw_ods."fw_text" NULL, + location_name fw_ods."fw_text" NULL, + tyre_size fw_ods."fw_text" NULL, + tyre_ply_rating fw_ods."fw_num_dimid" NULL, + tyre_pressure_kg_per_cm2 fw_ods."fw_num_metric" NULL, + engine_speed_var fw_ods."fw_num_dimid" NULL, + fan_speed_rpm_var fw_ods."fw_num_dimid" NULL, + gear_used fw_ods."fw_text" NULL, + effort_type fw_ods."fw_text" NULL, + engine_rpm_type fw_ods."fw_text" NULL, + fuel_consumption_lit_per_hr fw_ods."fw_num_metric" NULL, + fuel_consumption_kg_per_kwh fw_ods."fw_num_metric" NULL, + sfc_g_per_kwh fw_ods."fw_num_metric" NULL, + speed_kmph fw_ods."fw_num_metric" NULL, + wheel_slippage_pct fw_ods."fw_num_metric" NULL, + wheel_slippage_pct_front fw_ods."fw_num_metric" NULL, + no_of_load_lugs_front fw_ods."fw_num_dimid" NULL, + power_kw fw_ods."fw_num_metric" NULL, + pull_kgf fw_ods."fw_num_metric" NULL, + pull_kn fw_ods."fw_num_metric" NULL, + effort_kg fw_ods."fw_num_metric" NULL, + power_hp fw_ods."fw_num_metric" NULL, + sfc_gms_per_hp_hr fw_ods."fw_num_metric" NULL, + specific_energy_kwh_per_ltr fw_ods."fw_num_metric" NULL, + temp_engine_oil_c fw_ods."fw_num_dimid" NULL, + temp_engine_oil_high_c fw_ods."fw_num_dimid" NULL, + temp_trans_oil_c fw_ods."fw_num_dimid" NULL, + temp_trans_oil_high_c fw_ods."fw_num_dimid" NULL, + temp_coolant_c fw_ods."fw_num_dimid" NULL, + temp_coolant_high_c fw_ods."fw_num_dimid" NULL, + temp_fuel_in_c fw_ods."fw_num_dimid" NULL, + temp_fuel_high_c fw_ods."fw_num_dimid" NULL, + temp_fuel_out_c fw_ods."fw_num_dimid" NULL, + temp_water_outlet_c fw_ods."fw_num_dimid" NULL, + atm_rh_pct fw_ods."fw_num_metric" NULL, + atm_temp_c fw_ods."fw_num_metric" NULL, + atm_pressure_kpa fw_ods."fw_num_metric" NULL, + test_file_load_date fw_ods."fw_timestamp" NULL, + updated_by fw_ods."fw_text" NULL, + created_by fw_ods."fw_text" NULL DEFAULT CURRENT_USER, + update_timestamp fw_ods."fw_timestamp" NULL, + create_timestamp fw_ods."fw_timestamp" NULL DEFAULT now(), + summary_yn text NULL, + test_report_date date NULL, + old_test_file_name fw_ods."fw_text" NULL, + CONSTRAINT fw_ods_drawbar_performance_pkey PRIMARY KEY (syspk) +); + + +-- fw_ods.fw_ods_observations definition + +-- Drop table + +DROP TABLE if exist fw_ods.fw_ods_observations; + +CREATE TABLE fw_ods.fw_ods_observations ( + syspk bigserial NOT NULL, + client_id fw_ods."fw_num_dimid" NULL, + function_id fw_ods."fw_num_dimid" NULL, + test_file_mnemonic fw_ods."fw_text" NULL, + test_sheet_mnemonic fw_ods."fw_text" NULL, + test_file_id fw_ods."fw_num_dimid" NULL, + test_file_name fw_ods."fw_text" NULL, + test_iteration_number fw_ods."fw_num_dimid" NULL, + platform fw_ods."fw_text" NULL, + benchmark_yn fw_ods."fw_text" NULL, + tractor_make fw_ods."fw_text" NULL, + tractor_model fw_ods."fw_text" NULL, + tractor_engine_hp fw_ods."fw_num_dimid" NULL, + wheel_drive_type fw_ods."fw_text" NULL, + name_of_implement fw_ods."fw_text" NULL, + type_of_implement fw_ods."fw_text" NULL, + season fw_ods."fw_text" NULL, + parameters fw_ods."fw_text" NULL, + "sequence" fw_ods."fw_num_dimid" NULL, + tractor_model1 fw_ods."fw_text" NULL, + tractor_model2 fw_ods."fw_text" NULL, + tractor_model3 fw_ods."fw_text" NULL, + tractor_model4 fw_ods."fw_text" NULL, + tractor_model5 fw_ods."fw_text" NULL, + display_yn fw_ods."fw_text" NULL, + created_by fw_ods."fw_text" NULL, + updated_by fw_ods."fw_text" NULL, + create_timestamp fw_ods."fw_timestamp" NULL, + update_timestamp fw_ods."fw_timestamp" NULL, + old_test_file_name fw_ods."fw_text" NULL +); + diff --git a/onetime/createtables/ods/ods_tables.sql b/onetime/createtables/ods/ods_tables.sql new file mode 100755 index 0000000..d91588b --- /dev/null +++ b/onetime/createtables/ods/ods_tables.sql @@ -0,0 +1,2068 @@ +/*********************************************************************************** +Name: Create_TRX_Tables +Desc : Script creates ALL the tables requried for the ODS +Version Rev: v0.6 +Create Date: 15 Jan 2021 +Version History: + v0.1 - Base Version + v0.5 - ADDED IHT tables on 23rd March 2021 + v0.6 - ADDED latest PTO file format changes 21st April 2021 + v0.7 - ADDED unique constraint comments +*************************************************************************************/ + +SET search_path To transactional; +drop table if exists test_master; + +CREATE TABLE test_master ( + syspk serial NOT NULL, -- PK + client_id SMALLINT NOT NULL, -- UKA1 + function_id SMALLINT NOT NULL, -- UKA2 + Test_Name TEXT NOT NULL, -- UKA3 + Test_Type TEXT NOT NULL, + Test_Description TEXT NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + + + + +drop table if exists test_lab_location_master; + +CREATE TABLE test_lab_location_master ( + syspk serial NOT NULL, -- PK + client_id SMALLINT NOT NULL, -- UKA1 + function_id SMALLINT NOT NULL, -- UKA2 + Location_Name TEXT NOT NULL, -- UKA3 + Soil_Type TEXT, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +) ; + +drop table if exists test_instance; + +CREATE TABLE test_instance ( + syspk serial NOT NULL, -- PK + client_id SMALLINT NOT NULL, -- UKA1 + function_id SMALLINT NOT NULL, -- UKA2 + file_syspk INT , -- UKA3 + file_mnemonic TEXT, + file_sheet_mnemonic TEXT , + Test_master_Id INT , + test_file_name TEXT, + project_name TEXT, + Date_of_test date , + Job_Order_No TEXT NULL, + Test_Tractor_ID INT NULL, + Tractor_model TEXT, + Tractor_make TEXT, + Tractor_Sr_No TEXT, + Generation TEXT, + Test_Location_ID INT NULL, + Test_Location_name TEXT, + Test_mode TEXT, + Test_Type TEXT, + Test_Name TEXT, + Test_condition TEXT, + Objective_of_test TEXT, + Background_of_test TEXT, + Test_purpose TEXT, + Test_Standard_Ref TEXT, + Test_Standard_desc TEXT, + Test_Standard_id INT, + Acceptance_Criteria TEXT, + Project_Group TEXT, + Customer_Name TEXT, + No_of_Sample TEXT, + Sample_Receipt_Date date NULL, + Test_Start_Date date NULL, + Test_End_Date date NULL, + Type_of_Soil TEXT, + soil_Moisture_Content_pct NUMERIC NULL, + Soil_Cone_Index NUMERIC NULL, + soil_Bulk_Density_g_per_cc NUMERIC NULL, + Field_Condition TEXT, + Season TEXT, + type_of_Road TEXT, + Gradient_slope_1_Degree INT NULL, + Gradient_slope_2_Degree INT NULL, + tractor_Hitch_Type TEXT, + Tractor_Hitch_Ht_mm INT NULL, + Tractor_RWheel_C2H_dist_mm INT NULL, + Test_Engineer TEXT, + Test_Operator TEXT, + Remarks TEXT, + observations TEXT, + Test_report_No TEXT, + Test_Report_Date date NULL, + Report_Title TEXT, + Report_Prepared_By TEXT, + Report_Reviewed_By TEXT, + Report_Approved_by TEXT, + Report_Prepared_date date, + report_reviewed_date date NULL, + report_approved_date date NULL, + Report_template_No TEXT, + Report_template_Replaces TEXT, + Report_template_Rev_No TEXT, + Report_Template_Rev_Date TEXT, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +) ; +/* This table is for future use */ + +drop table if exists test_instance_images; + +CREATE TABLE test_instance_images ( + SYSPK serial NOT NULL, -- PK + client_id INT NOT NULL, -- UKA1 + function_id INT NOT NULL, -- UKA2 + file_syspk INT NULL, -- UKA3 + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_instance_Id INT , -- UKA4 + Srl_No INT NULL, -- UKA5 + image bytea NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + +drop table if exists test_instance_tractor_info; + +CREATE TABLE test_instance_tractor_info ( + syspk serial NOT NULL, -- PK + client_id SMALLINT NOT NULL, -- UKA1 + function_id SMALLINT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_instance_id INT NULL, -- UKA3 + Tractor_Model TEXT NULL, -- UKA4 + Tractor_Make TEXT , + Tractor_Sr_No TEXT, + Tractor_Engine_HP INT NULL, + Tractor_Platform TEXT, + Configuration TEXT, + Generation TEXT, + Domestic_Export TEXT, + Mahindra_Model_YN TEXT NULL, + Test_Tractor_YN TEXT NULL, + FIP_Type TEXT, + Hour_Meter_Reading INT NULL, + Steering_Type TEXT, + Transmission_Type TEXT, + Transmission_Disc_Diam TEXT, + Wheel_Drive_Type TEXT NULL, + Gear_Ratio NUMERIC NULL, + EGR_YN TEXT, + Brake_Type TEXT, + Brake_Free_Play_LH INT NULL, + Brake_Free_Play_RH INT NULL, + PTO_Type TEXT, + Standard_PTO_Speed_RPM INT NULL, + EPTO_Speed_RPM TEXT NULL, + PTO_Power_HP NUMERIC, + Ballast_Condition TEXT NULL, + Ballasted_Tractor_Accessories TEXT NULL, + Mechanical_Ballast_Rear TEXT NULL, + Mechanical_Ballast_Rear_in_kg INT NULL, + Water_Ballast_Rear_75_PCT TEXT NULL, + Mechanical_Ballast_Front TEXT NULL, + Mechanical_Ballast_Front_Kg INT NULL, + Front_bumper_weight_kg INT NULL, + Total_Ballast_Weight INT NULL, + Tractor_Weight_Front_kg INT NULL, + Tractor_Weight_Rear_kg INT NULL, + Tractor_Weight_Total_kg INT NULL, + Tractor_Weight_Front_observed_kg INT NULL, + Tractor_Weight_Rear_observed_kg INT NULL, + Tractor_Weight_Total_observed_kg INT NULL, + Tractor_Weight_Front_remark TEXT NULL, + Tractor_Weight_Rear_remark TEXT NULL, + Tractor_Weight_Total_remark TEXT NULL, + Unballasted_Max_Speed_kmph NUMERIC NULL, + Road_Ballasted_Max_speed_kmph NUMERIC NULL, + Wheel_Base_mm INT NULL, + Wheel_Track_mm INT, + Overall_Height_mm INT, + Rear_Track_WIdth_mm INT, + Turning_Circle_Diameter_mm INT, + Weight_reactions_front_kg INT, + Weight_reactions_rear_kg INT, + Hitch_Height_mm INT NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + +drop table if exists test_instance_engine_info; + +CREATE TABLE test_instance_engine_info ( + syspk serial NOT NULL, -- PK + client_id SMALLINT NOT NULL, -- UKA1 + function_id SMALLINT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_ID INT NULL, -- UKA3 + Test_instance_Tractor_ID INT NULL, -- UKA4 + Tractor_Model TEXT, + Tractor_Make TEXT , + Tractor_sr_no TEXT, + Engine_Make TEXT, + Engine_Type TEXT, + Engine_Model TEXT, + Engine_Serial_No TEXT, + Low_Idle_Declared TEXT, + Low_idle_Observed INT NULL, + Low_Idle_remark TEXT NULL, + High_Idle_Declared TEXT, + High_idle_Observed INT NULL, + High_Idle_remark TEXT NULL, + Rated_RPM INT NULL, + Rated_RPM_Observed INT NULL, + Rated_RPM_remark TEXT NULL, + Engine_set_RPM INT NULL, + Engine_Power_HP INT NULL, + PTO_Power_HP INT NULL, + Engine_to_PTO_Ratio_540_PTO TEXT NULL, + Engine_to_PTO_Ratio_540E_PTO TEXT NULL, + Engine_Cylinder_No INT NULL, + Engine_Cylinder_Stroke_mm INT NULL, + Engine_Cylinder_Bore_mm NUMERIC NULL, + Engine_Cylinder_Capacity_ltr INT NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +) ; + +drop table if exists test_instance_implement_info; + +CREATE TABLE test_instance_implement_info ( + syspk serial NOT NULL, -- PK + client_id SMALLINT NOT NULL, -- UKA1 + function_id SMALLINT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_instance_ID INT NULL, -- UKA3 + Name_of_Implement TEXT NULL, -- UKA4 + Type_of_Implement TEXT, + Make_of_Implement TEXT, + No_of_Disc_blades_bottoms TEXT NULL, + Type_of_disc_blades_bottoms TEXT, + size_of_bottoms_blades_mm INT NULL, + size_of_bottoms_blades2_mm INT, + size_of_bottoms_blades3_mm INT, + Spacing_of_bottoms_flanges_mm INT NULL, + Cutting_Width_m TEXT, + Implement_Weight_kg INT NULL, + Hitch_Category TEXT, + Span_For_Mounted_Implement_mm INT NULL, + Mast_Height_For_Mounted_Implement_mm TEXT NULL, + Type_of_Cage_wheel_HCW_FCW TEXT, + Cage_wheel_Dia_mm INT NULL, + Cage_wheel_width_mm INT NULL, + Cage_Wheel_weight_kg INT NULL, + Cage_Wheel_Inner_ring_Dia_mm INT NULL, + Cage_Wheel_Outer_ring_Dia_mm INT NULL, + Cage_Wheel_center_ring_Dia_mm INT NULL, + Dist_btwn_Fender_to_FCW_inner_ring_mm INT NULL, + Dist_btwn_LHS_FCW_to_RHS_FCW_mm INT NULL, + Dist_btwn_IW_ring_to_CW_mounting_ring_mm INT NULL, + No_of_angles_on_cage_wheel INT NULL, + No_of_days_of_water_logging INT NULL, + Depth_of_water_mm INT NULL, + Implement_Image_Ref_Id INT NULL, + Length_mm INT NULL, + Width_mm INT NULL, + Height_mm INT NULL, + Gross_mass_kg INT NULL, + No_and_types_of_lugs TEXT NULL, + Size_of_angle_section_mm INT NULL, + Size_of_angle_section2_mm INT, + Size_of_angle_section3_mm INT, + Length_of_lugs_mm INT NULL, + Spacing_of_lugs_mm INT NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + +drop table if exists test_instance_trailer_info; + +CREATE TABLE test_instance_trailer_info ( + syspk serial NOT NULL, -- PK + client_id SMALLINT NOT NULL, -- UKA1 + function_id SMALLINT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_instance_ID INT NULL, -- UKA3 + Type_Of_Trailer TEXT NULL, -- UKA4 + No_Of_Axle INT NULL, -- UKA5 + No_Of_Wheels INT NULL, + Trailer_Hitch_Ht_above_ground_lvl_mm INT NULL, + Make_model_of_trailer TEXT, + Trailer_platform_length_mm INT NULL, + Trailer_platform_Width_mm INT NULL, + Trailer_platform_Height_mm INT NULL, + Tire_size TEXT, + Inflation_pressure_psi INT NULL, + Track_width_of_trailer_mm INT NULL, + Hzntl_Dist_of_hitch_pt_from_trailer_face_mm INT NULL, + Tractor_RWC_to_Hitch_Pt_Center_Dist_mm INT NULL, + Dist_from_Trailer_front_axle_Dist_from_hitch_pt_mm INT NULL, + Dist_from_tractor_RWC_to_trailer_RWC_mm INT NULL, + Trailer_empty_Weight_Kg INT NULL, + Trailer_Gross_Weight_Kg INT NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +) ; + +drop table if exists test_instance_tyre_info; + +CREATE TABLE test_instance_tyre_info ( + syspk serial NOT NULL, -- PK + client_id SMALLINT NOT NULL, -- UKA1 + function_id SMALLINT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_ID INT NULL, -- UKA3 + Test_Instance_Tractor_ID INT NULL,-- UKA4 + Tractor_Model TEXT, + Tractor_Make TEXT , + Tractor_sr_no TEXT, + Tyre_Type TEXT NULL, -- UKA5 + Tyre_Make TEXT NULL, + Tyre_Size TEXT NULL, + tyre_use_type TEXT NULL, + Tyre_Ply_Rating INT NULL, + tyre_Load_Carrying_Capacity TEXT, + tyre_Pressure_psi NUMERIC NULL, + tyre_Pressure_kg_per_cm2 NUMERIC NULL, + tyre_Number_of_lug INT NULL, + tyre_Number_of_no_load_lug_30m INT NULL, + tyre_Lug_Height NUMERIC NULL, + tyre_static_rolling_radius_mm NUMERIC NULL, + tyre_Dynamic_rolling_radius_mm NUMERIC NULL, + tyre_Wheel_Rim_Make_and_Size TEXT, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +) ; + +drop table if exists test_instance_gear_speed_chart; + +CREATE TABLE test_instance_gear_speed_chart ( + syspk serial NOT NULL, -- PK + client_id SMALLINT NOT NULL, -- UKA1 + function_id SMALLINT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_ID INT NULL, -- UKA3 + Test_instance_Tractor_ID INT, -- UKA4 + Tractor_Model TEXT, + Tractor_Make TEXT , + Tyre_condition TEXT NULL, -- UKA5 + Forward_Reverse TEXT NULL, -- UKA6 + Gear TEXT NULL, -- UKA7 + speed_kmph NUMERIC, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +) ; + +drop table if exists test_instance_tractor_info_misc; + +CREATE TABLE test_instance_tractor_info_misc ( + syspk serial NOT NULL, -- PK + client_id SMALLINT NOT NULL, -- UKA1 + function_id SMALLINT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_ID INT NULL, -- UKA3 + Test_instance_Tractor_ID INT, -- UKA4 + Tractor_Model TEXT, + Tractor_Make TEXT , + Capacity_of_fuel_tank_ltr TEXT NULL, + Make_type_and_model_of_injection_pump TEXT, + Manufacturers_production_setting TEXT, + Make_type_and_model_of_injectors TEXT, + Make_type_and_model_of_magneto_coil_and_distributor TEXT, + Make_type_and_model_of_carburetor TEXT, + Ignition_or_injection_timing TEXT, + Aircleaner_Make_model TEXT, + Aircleaner_type TEXT, + Precleaner_make_model TEXT, + Precleaner_type TEXT, + Hydraulic_Type TEXT, + Pump_speed_at_rated_engine_speed_rpm INT, + Pump_HP INT, + Oil TEXT, + Lift_Rod_Type_LH TEXT, + Lift_Rod_Type_RH TEXT, + Lift_Rod_Length_LH INT, + Lift_Rod_Length_RH INT, + Lower_Link_Length_LH INT, + Lower_Link_Length_RH INT, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL + ); + +drop table if exists test_instance_Wheels_info; + +CREATE TABLE test_instance_Wheels_info ( + syspk serial NOT NULL, -- PK + client_id SMALLINT NOT NULL, -- UKA1 + function_id SMALLINT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_ID INT NULL, -- UKA3 + Test_instance_Tractor_ID INT, -- UKA4 + Tractor_Model TEXT, + Tractor_Make TEXT , + Steered_Driving_wheel TEXT, -- UKA5 + Location_of_driving_wheel TEXT, + Make_of_tyres TEXT, + Wheel_Types TEXT, + Wheel_Size TEXT, + Maximum_permissible_load_kg NUMERIC, + Ply_rating INT, + Track_wIdth_max_mm INT, + Track_wIdth_min_mm INT, + Inflation_pressure_kg_per_cm2 NUMERIC, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL + ); + +drop table if exists test_instance_fuel_lubricant_info; + + CREATE TABLE test_instance_fuel_lubricant_info ( + syspk serial NOT NULL, -- PK + client_id SMALLINT NOT NULL, -- UKA1 + function_id SMALLINT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_ID INT NULL, -- UKA3 + Test_instance_Tractor_ID INT, -- UKA4 + Tractor_Model TEXT, + Tractor_Make TEXT , + fuel_lubricant_unit TEXT, + Trade_name TEXT, + fuel_lubricant_Type TEXT, + octane_per_Cetane_Number INT, + Viscocity TEXT, + Density_At_15C TEXT, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL + ); + +drop table if exists test_instance_equipment_info; + +CREATE TABLE test_instance_equipment_info ( + syspk serial NOT NULL, -- PK + client_id SMALLINT NOT NULL, -- UKA1 + function_id SMALLINT NOT NULL, -- UKA2 + file_syspk INT, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_ID INT NULL, -- UKA3 + Test_instance_Tractor_ID INT, -- UKA4 + Tractor_Model TEXT, + Tractor_Make TEXT , + Srl_No INT, + instrument_Name TEXT, -- UKA5 + instrument_Serial_No TEXT, + Calibration_Due_Date date, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL + ); + + drop table if exists test_instance_measurement_uncertainty; + +CREATE TABLE test_instance_measurement_uncertainty ( + syspk serial NOT NULL, -- PK + client_id SMALLINT NOT NULL, -- UKA1 + function_id SMALLINT NOT NULL, -- UKA2 + file_syspk INT, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_ID INT NULL, -- UKA3 + Test_instance_Tractor_ID INT, + Tractor_Model TEXT, + Tractor_Make TEXT, + Load_cell TEXT, + RPM_Meter TEXT, + Speed TEXT, + Fuel_flow_meter TEXT, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL + ); + +drop table if exists test_instance_atmospheric_info; + +CREATE TABLE test_instance_atmospheric_info ( + syspk serial NOT NULL, -- PK + client_id SMALLINT NOT NULL, -- UKA1 + function_id SMALLINT NOT NULL, -- UKA2 + file_syspk INT, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_ID INT NULL, -- UKA3 + Test_instance_Tractor_ID INT, + Tractor_Model TEXT, + Tractor_Make TEXT, + date_of_Test date, + start_time TEXT, + end_time TEXT, + Ambient_temp_C NUMERIC, + humidity_Pct NUMERIC, + Pressure_kPa NUMERIC, + wind_velocity_kmph TEXT, + Background_Noise_dBA NUMERIC, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL + ); + +drop table if exists test_instance_drawbar_info; + +CREATE TABLE test_instance_drawbar_info ( + syspk serial NOT NULL, -- PK + client_id SMALLINT NOT NULL, -- UKA1 + function_id SMALLINT NOT NULL, -- UKA2 + file_syspk INT, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_ID INT NULL, -- UKA3 + Test_instance_Tractor_ID INT, + Tractor_Model TEXT, + Tractor_Make TEXT, + Drawbar_type TEXT, + Test_condition TEXT, + Drawbar_type_name TEXT, -- UKA4 + Drawbar_type_info TEXT, + Height_above_ground_max_mm NUMERIC, + Height_above_ground_min_mm NUMERIC, + Position_related_to_PTO TEXT, + Wheel_Base TEXT, + Required_pull_in_kg NUMERIC, + Actual_Pull_in_kg NUMERIC, + Required_Power_in_hp NUMERIC, + actual_power_in_hp NUMERIC, + Calculated_hitch_height_mm NUMERIC, + actual_hitch_height_mm NUMERIC, + weight_Front_kg INT, + weight_rear_kg INT, + weight_total_kg INT, + status TEXT, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL + ); + + +drop table if exists test_instance_weight_reaction; + + CREATE TABLE test_instance_weight_reaction ( + SYSPK serial NOT NULL, -- PK + Client_Id INT NOT NULL, -- UKA1 + Function_Id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_Id INT NULL, -- UKA3 + Test_Instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Test_Condition TEXT NULL, -- UKA4 + Total_Weight_kg INT NULL, + High_Idle_RPM INT NULL, + Front_Reaction_kg INT NULL, + Rear_Reaction_kg INT NULL, + Left_Reaction_FL_RL_kg INT NULL, + Right_reaction_FR_RR_kg INT NULL, + Front_Left_Reaction_kg INT NULL, + Front_Right_Reactionkg INT NULL, + Rear_Left_Reaction_kg INT NULL, + Rear_Right_Reactionkg INT NULL, + Distance_of_lifting_poINT_from_rear_axle_mm_d1 INT NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + +drop table if exists field_perf_summary; + +CREATE TABLE field_perf_summary ( +syspk Serial NOT NULL, -- PK + client_id SMALLINT NOT NULL, -- UKA1 + function_id SMALLINT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_ID INT NULL, -- UKA3 + Test_Instance_Tractor_ID INT NULL, -- UKA4 + Tractor_Model TEXT NULL, + Tractor_Make TEXT , + Test_iteration_number INT NULL, -- UKA5 + Test_Condition TEXT NULL, + Test_Date date NULL, + Engine_RPM_set INT NULL, + PTO_RPM_set INT NULL, + Gear_used TEXT, + Nominal_Speed_KMPH NUMERIC NULL, + Engine_RPM_Drop_on_straight_1st_Pass TEXT, + Engine_RPM_Drop_on_straight_2nd_Pass TEXT, + Engine_RPM_Drop_on_straight_3rd_Pass TEXT, + Engine_RPM_Drop_on_turn_1st_Pass TEXT, + Engine_RPM_Drop_on_turn_2nd_Pass TEXT, + Engine_RPM_Drop_on_turn_3rd_Pass TEXT, + No_of_passes INT NULL, + Depth_of_cut_cm TEXT, + erpmdrop_straight_1stpass_low numeric NULL, + erpmdrop_straight_1stpass_high numeric NULL, + erpmdrop_straight_2ndpass_low numeric NULL, + erpmdrop_straight_2ndpass_high numeric NULL, + erpmdrop_straight_3rdpass_low numeric NULL, + erpmdrop_straight_3rdpass_high numeric NULL, + erpmdrop_turn_1stpass_low numeric NULL, + erpmdrop_turn_1stpass_high numeric NULL, + erpmdrop_turn_2ndpass_low numeric NULL, + erpmdrop_turn_2ndpass_high numeric NULL, + erpmdrop_turn_3rdpass_low numeric NULL, + erpmdrop_turn_3rdpass_high numeric NULL, + depth_of_cut_cm_low numeric NULL, + depth_of_cut_cm_high numeric NULL, + Gear_used_on_Straight_Road TEXT, + Straight_road_RPM_Drop TEXT, + Gear_used_on_Up_Slope_1 TEXT, + Up_Slope_RPM_Drop_1 TEXT, + Gear_used_on_Up_Slope_2 TEXT, + Up_Slope_RPM_Drop_2 TEXT, + Gear_used_on_Down_Slope TEXT, + Down_Slope_RPM_Shoot_up TEXT, + Avg_speed_of_travel_kmph NUMERIC NULL, + Total_dist_travelled_km NUMERIC NULL, + No_load_speed_kmph NUMERIC NULL, + On_load_speed_kmph NUMERIC NULL, + Fuel_consumption_lit_per_hr NUMERIC NULL, + Mileage_Km_per_Ltr NUMERIC NULL, + Area_covered_acr_per_hr NUMERIC NULL, + Fuel_consumption_lit_per_Acr NUMERIC NULL, + Field_Efficiency_pct NUMERIC NULL, + productivity numeric NULL, + wheel_slippage_pct NUMERIC NULL, + Fuel_consumption_Var_lit_per_hr NUMERIC NULL, + Mileage_Var_Km_per_Ltr NUMERIC NULL, + Area_covered_Var_acr_per_hr NUMERIC NULL, + Fuel_consumption_Var_lit_per_Acr NUMERIC NULL, + Fuel_consumption_Var_pct_lit_per_hr NUMERIC NULL, + Mileage_var_pct_Km_per_Ltr NUMERIC NULL, + Area_covered_Var_pct_acr_per_hr NUMERIC NULL, + Fuel_consumption_Var_pct_lit_per_Acr NUMERIC NULL, + Engine_Smoke_on_Load TEXT, + Engine_acceleration_smoke TEXT, + Range_Gear_Shifting TEXT, + Speed_Gear_Shifting TEXT, + Draft_Response TEXT, + Tractor_Steer_ability TEXT, + Tractor_braking_Perf TEXT, + Front_Visibility TEXT, + Implement_Accessibility TEXT, + Front_Wheel_dragging_at_turning TEXT, + Front_end_lifting_during_operation TEXT, + RPM_Recovery_Time TEXT, + Engine_Vibration TEXT, + Engine_Sound TEXT, + Implement_Lifting_per_Lowering_response TEXT, + Pulverization_Quality TEXT, + Pulverization_Index TEXT, + test_engr_comments TEXT, + test_mgr_comments TEXT, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +) ; + +drop table if exists field_perf_summary_implement_info; + +CREATE TABLE field_perf_summary_implement_info ( + syspk serial NOT NULL, -- PK + client_id SMALLINT NOT NULL, -- UKA1 + function_id SMALLINT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_ID INT NULL, -- UKA3 + Name_of_implement TEXT NULL, -- UKA4 + Implement_Type TEXT, + Implement_Size TEXT, + Hitch_Category TEXT, + Implement_Weight INT NULL, + Type_of_Cage_Wheel TEXT, + Cage_Wheel_Width_mm INT NULL, + Cage_wheel_Weight INT NULL, + Cage_Wheel_inner_and_Outer_Ring_Dia_mm INT NULL, + Cage_Wheel_Center_Ring_Dia_mm INT NULL, + Dist_between_RHS_and_LHS_cage_wheel_Inner_Ring_mm INT NULL, + No_of_angles_on_cage_wheel INT NULL, + Soil_Type TEXT, + soil_Moisture_Content_pct NUMERIC NULL, + soil_Bulk_Density_g_per_cc NUMERIC NULL, + Soil_Cone_Index NUMERIC NULL, + Field_Condition TEXT, + Season TEXT, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + +drop table if exists field_perf_summary_tractor_info; +CREATE TABLE field_perf_summary_tractor_info ( + syspk serial NOT NULL, -- PK + client_id SMALLINT NOT NULL, -- UKA1 + function_id SMALLINT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_ID INT NULL, -- UKA3 + Test_instance_Tractor_ID INT NULL, -- UKA4 + Tractor_Model TEXT NULL, + Tractor_Make TEXT, + Tractor_Engine_HP INT NULL, + Rated_RPM INT NULL, + Transmission_Type TEXT, + Wheel_Drive_Type TEXT NULL, + FIP_Type TEXT, + Steering_Type TEXT, + Tractor_Weight_Front_kg INT NULL, + Tractor_Weight_Rear_kg INT NULL, + Tractor_Weight_Total_kg INT NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +) ; + + DROP TABLE if exists field_perf_summary_trailer_info; + +CREATE TABLE field_perf_summary_trailer_info ( + syspk serial NOT NULL, -- PK + client_id SMALLINT NOT NULL, -- UKA1 + function_id SMALLINT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_ID INT NULL, -- UKA3 + Trailer_type TEXT NULL, -- UKA4 + Tire_size_and_inflation_pressure_psi TEXT, + No_Of_Axle INT NULL, + No_Of_Wheels INT NULL, + Trailer_Gross_Weight_Kg INT NULL, + Tractor_RWC_to_Hitch_PoINT_Center_Dist_mm INT NULL, + Tractor_Hitch_Ht_mm INT NULL, + Trailer_hitch_Height_above_ground_level_mm INT NULL, + Gradient_Slope_1_Degree INT NULL, + Gradient_Slope_2_Degree INT NULL, + Tractor_Hitch_Type TEXT NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +) ; + + DROP TABLE if exists Drawbar_Perf_results_summary; + +CREATE TABLE Drawbar_Perf_results_summary ( + syspk serial NOT NULL, -- PK + client_id SMALLINT NOT NULL, -- UKA1 + function_id SMALLINT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_ID INT NULL, -- UKA3 + Test_instance_Tractor_ID INT, + Tractor_Model TEXT, + Tractor_Make TEXT, + Gear_Number_and_Range TEXT NULL, -- UKA4 + Travel_Speed_Km_per_hr NUMERIC, -- UKA5 + Drawbar_Power_kW NUMERIC, + Drawbar_Power_hp NUMERIC, + Drawbar_Pull_kgf INT, + Drawbar_Pull_kN NUMERIC, + Engine_speed_min_1 INT, + Fan_Speed_min_1 INT, + Wheel_Slip_Pct_Front NUMERIC, + No_of_load_lugs_Front NUMERIC, + Wheel_Slip_Pct_Rear NUMERIC, + Fuel_Consumption_l_per_h NUMERIC, + Fuel_Consumption_Kg_per_kWh NUMERIC, + Fuel_Consumption_g_per_kWh NUMERIC, + Fuel_Consumption_kWh_per_l NUMERIC, + Temp_Engine_oil_C INT, + Temp_Trans_Oil_C INT, + Temp_Coolant_C INT, + Temp_Fuel_In_C INT, + Temp_Fuel_out_C INT, + Atm_conditions_RH_Pct NUMERIC, + Atm_conditions_Temp_C NUMERIC, + Atm_conditions_Pressure_kPa NUMERIC, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL + ); + +DROP TABLE if exists Drawbar_Perf_results; + +CREATE TABLE Drawbar_Perf_results ( + syspk serial NOT NULL, -- PK + client_id SMALLINT NOT NULL, -- UKA1 + function_id SMALLINT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_ID INT NULL, -- UKA3 + Test_instance_Tractor_ID INT, + Tractor_Model TEXT, + Tractor_Make TEXT, + Gear_Number_and_Range TEXT NULL, -- UKA4 + Travel_Speed_Km_per_hr NUMERIC, -- UKA5 + Drawbar_Power_kW NUMERIC, + Drawbar_Power_hp NUMERIC, + Drawbar_Pull_kgf INT, + Drawbar_Pull_kN NUMERIC, + Engine_speed_min_1 INT, + Fan_Speed_min_1 INT, + Wheel_Slip_Pct_Front NUMERIC, + No_of_load_lugs_Front NUMERIC, + Wheel_Slip_Pct_Rear NUMERIC, + Fuel_Consumption_l_per_h NUMERIC, + Fuel_Consumption_Kg_per_kWh NUMERIC, + Fuel_Consumption_g_per_kWh NUMERIC, + Fuel_Consumption_kWh_per_l NUMERIC, + Temp_Engine_oil_C INT, + Temp_Trans_Oil_C INT, + Temp_Coolant_C INT, + Temp_Fuel_In_C INT, + Temp_Fuel_out_C INT, + Atm_conditions_RH_Pct NUMERIC, + Atm_conditions_Temp_C NUMERIC, + Atm_conditions_Pressure_kPa NUMERIC, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL + ); + +DROP TABLE if exists Drawbar_Perf_OECD_results; + + CREATE TABLE Drawbar_Perf_OECD_results ( + syspk serial NOT NULL, -- PK + client_id SMALLINT NOT NULL, -- UKA1 + function_id SMALLINT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_ID INT NULL, -- UKA3 + Test_instance_Tractor_ID INT, + Tractor_Model TEXT, + Tractor_Make TEXT, + Test_Condition TEXT, -- UKA4 + Srl_No TEXT, + Gear_Number_and_Range TEXT, -- UKA5 + Travel_Speed_Km_per_hr NUMERIC, -- UKA6 + Drawbar_Power_kW NUMERIC, + Drawbar_Power_hp NUMERIC, + Drawbar_Pull_kgf INT, + Drawbar_Pull_kN NUMERIC, + Engine_speed_min_1 INT, + Fan_Speed_min_1 INT, + Wheel_Slip_Pct_Front NUMERIC, + No_of_load_lugs_Front NUMERIC, + Wheel_Slip_Pct_Rear NUMERIC, + Fuel_Consumption_l_per_h NUMERIC, + Fuel_Consumption_Kg_per_kWh NUMERIC, + Fuel_Consumption_g_per_kWh NUMERIC, + Fuel_Consumption_kWh_per_l NUMERIC, + Temp_Engine_oil_C INT, + Temp_Trans_Oil_C INT, + Temp_Coolant_C INT, + Temp_Fuel_In_C INT, + Temp_Fuel_out_C INT, + Atm_conditions_RH_Pct NUMERIC, + Atm_conditions_Temp_C NUMERIC, + Atm_conditions_Pressure_kPa NUMERIC, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL + ); + +DROP TABLE if exists Drawbar_Perf_observations; + + CREATE TABLE Drawbar_Perf_observations ( + syspk serial NOT NULL, -- PK + client_id SMALLINT NOT NULL, -- UKA1 + function_id SMALLINT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_ID INT NULL, -- UKA3 + Test_instance_Tractor_ID INT, + Tractor_Model TEXT, + Tractor_Make TEXT, + Srl_No INT NULL, + Test_Parameter TEXT, -- UKA4 + Acceptance_Criteria TEXT, + Observation TEXT, + Remarks TEXT, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL + ); + + DROP TABLE if exists PTO_Perf_results; + + CREATE TABLE PTO_Perf_results ( + SYSPK serial NOT NULL, -- PK + client_id INT NOT NULL, -- UKA1 + function_id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_instance_Id INT NULL, -- UKA3 + Test_instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Test_Mode TEXT NULL, -- UKA4 + PTO_Test_Type TEXT NULL, -- UKA5 + PTO_Test_sub_type TEXT NULL, -- UKA6 + Serial_number TEXT NULL, + Speed_Engine_rpm INT NULL, -- UKA7 + Speed_PTO_rpm NUMERIC NULL, + Brake_Torque_N_m NUMERIC NULL, + Brake_Torque_Kg_m NUMERIC NULL, + power_kw NUMERIC NULL, + power_hp NUMERIC NULL, + Eq_Cblock_row_number_Torque_Nm NUMERIC NULL, + Fuel_Consumption_Kg_per_hr NUMERIC NULL, + Fuel_Consumption_gm_per_hp_hr NUMERIC NULL, + Fuel_Consumption_kg_per_kWh NUMERIC NULL, + Fuel_Consumption_ltr_per_hr NUMERIC NULL, + Fuel_Consumption_mm3_per_Str_Per_Cyl NUMERIC NULL, + Sp_Energy_kwh_per_ltr NUMERIC NULL, + Temperatures_Fuel_C NUMERIC NULL, + Temperatures_Ambient_C NUMERIC NULL, + Temperatures_Air_INTake_C NUMERIC NULL, + Temperatures_Water_outlet_C NUMERIC NULL, + Temperatures_Exhaust_C NUMERIC NULL, + Temperatures_Engine_oil_C NUMERIC NULL, + Pressure_Ambient_Bar NUMERIC NULL, + Pressure_Ambient_mm_of_hg NUMERIC NULL, + Pressure_Exhaust_Bar NUMERIC NULL, + Pressure_Exhaust_mm_of_hg NUMERIC NULL, + Pressure_Lub_oil_Bar NUMERIC NULL, + Pressure_Lub_oil_mm_of_hg NUMERIC NULL, + RH_pct NUMERIC NULL, + Average_YN TEXT NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + + + DROP TABLE if exists PTO_Key_Perf_Parameters; + +create table PTO_Key_Perf_Parameters ( + SYSPK serial NOT NULL, -- PK + client_id INT NOT NULL, -- UKA1 + function_id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_instance_Id INT NULL, -- UKA3 + Test_instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Tractor_serial_number TEXT NULL, + Tractor_Emission TEXT NULL, + Test_standard TEXT NULL, -- ICT + Test_Mode TEXT NULL, -- UKA4 (Standard, Normal, Boost, Eco) + PTO_Gear_Ratio NUMERIC NULL, + Specific_gravity_of_fuel_kg_per_m3 NUMERIC NULL, + PTO_Power_Declared_hp TEXT NULL, + PTO_Power_Observed_hp NUMERIC NULL, + PTO_Power_Declared_Kw TEXT NULL, + PTO_Power_Observed_Kw NUMERIC NULL, + PTO_SFC_Declared_gm_per_hp_hr TEXT NULL, + PTO_SFC_Observed_gm_per_hp_hr NUMERIC NULL, + PTO_SFC_Declared_kg_per_Kw_hr TEXT NULL, + PTO_SFC_Observed_kg_per_Kw_hr NUMERIC NULL, + pct_of_Backup_Torque_Declared TEXT NULL, + pct_of_Backup_Torque_Observed NUMERIC NULL, + Max_Equ_crankshaft_Torque_Declared_Nm TEXT NULL, + Max_Equ_crankshaft_Torque_Observed_Nm NUMERIC NULL, + Equ_crankshaft_Torque_at_Max_Power_Declared_Nm TEXT NULL, + Equ_crankshaft_Torque_at_Max_Power_Observed_Nm NUMERIC NULL, + Engine_speed_at_max_equ_crankshaft_torque_Declared_rpm TEXT NULL, + Engine_speed_at_max_equ_crankshaft_torque_Observed_rpm NUMERIC NULL, + Rated_Engine_Speed_Declared_rpm TEXT NULL, + Rated_Engine_Speed_Observed_rpm NUMERIC NULL, + Max_Torque_Engine_Speed_Declared_rpm TEXT NULL, + Max_Torque_Engine_Speed_Observed_rpm NUMERIC NULL, + Engine_High_Idle_Speed_Declared_rpm TEXT NULL, + Engine_High_Idle_Speed_Observed_rpm NUMERIC NULL, + Engine_Low_Idle_Speed_Declared_rpm TEXT NULL, + Engine_Low_Idle_Speed_Observed_rpm NUMERIC NULL, + Engine_Oil_Temp_at_NA_Declared_C TEXT NULL, + Engine_Oil_Temp_at_NA_Observed_C NUMERIC NULL, + Coolant_Temp_at_NA_Declared_C TEXT NULL, + Coolant_Temp_at_NA_Observed_C NUMERIC NULL, + Engine_Oil_Temp_at_HA_Declared_C TEXT NULL, + Engine_Oil_Temp_at_HA_Observed_C NUMERIC NULL, + Coolant_Temp_at_HA_Declared_C TEXT NULL, + Coolant_Temp_at_HA_Observed_C NUMERIC NULL, + Ambient_Pressure_Declared_Bar TEXT NULL, + Ambient_Pressure_Observed_Bar NUMERIC NULL, + Ambient_Pressure_Declared_mm_of_Hg TEXT NULL, + Ambient_Pressure_Observed_mm_of_Hg NUMERIC NULL, + Back_Pressure_Declared_Bar TEXT NULL, + Back_Pressure_Observed_Bar NUMERIC NULL, + Back_Pressure_Declared_mm_of_hg TEXT NULL, + Back_Pressure_Observed_mm_of_hg NUMERIC NULL, + Engine_Oil_Pressure_Declared_Bar TEXT NULL, + Engine_Oil_Pressure_Observed_Bar NUMERIC NULL, + Exhaust_Temp_Declared_C TEXT NULL, + Exhaust_Temp_Observed_C NUMERIC NULL, + Relative_Humidity_Declared_pct TEXT NULL, + Relative_Humidity_Observed_pct NUMERIC NULL, + Coolant_water_pct_of_total_coolant_capacity_Declared TEXT NULL, + Coolant_water_pct_of_total_coolant_capacity_Observed NUMERIC NULL, + Test_Engineer TEXT NULL, + Test_Bed TEXT NULL, + Location_name TEXT NULL, + Total_Run_hrs INT NULL, + Test_date date NULL, + Tooled_up TEXT NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + + DROP TABLE if exists PTO_smoke_Test; + +create table PTO_smoke_Test ( + SYSPK serial NOT NULL, -- PK + client_id INT NOT NULL, -- UKA1 + function_id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_instance_Id INT NULL, -- UKA3 + Test_instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Test_mode TEXT NULL, -- UKA4 + PTO_Test_Type TEXT NULL, -- UKA5 + Srl_no TEXT NULL, + Engine_speed_rpm INT NULL, -- UKA6 + PTO_Speed_rpm INT NULL, + Torque_100_pct NUMERIC NULL, + Torque_80_pct NUMERIC NULL, + Smoke_FSN_100_pct NUMERIC NULL, + Smoke_FSN_80_pct NUMERIC NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + + DROP TABLE if exists PTO_Engine_oil_consumption; + +create table PTO_Engine_oil_consumption ( + SYSPK serial NOT NULL, -- PK + client_id INT NOT NULL, -- UKA1 + function_id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_instance_Id INT NULL, -- UKA3 + Test_instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Test_mode TEXT NULL, -- UKA4 + PTO_Test_Type TEXT NULL, -- UKA5 + Srl_No TEXT NULL, -- UKA6 + Oil_Consumption_Gm_per_hr NUMERIC NULL, + Oil_consumption_pct_of_Fuel_consumption NUMERIC NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + + DROP TABLE if exists PTO_Multipoint_mapping; + +Create table PTO_Multipoint_mapping ( + SYSPK serial NOT NULL, -- PK + client_id INT NOT NULL, -- UKA1 + function_id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_instance_Id INT NULL, -- UKA3 + Test_instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Test_mode TEXT NULL, -- UKA4 + Test_condition TEXT NULL, -- UKA5 + Engine_speed_rpm INT NULL, -- UKA6 + Engine_load_pct INT NULL, -- UKA7 + SFC_gm_per_hp_hr NUMERIC NULL, + Fuel_Consumption_ltr_per_hr NUMERIC NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL + ); + +DROP TABLE if exists PTO_Perf_Governing_Graph; + +Create table PTO_Perf_Governing_Graph ( + SYSPK serial NOT NULL, -- PK + client_id INT NOT NULL, -- UKA1 + function_id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_instance_Id INT NULL, -- UKA3 + Test_instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Test_mode TEXT NULL, -- UKA4 + Test_type TEXT NULL, + Test_condition TEXT NULL, -- UKA5 + Engine_Speed_rpm INT NULL, -- UKA6 + Torque_Kg_m NUMERIC NULL, + Power_hp NUMERIC NULL, + SFC_gm_per_hp_hr NUMERIC NULL, + Fuelling_mm3_per_stroke_per_cyl NUMERIC NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + +DROP TABLE if exists Budni_PTO_Perf_Results_summary; + +create table Budni_PTO_Perf_Results_summary ( + SYSPK serial NOT NULL, -- PK + client_id INT NOT NULL, -- UKA1 + function_id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_instance_Id INT NULL, -- UKA3 + Test_instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + PTO_Category TEXT NULL, -- UKA4 + PTO_Sub_Category TEXT NULL, -- UKA5 + Power_kW NUMERIC NULL, + Speed_rpm_PTO INT NULL, + Speed_rpm_Engine INT NULL, + Fuel_Consumption_ltr_per_hr NUMERIC NULL, + Fuel_Consumption_kg_per_hr NUMERIC NULL, + specific_kg_per_kWh NUMERIC NULL, + Specific_Energy_kWhl NUMERIC NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + +DROP TABLE if exists Budni_PTO_Perf_Results_Details; + +create table Budni_PTO_Perf_Results_Details ( + SYSPK serial NOT NULL, -- PK + client_id INT NOT NULL, -- UKA1 + function_id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_instance_Id INT NULL, -- UKA3 + Test_instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Ambient_type TEXT NULL, -- UKA4 + No_load_max_engine_speed_rpm INT NULL, + equi_crankshaft_torque_at_max_power_Nm NUMERIC NULL, + max_equi_crankshaft_torque_Nm INT NULL, + Engine_speed_at_max_equi_crankshaft_torque_rpm NUMERIC NULL, + Backup_torque TEXT NULL, + Pct_Smoke_level_max_light_absorption_coef_per_mtr NUMERIC NULL, + Range_of_atm_conditions_Temp_C TEXT NULL, + Range_of_atm_conditions_Pressure_kPa TEXT NULL, + Range_of_atm_conditions_Rel_HumIdity_Pct TEXT NULL, + max_temp_Engine_Oil_C INT NULL, + max_temp_Coolant_water_C INT NULL, + max_temp_Fuel_c INT NULL, + max_temp_Air_INTake_C TEXT NULL, + max_temp_Exhaust_Gas_C INT NULL, + Pressure_at_max_Power_INTake_Air_kPa TEXT NULL, + Pressure_at_max_Power_Exhst_gas_bfr_turbo_charger_kPa TEXT NULL, + Consumptions_Lub_oil_gkWh NUMERIC NULL, + Consumptions_coolant_Water_Pct_of_total_coolant_capacity NUMERIC NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + + DROP TABLE if exists Budni_Drawbar_Perf_Results; + +create table Budni_Drawbar_Perf_Results ( + SYSPK serial NOT NULL, -- PK + client_id INT NOT NULL, -- UKA1 + function_id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_instance_Id INT NULL, -- UKA3 + Test_instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Test_Condtion TEXT NULL, -- UKA4 + Gear_Used TEXT NULL, -- UKA5 + Travel_speed_km_per_hr NUMERIC NULL, + Drawbar_Power_kW NUMERIC NULL, + Drawbar_Pull_kN NUMERIC NULL, + Engine_speed_rpm INT NULL, + Wheel_Slippage_Pct NUMERIC NULL, + Fuel_Consumption_Kg_per_kWh NUMERIC NULL, + Fuel_consumption_ltr_per_hr NUMERIC NULL, + specific_energy_kwh_per_ltr NUMERIC NULL, + Temp_Fuel_C TEXT NULL, + Temp_trans_oil_C TEXT NULL, + Temp_Coolant_C TEXT NULL, + Temp_Engine_oil_C TEXT NULL, + Atmosp_conditions_RH_Pct TEXT NULL, + Atmosp_conditions_Temp_C TEXT NULL, + Atmosp_conditions_Pressure_kPa TEXT NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + +DROP TABLE if exists Budni_Hydraulic_Power_test_Results; + +create table Budni_Hydraulic_Power_test_Results ( + SYSPK serial NOT NULL, -- PK + client_id INT NOT NULL, -- UKA1 + function_id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_instance_Id INT NULL, -- UKA3 + Test_instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Pump_dlvry_rate_at_min_pressure_engine_speed_l_per_min NUMERIC NULL, + Max_hydraulic_power_kW NUMERIC NULL, + Pump_dlvry_rate_at_Max_hydraulic_power_lmin NUMERIC NULL, + Pressure_at_Max_hydraulic_power_MPa NUMERIC NULL, + Sustained_pressure_of_the_open_relief_valve_Mpa NUMERIC NULL, + tapping_poINT_Relief_valve_test TEXT NULL, + tapping_PoINT_Pump_perf_test TEXT NULL, + tapping_PoINT_Temperature_of_hydraulic_fluId_C TEXT NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + + DROP TABLE if exists Budni_Hydraulic_Lifting_Capacity_test_Results; + +create table Budni_Hydraulic_Lifting_Capacity_test_Results ( + SYSPK serial NOT NULL, -- PK + client_id INT NOT NULL, -- UKA1 + function_id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_instance_Id INT NULL, -- UKA3 + Test_instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Test_condition TEXT NULL, -- UKA4 + Height_of_lower_hitch_pt_above_ground_in_down_position_mm INT NULL, + Vertical_move_ment_with_lifting_forces_mm INT NULL, + Max_force_exerted_through_full_range_kN NUMERIC NULL, + Corresponding_pressure_MPa INT NULL, + Moment_about_rear_axle_kN_m NUMERIC NULL, + Max_tilt_angle_of_mast_from_vertical_degrees NUMERIC NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + + DROP TABLE if exists Budni_Hydraulic_Maint_of_lift_Load_Results; + +create table Budni_Hydraulic_Maint_of_lift_Load_Results ( + SYSPK serial NOT NULL, -- PK + client_id INT NOT NULL, -- UKA1 + function_id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_instance_Id INT NULL, -- UKA3 + Test_instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Elapsed_time_min INT NULL, -- UKA4 + Force_applied_at_the_frame_kN NUMERIC NULL, + Temp_of_hydraulic_fluid_at_the_start_of_test_C TEXT NULL, + Cumulative_drop_in_height_of_lift_mm NUMERIC NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + + DROP TABLE if exists Budni_Brake_Perf_Service_Brake_Test_Results; + +create table Budni_Brake_Perf_Service_Brake_Test_Results ( + SYSPK serial NOT NULL, -- PK + client_id INT NOT NULL, -- UKA1 + function_id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_instance_Id INT NULL, -- UKA3 + Test_instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Brake_Test_Type TEXT NULL, -- UKA4 + Brake_Test_Name TEXT NULL, -- UKA5 + Speed_condition TEXT NULL, -- UKA6 + Ballast_Condition TEXT NULL, -- UKA7 + Trial_number INT NULL, -- UKA8 + Braking_device_control_force_N INT NULL, + Mean_deceleration_msec2 NUMERIC NULL, + Stopping_Dist_m NUMERIC NULL, + Max_dev_of_tractor_from_its_org_course_m TEXT NULL, + Abnormal_vibration TEXT NULL, + The_brakes_were_heated_by TEXT NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + + DROP TABLE if exists Budni_Brake_Perf_Parking_Brake_Test_Results; + +create table Budni_Brake_Perf_Parking_Brake_Test_Results ( + SYSPK serial NOT NULL, -- PK + client_id INT NOT NULL, -- UKA1 + function_id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_instance_Id INT NULL, -- UKA3 + Test_instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Test_condition TEXT NULL, -- UKA4 + Braking_device_control_force_N_Facing_up INT NULL, + Efficacy_of_parking_brake_Facing_up TEXT NULL, + Braking_device_control_force_N_Facing_down INT NULL, + Efficacy_of_parking_brake_Facing_down TEXT NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + +DROP TABLE if exists Budni_Noise_Atmospheric_conditions; + +create table Budni_Noise_Atmospheric_conditions( + SYSPK serial NOT NULL, -- PK + client_id INT NOT NULL, -- UKA1 + function_id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_instance_Id INT NULL, -- UKA3 + Test_instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Noise_position TEXT NULL, -- UKA4 + Background_noise_level_dBA INT NULL, + Temperature_C INT NULL, + Pressure_kPa NUMERIC NULL, + Relative_humIdity_Pct INT NULL, + Wind_velocity_ms NUMERIC NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + +DROP TABLE if exists Budni_Noise_Measurement_Results; + +create table Budni_Noise_Measurement_Results ( + SYSPK serial NOT NULL, -- PK + client_id INT NOT NULL, -- UKA1 + function_id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_instance_Id INT NULL, -- UKA3 + Test_instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Noise_position TEXT NULL, -- UKA4 + Gear TEXT NULL, -- UKA5 + Drawbar_pull_max_noise_kN TEXT NULL, + Travel_speed_km_per_hr TEXT NULL, + Noise_level_dB_A NUMERIC NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + + DROP TABLE if exists Budni_Vibration_Measurement; + +create table Budni_Vibration_Measurement ( + SYSPK serial NOT NULL, -- PK + client_id INT NOT NULL, -- UKA1 + function_id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_instance_Id INT NULL, -- UKA3 + Test_instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Srl_No INT NULL, + Measuring_Points TEXT NULL, -- UKA4 + Vibration_At_no_load_VD_microns INT NULL, + Vibration_At_no_load_HD_microns INT NULL, + Vibration_At_load_85_Pct_of_max_PTO_Power_VD_microns INT NULL, + Vibration_At_load_85_Pct_of_max_PTO_Power_HD_microns INT NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + + DROP TABLE if exists Budni_Centre_of_Gravity_Location; + +create table Budni_Centre_of_Gravity_Location ( + SYSPK serial NOT NULL, -- PK + client_id INT NOT NULL, -- UKA1 + function_id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_instance_Id INT NULL, -- UKA3 + Test_instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + condition TEXT NULL, -- UKA4 + Particulars TEXT NULL, -- UKA5 + coordinates TEXT NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + + DROP TABLE if exists Budni_Field_Perf_Results; + +create table Budni_Field_Perf_Results ( + SYSPK serial NOT NULL, -- PK + Client_Id INT NOT NULL, -- UKA1 + Function_Id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_Id INT NULL, -- UKA3 + Test_Instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Operation_type TEXT NULL, -- UKA4 + Type_of_soil TEXT NULL, + Avg_soil_moisture_pct_ TEXT NULL, + Avg_depth_of_standing_water_cm TEXT NULL, + Bulk_density_of_soil_g_per_cc TEXT NULL, + Cone_index_kgf_per_sq_cm TEXT NULL, + Puddling_index_pct TEXT NULL, + Gear_used TEXT NULL, + Avg_speed_of_operation_kmph TEXT NULL, + Avg_wheel_slip_pct TEXT NULL, + Avg_Travel_reduction_pct TEXT NULL, + Avg_depth_of_cut_cm TEXT NULL, + Avg_Depth_of_puddle_cm TEXT NULL, + Avg_working_width_cm TEXT NULL, + Area_covered_ha_per_hr TEXT NULL, + Fuel_consumption_ltr_per_hr TEXT NULL, + Fuel_consumption_ltr_per_ha TEXT NULL, + Avg_draft_of_implement_kN TEXT NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + +DROP TABLE if exists Budni_Haulage_Perf_Results; + +create table Budni_Haulage_Perf_Results ( + SYSPK serial NOT NULL, -- PK + client_id INT NOT NULL, -- UKA1 + function_id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_instance_Id INT NULL, -- UKA3 + Test_instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Trailer_type TEXT NULL, -- UKA4 + Gross_mass_of_trailer_tonne INT NULL, + Height_of_trailer_hitch_above_ground_level_mm INT NULL, + Gear_used_negotiating_slopes_up_to_8Pct TEXT NULL, + Avg_travel_speed_kmph TEXT NULL, + Avg_fuel_consumption_ltr_per_hr TEXT NULL, + Avg_fuel_consumption_ml_per_km_per_tonne TEXT NULL, + Avg_Dist_traveled_per_litre_of_fuel_consumption_km TEXT NULL, + Effectiveness_of_Brakes TEXT NULL, + Maneuverability_of_tractor_trailer_combination TEXT NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + + DROP TABLE if exists Budni_Air_Cleaner_Perf_Results; + +create table Budni_Air_Cleaner_Perf_Results ( + SYSPK serial NOT NULL, -- PK + client_id INT NOT NULL, -- UKA1 + function_id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_instance_Id INT NULL, -- UKA3 + Test_instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Sequence_Number INT NULL, -- UKA4 + Atm_Condtion_temperature_C TEXT NULL, + Atm_Condition_Pressure_kPa TEXT NULL, + Atm_Condition_Relative_humIdity_Pct NUMERIC NULL, + Atm_condtion_mass_of_oil_before_test NUMERIC NULL, + Position_of_tractor TEXT NULL, + Loss_of_oil_g NUMERIC NULL, + Oil_pull_Over_Pct NUMERIC NULL, + Engine_oil_pressure TEXT NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + + DROP TABLE if exists Budni_Test_observations; + + +create table Budni_Test_observations( + SYSPK serial NOT NULL, -- PK + client_id INT NOT NULL, -- UKA1 + function_id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_instance_Id INT NULL, -- UKA3 + Test_instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + sequence_number INT NULL, -- UKA4 + Srl_No TEXT NULL, + Characteristic TEXT NULL, + Category_Evaluative_or_Non_Evaluative TEXT NULL, + Requirements_as_per_IS_12207_2008 TEXT NULL, + Values_declared_by_the_applicant_D_Rqmt TEXT NULL, + As_observed TEXT NULL, + Whether_meets_the_requirements_YN TEXT NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + +DROP TABLE if exists IHT_CGM_Lifting_Angle_Load_Details; + +CREATE TABLE IHT_CGM_Lifting_Angle_Load_Details ( + SYSPK serial NOT NULL, -- PK + Client_Id INT NOT NULL, -- UKA1 + Function_Id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_Id INT NULL, -- UKA3 + Test_Instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Angle NUMERIC NULL, -- UKA4 + Value_in_tan NUMERIC NULL, + Diff_Of_tan_value NUMERIC NULL, + Load_kn NUMERIC NULL, + Load_kg NUMERIC NULL, + Diff_in_Load_kg NUMERIC NULL, + Vertical_Co_Ordinate_Z_mm NUMERIC NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + + DROP TABLE if exists IHT_CGM_Results; + +CREATE TABLE IHT_CGM_Results ( + SYSPK serial NOT NULL, -- PK + Client_Id INT NOT NULL, -- UKA1 + Function_Id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_Id INT NULL, -- UKA3 + Test_Instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Horizontal_Distance_from_RAC_X_mm NUMERIC NULL, + Lateral_Co_Ordinate_in_Horizontal_Plane_Y_mm NUMERIC NULL, + Vertical_Co_Ordinate_Z_mm NUMERIC NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + + DROP TABLE if exists IHT_Steering_Effort; + +CREATE TABLE IHT_Steering_Effort ( + SYSPK serial NOT NULL, -- PK + Client_Id INT NOT NULL, -- UKA1 + Function_Id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_Id INT NULL, -- UKA3 + Test_Instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Test_condition TEXT NULL, -- UKA4 + Test_Speed_kmph TEXT NULL, -- UKA5 + Max_Angle_LH NUMERIC NULL, + Max_Angle_RH NUMERIC NULL, + Max_Effort_LH NUMERIC NULL, + Max_Effort_RH NUMERIC NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + + DROP TABLE if exists IHT_Steering_Effort_Raw_Data; + +CREATE TABLE IHT_Steering_Effort_Raw_Data ( + SYSPK serial NOT NULL, -- PK + Client_Id INT NOT NULL, -- UKA1 + Function_Id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_Id INT NULL, -- UKA3 + Test_Instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + time_sec NUMERIC NULL, -- UKA4 + steering_anglel NUMERIC NULL, + effort_kg NUMERIC NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + +DROP TABLE if exists IHT_Pedal_Effort; + +CREATE TABLE IHT_Pedal_Effort ( + SYSPK serial NOT NULL, -- PK + Client_Id INT NOT NULL, -- UKA1 + Function_Id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_Id INT NULL, -- UKA3 + Test_Instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Parameters TEXT NULL, -- UKA4 + Efforts_Kg NUMERIC NULL, + Travel_mm NUMERIC NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + +DROP TABLE if exists IHT_Gear_Effort; + +CREATE TABLE IHT_Gear_Effort ( + SYSPK serial NOT NULL, -- PK + Client_Id INT NOT NULL, -- UKA1 + Function_Id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_Id INT NULL, -- UKA3 + Test_Instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Parameters TEXT NULL, -- UKA4 + Efforts_Kg NUMERIC NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + +DROP TABLE if exists IHT_Brake_Pedal_Effort; + +cREATE TABLE IHT_Brake_Pedal_Effort ( + SYSPK serial NOT NULL, -- PK + Client_Id INT NOT NULL, -- UKA1 + Function_Id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_Id INT NULL, -- UKA3 + Test_Instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Srl_No TEXT NULL, + Pedal_Effort_Kg NUMERIC NULL, -- UKA4 + Pedal_Travel_RH_mm NUMERIC NULL, + Pedal_Travel_LH_mm NUMERIC NULL, + Pedal_Travel_Latched_mm NUMERIC NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + +DROP TABLE if exists IHT_Clutch_Pedal_Effort; + +CREATE TABLE IHT_Clutch_Pedal_Effort ( + SYSPK serial NOT NULL, -- PK + Client_Id INT NOT NULL, -- UKA1 + Function_Id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_Id INT NULL, -- UKA3 + Test_Instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Pedal_Effort_Kg NUMERIC NULL, -- UKA4 + Srl_No TEXT NULL, + Pedal_Travel_mm NUMERIC NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + +DROP TABLE if exists IHT_Hyd_Lift_Sensitivity; + +CREATE TABLE IHT_Hyd_Lift_Sensitivity ( + SYSPK serial NOT NULL, -- PK + Client_Id INT NOT NULL, -- UKA1 + Function_Id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_Id INT NULL, -- UKA3 + Test_Instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + TPL_load TEXT NULL, -- UKA4 + Engine_RPM_type TEXT NULL, -- UKA5 + Engine_RPM INT NULL, -- UKA6 + lifting_time_sec NUMERIC NULL, + Lowering_time_sec NUMERIC NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + +DROP TABLE if exists IHT_Speed_lead_lag_measurement; + +CREATE TABLE IHT_Speed_lead_lag_measurement ( + SYSPK serial NOT NULL, -- PK + Client_Id INT NOT NULL, -- UKA1 + Function_Id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_Id INT NULL, -- UKA3 + Test_Instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Gear TEXT NULL, -- UKA4 + Engine_RPM INT NULL, + Wheel_Drive_type TEXT NULL, + No_of_Revolution_front NUMERIC NULL, + Ratio NUMERIC NULL, + Lead_Lag_PCT TEXT NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + +DROP TABLE if exists IHT_Gear_Max_Speed; + +CREATE TABLE IHT_Gear_Max_Speed ( + SYSPK serial NOT NULL, -- PK + Client_Id INT NOT NULL, -- UKA1 + Function_Id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_Id INT NULL, -- UKA3 + Test_Instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Test_condition TEXT NULL, -- UKA4 + Gear TEXT NULL, -- UKA5 + LOW_1000_RPM NUMERIC NULL, + RATED_2300_RPM NUMERIC NULL, + HIGH_2500_RPM NUMERIC NULL, + Specification NUMERIC NULL, + Actual_Speed_pct NUMERIC NULL, + Diff_in_Speed_KMPH NUMERIC NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + +DROP TABLE if exists IHT_Brake_Perf_test_condition; + +CREATE TABLE IHT_Brake_Perf_test_condition ( + SYSPK serial NOT NULL, -- PK + Client_Id INT NOT NULL, -- UKA1 + Function_Id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_Id INT NULL, -- UKA3 + Test_Instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + test_condition TEXT NULL, -- UKA4 + Date_of_Test date NULL, + Time_of_Test TEXT NULL, + Location_name TEXT NULL, + Test_Mode TEXT NULL, + Wind_velocity_kmph TEXT NULL, + Ambient_Temp_C NUMERIC NULL, + HumIdity_RH_PCT NUMERIC NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + +DROP TABLE if exists IHT_Brake_Perf_test_results; + +CREATE TABLE IHT_Brake_Perf_test_results ( + SYSPK serial NOT NULL, -- PK + Client_Id INT NOT NULL, -- UKA1 + Function_Id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_Id INT NULL, -- UKA3 + Test_Instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Test_condition TEXT NULL, -- UKA4 + test_mode TEXT NULL, -- UKA5 + Srl_No INT NULL, + Trigger_speed_km_per_h NUMERIC NULL, -- UKA6 + Brake_Control_Input_Force_kg NUMERIC NULL, -- UKA7 + Brake_perf_Test_condition_Id INT NULL, + Required_Corrected_Stopping_distance_m NUMERIC NULL, + Actual_Stopping_Distance_m NUMERIC NULL, + Deceleration_m_s2_V2_2s NUMERIC NULL, + Observation TEXT NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + +DROP TABLE if exists IHT_Hot_Air_Mapping_Results; + +CREATE TABLE IHT_Hot_Air_Mapping_Results ( + SYSPK serial NOT NULL, -- PK + Client_Id INT NOT NULL, -- UKA1 + Function_Id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_Id INT NULL, -- UKA3 + Test_Instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Gear TEXT NULL, -- UKA4 + Load_kg INT NULL, -- UKA5 + Speed_kmph NUMERIC NULL, + Speed_rpm INT NULL, -- UKA6 + Ambient_measured_temp_C INT NULL, + Head_measured_temp_C INT NULL, + Head_ROA_C INT NULL, + Chest_measured_temp_C INT NULL, + Chest_ROA_C INT NULL, + LH_Leg_measured_temp_C INT NULL, + LH_Leg_ROA_C INT NULL, + RH_Leg_measured_temp_C INT NULL, + RH_Leg_ROA_C INT NULL, + RH_Hand_measured_temp_C INT NULL, + RH_Hand_ROA_C INT NULL, + LH_Hand_measured_temp_C INT NULL, + LH_Hand_ROA_C INT NULL, + Hood_Gas_spring_RH_sIde_measured_temp_C INT NULL, + Hood_Gas_spring_RH_sIde_ROA_C INT NULL, + Hood_foam_top_measured_temp_C INT NULL, + Hood_foam_top_ROA_C INT NULL, + Hood_foam_mIddle_measured_temp_C INT NULL, + Hood_foam_mIddle_ROA_C INT NULL, + Hood_foam_bottom_measured_temp_C INT NULL, + Hood_foam_bottom_ROA_C INT NULL, + outsIde_Hood_top_measured_temp_C INT NULL, + outsIde_Hood_top_ROA_C INT NULL, + outsIde_Hood_MIddle_measured_temp_C INT NULL, + outsIde_Hood_MIddle_ROA_C INT NULL, + outsIde_Hood_Bottom_measured_temp_C INT NULL, + outsIde_Hood_Bottom_ROA_C INT NULL, + Time_of_Test TIME NULL, + Towards_main_security_gate_YN TEXT NULL, + Time_Diff_h_min TIME NULL, + Max_YN TEXT NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + +DROP TABLE if exists IHT_Noise_Measurement_Results; + +CREATE TABLE IHT_Noise_Measurement_Results ( + SYSPK serial NOT NULL, -- PK + Client_Id INT NOT NULL, -- UKA1 + Function_Id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_Id INT NULL, -- UKA3 + Test_Instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Test_Type TEXT NULL, -- UKA4 + Test_condition TEXT NULL, -- UKA5 + Test_mode TEXT NULL, -- UKA6 + Gear TEXT NULL, -- UKA7 + Speed_rpm INT NULL, + speed_kmph NUMERIC NULL, + Load_kg INT NULL, + noise_measurement_id int4 NULL, + Noise_Level_1_dB_A NUMERIC NULL, + Noise_Level_2_dB_A NUMERIC NULL, + Noise_Level_3_dB_A NUMERIC NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); + DROP TABLE if exists IHT_Noise_Measurement_test; + +CREATE TABLE IHT_Noise_Measurement_test ( + SYSPK serial NOT NULL, -- PK + Client_Id INT NOT NULL, -- UKA1 + Function_Id INT NOT NULL, -- UKA2 + file_syspk INT NULL, + file_mnemonic TEXT NULL, + file_sheet_mnemonic TEXT NULL, + Test_Instance_Id INT NULL, -- UKA3 + Test_Instance_Tractor_Id INT NULL, + Tractor_Model TEXT NULL, + Tractor_Make TEXT NULL, + Test_Type TEXT NULL, -- UKA4 + Test_condition TEXT NULL, -- UKA5 + Test_mode TEXT NULL, -- UKA6 + remarks TEXT NULL, + acceptance_criteria TEXT NULL, + Created_By TEXT NULL DEFAULT current_user, + Updated_by text NULL, + Create_timestamp TIMESTAMP NULL DEFAULT now(), + update_timestamp TIMESTAMP NULL +); \ No newline at end of file diff --git a/onetime/createtables/staging/create_table_FTDRY_SUM.sql b/onetime/createtables/staging/create_table_FTDRY_SUM.sql new file mode 100755 index 0000000..fef5e08 --- /dev/null +++ b/onetime/createtables/staging/create_table_FTDRY_SUM.sql @@ -0,0 +1,342 @@ +SET search_path TO staging2; + + +drop table if exists staging2.FTDRY_SUM_Trac_H1_Block; + +drop table if exists staging2.FTDRY_SUM_Implement_Block; + +drop table if exists staging2.FTDRY_SUM_Test_Condition_1_Block; + +drop table if exists staging2.FTDRY_SUM_Test_Condition_2_Block; + +drop table if exists staging2.FTDRY_SUM_Comments_By_Block; + +drop table if exists staging2.stg_process_table_ftdry_sum; + +drop table if exists staging2.stg_specific_table_ftdry_sum; + +create table staging2.FTDRY_SUM_Trac_H1_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +Tractor_Model text, +Tractor_Make text, +Tractor_Engine_HP text, +Rated_RPM text, +Transmission_Type text, +Wheel_Drive_Type text, +FIP_Type text, +Steering_Type text, +Tractor_Weight_kg_Front text, +Tractor_Weight_kg_Rear text, +Tractor_Weight_kg_Total text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + + +create table staging2.FTDRY_SUM_Implement_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +Make_of_Implement text, +Implement_Type text, +Implement_Size text, +Hitch_Category text, +Implement_Weight text, +Soil_Type text, +Moisture_Content text, +Bulk_Density_g_cc text, +Soil_Cone_index text, +Field_Condition text, +Season text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.FTDRY_SUM_Test_Condition_1_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +test_iterationnumber text, +Test_Condition text, +Test_Date text, +Tractor_Model text, +Engine_RPM_set text, +PTO_RPM_set text, +Gear_Used text, +Nominal_Speed_KMPH text, +Engine_RPM_Drop_on_straight text, +Engine_RPM_Drop_on_turn text, +Depth_of_cut_cm text, +No_load_speed_kmph text, +On_load_speed_kmph text, +wheel_slippage_ text, +Fuel_consumption_lit_hr text, +Area_covered_acr_hr text, +Fuel_consumption_lit_Acr text, +M_M_Performance_in_compared_to_respective_competitor_tractors text, +Fuel_consumption_lit_hr_2 text, +Area_covered_acr_hr_2 text, +Fuel_consumption_lit_Acr_2 text, +Trail_Observations text, +Engine_Smoke_on_Load text, +Engine_acceleration_smoke text, +Draft_Response text, +Tractor_Steer_ability text, +Tractor_braking_performance text, +Front_Visibility text, +Implement_Accessibility text, +Front_Wheel_dragging_at_turning text, +Front_end_lifting_during_operation text, +RPM_Recovery_Time text, +Engine_Vibration text, +Engine_Sound text, +Implement_Lifting_Lowering_response text, +Pulverization_Quality text, +Pulverization_Index text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.FTDRY_SUM_Test_Condition_2_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +test_iterationnumber text, +Test_Condition text, +Test_Date text, +Tractor_Model text, +Engine_RPM_set text, +PTO_RPM_set text, +Gear_Used text, +Nominal_Speed_KMPH text, +Engine_RPM_Drop_on_straight text, +Engine_RPM_Drop_on_turn text, +Depth_of_cut_cm text, +No_load_speed_kmph text, +On_load_speed_kmph text, +wheel_slippage_ text, +Fuel_consumption_lit_hr text, +Area_covered_acr_hr text, +Fuel_consumption_lit_Acr text, +M_M_Performance_in_compared_to_respective_competitor_tractors text, +Fuel_consumption_lit_hr_2 text, +Area_covered_acr_hr_2 text, +Fuel_consumption_lit_Acr_2 text, +Trail_Observations text, +Engine_Smoke_on_Load text, +Engine_acceleration_smoke text, +Draft_Response text, +Tractor_Steer_ability text, +Tractor_braking_performance text, +Front_Visibility text, +Implement_Accessibility text, +Front_Wheel_dragging_at_turning text, +Front_end_lifting_during_operation text, +RPM_Recovery_Time text, +Engine_Vibration text, +Engine_Sound text, +Implement_Lifting_Lowering_response text, +Pulverization_Quality text, +Pulverization_Index text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.FTDRY_SUM_Comments_By_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +Tractor_model text, +Test_Engineer_Comments_1 text, +Test_Manager_Comments_1 text, +Test_Engineer_Comments_2 text, +Test_Manager_Comments_2 text, +Test_Engineer_Comments_3 text, +Test_Manager_Comments_3 text, +Test_Engineer_Comments_4 text, +Test_Manager_Comments_4 text, + +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + + + +create TABLE staging2.stg_process_table_ftdry_sum ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 NULL, +create_time timestamp DEFAULT current_timestamp, +block_row_number int4 NULL, +block_tag text null +); + + +CREATE TABLE staging2.stg_specific_table_ftdry_sum ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 null, +create_time timestamp DEFAULT current_timestamp +); + + diff --git a/onetime/createtables/staging/create_table_FTDRY_TRS.sql b/onetime/createtables/staging/create_table_FTDRY_TRS.sql new file mode 100755 index 0000000..3e61010 --- /dev/null +++ b/onetime/createtables/staging/create_table_FTDRY_TRS.sql @@ -0,0 +1,306 @@ +SET search_path TO staging2; + +drop table if exists staging2.FTDRY_TRS_H1_INT; + +drop table if exists staging2.ftdry_trs_h1_block ; + +drop table if exists staging2.ftdry_trs_implement_block ; + +drop table if exists staging2.ftdry_trs_spec_block; + +drop table if exists staging2.ftdry_trs_engine_rpm_block; + +drop table if exists staging2.stg_process_table_ftdry_trs; + +drop table if exists staging2.stg_specific_table_ftdry_trs; + +/* FTDRY_TRS starts */ + +create table staging2.FTDRY_TRS_H1_INT +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.FTDRY_TRS_H1_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +Report_Reference_No text, +Objective_Of_Test text, +Background_of_Test text, +Job_Order_No text, +Test_Location text, +Soil_Moisture_Content_ text, +Soil_Bulk_Density_g_cc text, +Test_Engineer text, +Test_Operator text, +Date_of_Test text, +Report_Date text, +Season text, +Type_of_Soil text, +Soil_Cone_Index_kPa text, +Field_Condition text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + + +create table staging2.FTDRY_TRS_SPEC_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +Tractor_Model text, +Tractor_Make text, +Tractor_Sr_No text, +Tractor_Engine_HP text, +FIP_Type text, +hour_Meter_Reading text, +Steering_Type text, +Transmission_Type text, +Wheel_Drive_Type_WD text, +EGR_Yes_No text, +Brake_Type text, +PTO_Type text, +Standard_PTO_Speed_RPM text, +EPTO_Speed_RPM text, +Front_Tyre_Make text, +Front_Tyre_Size text, +Front_Tyre_Pressure_psi text, +Rear_Tyre_Make text, +Rear_Tyre_Size text, +Rear_Tyre_Pressure_psi text, +Tractor_Weight_kg_Front text, +Tractor_Weight_kg_Rear text, +Tractor_Weight_kg_Total text, +Ballasted_Tractor_Accessories text, +Mechanical_Ballast_Rear text, +Mechanical_Ballast_Rear_in_KG text, +Water_Ballast_Rear text, +Mechanical_Ballast_Front text, +Mechanical_Ballast_Front_in_Kg text, +Total_Ballast_Weight text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.FTDRY_TRS_Engine_RPM_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +Tractor_model text, +Tractor_make text, +tractor_sr_no text, +Low_Idle text, +High_Idle text, +Rated_RPM text, +Engine_to_PTO_Ratio_540_PTO text, +Engine_to_PTO_Ratio_540E_PTO text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.FTDRY_TRS_Implement_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +Name_of_Implement text, +Type_of_Implement text, +Make_of_Implement text, +No_of_bottoms_Tyne_Disc_Blade text, +Cutting_Width_m text, +Implement_Weight_Kg text, +Hitch_Category text, +Span_cm_For_Mounted_Implement text, +Mast_Height_cm_For_Mounted_Implement text, +report_template_no text , +report_template_rev_no text, +report_template_rev_date text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + +create TABLE staging2.stg_process_table_ftdry_trs ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 NULL, +create_time timestamp DEFAULT current_timestamp, +block_row_number int4 NULL, +block_tag text null +); + + +CREATE TABLE staging2.stg_specific_table_ftdry_trs ( +generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 null, +create_time timestamp DEFAULT current_timestamp +); + +/* FTDRY_TRS ends */ diff --git a/onetime/createtables/staging/create_table_FTHLG_SUM.sql b/onetime/createtables/staging/create_table_FTHLG_SUM.sql new file mode 100755 index 0000000..7d9d88a --- /dev/null +++ b/onetime/createtables/staging/create_table_FTHLG_SUM.sql @@ -0,0 +1,339 @@ +SET search_path TO staging2; + +drop table if exists staging2.FTHLG_SUM_Trac_H1_Block; + +drop table if exists staging2.FTHLG_SUM_Trail_Type_Block; + +drop table if exists staging2.FTHLG_SUM_Test_Condition_1_Block; + +drop table if exists staging2.FTHLG_SUM_Test_Condition_2_Block; + +drop table if exists staging2.FTHLG_SUM_Comments_By_Block; + + +drop table if exists staging2.stg_process_table_fthlg_sum; + + +drop table if exists staging2.stg_specific_table_fthlg_sum; + + +create table staging2.FTHLG_SUM_Trac_H1_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +tractor_model text, +tractor_make text, +tractor_engine_hp text, +rated_rpm text, +transmission_type text, +wheel_drive_type text, +fip_type text, +steering_type text, +tractor_weight_kg_front text, +tractor_weight_kg_rear text, +tractor_weight_kg_total text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + + +create table staging2.FTHLG_SUM_Trail_Type_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +Trailer_Type text, +Tire_size_and_inflation_pressure_psi text, +No_Of_Axle text, +No_Of_Wheels text, +Trailer_Gross_Weight_Kg text, +Tractor_Rear_Wheel_Center_to_Hitch_Point_Center_Distance_mm text, +Tractor_Hitch_Height_from_Ground_mm text, +Trailer_hitch_Height_above_ground_level_mm text, +Gradient_Slope_1_Degree text, +Gradient_Slope_2_degree text, +Tractor_Hitch_Type text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.FTHLG_SUM_Test_Condition_1_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +test_iterationnumber text, +Test_Condition text, +Test_Date text, +Tractor_Model text, +Fuel_consumption_Ltr_hr text, +Mileage_Km_Ltr text, +Average_speed_of_travel_kmph text, +Total_distance_travelled_km text, +Gear_used_on_Straight_Road text, +Straight_road_RPM_Drop text, +Gear_used_on_Up_Slope_1 text, +Up_Slope_RPM_Drop_1 text, +Gear_used_on_Up_Slope_2 text, +Up_Slope_RPM_Drop_2 text, +Gear_used_on_Down_Slope text, +Down_Slope_RPM_Shoot_up text, +Performance_compared_to_respective_competitor_tractors text, +Fuel_consumption_lit_hr_2 text, +Mileage_Km_Ltr_2 text, +M_M_Performance_in_compared_to_respective_competitor_tractors text, +Fuel_consumption_lit_hr_3 text, +Mileage_Km_Ltr_3 text, +Engine_Smoke_on_Load text, +Engine_acceleration_smoke text, +Range_Gear_Shifting text, +Speed_Gear_Shifting text, +Tractor_Steer_ability text, +Tractor_braking_performance text, +Front_Visibility text, +Implement_Accessibility text, +Front_end_lifting_during_operation text, +RPM_Recovery_Time text, +Engine_Vibration text, +Engine_Sound text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.FTHLG_SUM_Test_Condition_2_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +test_iterationnumber text, +Test_Condition text, +Test_Date text, +Tractor_Model text, +Fuel_consumption_Ltr_hr text, +Mileage_Km_Ltr text, +Average_speed_of_travel_kmph text, +Total_distance_travelled_km text, +Gear_used_on_Straight_Road text, +Straight_road_RPM_Drop text, +Gear_used_on_Up_Slope_1 text, +Up_Slope_RPM_Drop_1 text, +Gear_used_on_Up_Slope_2 text, +Up_Slope_RPM_Drop_2 text, +Gear_used_on_Down_Slope text, +Down_Slope_RPM_Shoot_up text, +Performance_compared_to_respective_competitor_tractors text, +Fuel_consumption_lit_hr_2 text, +Mileage_Km_Ltr_2 text, +M_M_Performance_in_compared_to_respective_competitor_tractors text, +Fuel_consumption_lit_hr_3 text, +Mileage_Km_Ltr_3 text, +Engine_Smoke_on_Load text, +Engine_acceleration_smoke text, +Range_Gear_Shifting text, +Speed_Gear_Shifting text, +Tractor_Steer_ability text, +Tractor_braking_performance text, +Front_Visibility text, +Implement_Accessibility text, +Front_end_lifting_during_operation text, +RPM_Recovery_Time text, +Engine_Vibration text, +Engine_Sound text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.FTHLG_SUM_Comments_By_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +Tractor_Model text, +Test_Engineer_Comments_1 text, +Test_Manager_Comments_1 text, +Test_Engineer_Comments_2 text, +Test_Manager_Comments_2 text, +Test_Engineer_Comments_3 text, +Test_Manager_Comments_3 text, +Test_Engineer_Comments_4 text, +Test_Manager_Comments_4 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + + + +create TABLE staging2.stg_process_table_fthlg_sum ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 NULL, +create_time timestamp DEFAULT current_timestamp, +block_row_number int4 NULL, +block_tag text null +); + + +CREATE TABLE staging2.stg_specific_table_fthlg_sum ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 null, +create_time timestamp DEFAULT current_timestamp +); + + + + diff --git a/onetime/createtables/staging/create_table_FTHLG_TRS.sql b/onetime/createtables/staging/create_table_FTHLG_TRS.sql new file mode 100755 index 0000000..3266756 --- /dev/null +++ b/onetime/createtables/staging/create_table_FTHLG_TRS.sql @@ -0,0 +1,315 @@ + +SET search_path TO staging2; + +drop table if exists staging2.FTHLG_TRS_H1_INT; + +drop table if exists staging2.FTHLG_TRS_H1_Block; + +drop table if exists staging2.FTHLG_TRS_SPEC_Block; + +drop table if exists staging2.FTHLG_TRS_Engine_RPM_Block; + +drop table if exists staging2.FTHLG_TRS_Trailer_Block; + +drop table if exists staging2.stg_specific_table_fthlg_trs; + +drop table if exists staging2.stg_process_table_fthlg_trs; + + +create table staging2.FTHLG_TRS_H1_INT +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.FTHLG_TRS_H1_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +Report_Reference_No text, +Objective_Of_Test text, +Background_of_Test text, +Job_Order_No text, +Test_Location text, +Gradient_Slope_1_Degree text, +Gradient_Slope_2_Degree text, +Tractor_Hitch_Type text, +Test_Engineer text, +Test_Operator text, +Date_of_Test text, +Report_Date text, +Type_of_Road text, +Tractor_Hitch_Height_from_Ground_mm text, +Tractor_Rear_Wheel_Center_to_Hitch_Point_Center_Distance_mm text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + + +create table staging2.FTHLG_TRS_SPEC_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +Tractor_Model text, +Tractor_Make text, +Tractor_Sr_No text, +Tractor_Engine_HP text, +FIP_Type text, +Hour_Meter_Reading text, +Steering_Type text, +Transmission_Type text, +Wheel_Drive_Type_WD text, +EGR_Yes_No text, +Brake_Type text, +PTO_Type text, +Standard_PTO_Speed_RPM text, +EPTO_Speed_RPM text, +Front_Tyre_Make text, +Front_Tyre_Size text, +Front_Tyre_Pressure_psi text, +Rear_Tyre_Make text, +Rear_Tyre_Size text, +Rear_Tyre_Pressure_psi text, +Tractor_Weight_kg_Front text, +Tractor_Weight_kg_Rear text, +Tractor_Weight_kg_Total text, +Ballasted_Tractor_Accessories text, +Mechanical_Ballast_Rear text, +Mechanical_Ballast_Rear_in_kg text, +Water_Ballast_Rear_75 text, +Mechanical_Ballast_Front_in_kg text, +Mechanical_Ballast_Front text, +Total_Ballast_Weight text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.FTHLG_TRS_Engine_RPM_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +Tractor_model text, +Tractor_make text, +tractor_sr_no text, +Low_Idle text, +High_Idle text, +Rated_RPM text, +Engine_to_PTO_Ratio_540_PTO text, +Engine_to_PTO_Ratio_540E_PTO text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.FTHLG_TRS_Trailer_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +Type_Of_Trailer text, +No_Of_Axle text, +No_Of_Wheels text, +Trailer_hitch_Height_above_ground_level_mm text, +Make_model_of_trailer text, +Trailer_platform_length_mm text, +Trailer_platform_Width_mm text, +Trailer_platform_Height_mm text, +Tire_size text, +Inflation_pressure_psi text, +Track_width_of_trailer_mm text, +Horizontal_distance_of_hitch_point_from_trailer_front_face_mm text, +Tractor_Rear_Wheel_Center_to_Hitch_Point_Center_Distance_mm text, +Distance_from_Trailer_front_axle_distance_from_hitch_point_mm text, +Distance_from_tractor_rear_wheel_to_tractor_rear_wheel_mm text, +Trailer_empty_weight_Kg text, +Trailer_Gross_Weight_Kg text, +report_template_no text , + report_template_rev_no text, +report_template_rev_date text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + + + +create TABLE staging2.stg_process_table_fthlg_trs ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 NULL, +create_time timestamp DEFAULT current_timestamp, +block_row_number int4 NULL, +block_tag text null +); + + +CREATE TABLE staging2.stg_specific_table_fthlg_trs ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 null, +create_time timestamp DEFAULT current_timestamp +); diff --git a/onetime/createtables/staging/create_table_FTWET_SUM.sql b/onetime/createtables/staging/create_table_FTWET_SUM.sql new file mode 100755 index 0000000..848850b --- /dev/null +++ b/onetime/createtables/staging/create_table_FTWET_SUM.sql @@ -0,0 +1,306 @@ +SET search_path TO staging2; + + +drop table if exists staging2.FTWET_SUM_Trac_H1_Block; + +drop table if exists staging2.FTWET_SUM_Implement_Block; + +drop table if exists staging2.FTWET_SUM_Cage_Wheel_Block; +; +drop table if exists staging2.FTWET_SUM_Test_Condition_Block; + +drop table if exists staging2.FTWET_SUM_Comments_By_Block; + +drop table if exists staging2.stg_process_table_ftwet_sum; + +drop table if exists staging2.stg_specific_table_ftwet_sum; + + +create table staging2.FTWET_SUM_Trac_H1_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +Tractor_Model text, +Tractor_Make text, +Tractor_Engine_HP text, +Rated_RPM text, +Transmission_Type text, +Wheel_Drive_Type text, +FIP_Type text, +Steering_Type text, +Tractor_Weight_kg_Front text, +Tractor_Weight_kg_Rear text, +Tractor_Weight_kg_Total text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.FTWET_SUM_Implement_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +Make_of_Implement text, +Implement_Type text, +Implement_Size text, +Hitch_Category text, +Implement_Weight text, +Soil_Type text, +Moisture_Content text, +Bulk_Density_g_cc text, +Soil_Cone_index text, +Field_Condition text, +Season text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.FTWET_SUM_Cage_Wheel_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +Type_of_Cage_Wheel text, +Cage_Wheel_Width_mm text, +Cage_wheel_Weight text, +Cage_Wheel_inner_Outer_Ring_Dia_mm text, +Cage_Wheel_Center_Ring_Dia_mm text, +Distance_between_RHS_LHS_cage_wheel_Inner_Ring_mm text, +No_of_angles_on_cage_wheel text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.FTWET_SUM_Test_Condition_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +test_iterationnumber text, +Test_Condition text, +Test_Date text, +Tractor_Model text, +Engine_RPM_set text, +PTO_RPM_set text, +Gear_Used text, +Nominal_Speed_KMPH text, +Engine_RPM_Drop_on_straight_1st_Pass text, +Engine_RPM_Drop_on_straight_2nd_Pass text, +Engine_RPM_Drop_on_straight_3rd_Pass text, +Engine_RPM_Drop_on_turn_1st_Pass text, +Engine_RPM_Drop_on_turn_2nd_Pass text, +Engine_RPM_Drop_on_turn_3rd_Pass text, +No_of_passes text, +Avg_Depth_of_cut_cm text, +Fuel_consumption_lit_hr text, +Area_covered_acr_hr text, +Fuel_consumption_lit_Acr text, +M_M_Performance_in_compared_to_respective_competitor_tractors text, +Fuel_consumption_lit_hr_2 text, +Area_covered_acr_hr_2 text, +Fuel_consumption_lit_Acr_2 text, +Trail_Observations text, +Engine_Smoke_on_Load text, +Engine_acceleration_smoke text, +Draft_Response text, +Tractor_Steer_ability text, +Tractor_braking_performance text, +Front_Visibility text, +Implement_Accessibility text, +Front_Wheel_dragging_at_turning text, +Front_end_lifting_during_operation text, +RPM_Recovery_Time text, +Engine_Vibration text, +Engine_Sound text, +Implement_Lifting_Lowering_response text, +Pulverization_Quality text, +Pulverization_Index text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.FTWET_SUM_Comments_By_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +Tractor_Model text, +test_engineer_comments_1 text, +test_manager_comments_1 text, +test_engineer_comments_2 text, +test_manager_comments_2 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + +create TABLE staging2.stg_process_table_ftwet_sum ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 NULL, +create_time timestamp DEFAULT current_timestamp, +block_row_number int4 NULL, +block_tag text null +); + + +CREATE TABLE staging2.stg_specific_table_ftwet_sum ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 null, +create_time timestamp DEFAULT current_timestamp +); + diff --git a/onetime/createtables/staging/create_table_FTWET_TRS.sql b/onetime/createtables/staging/create_table_FTWET_TRS.sql new file mode 100755 index 0000000..d20663f --- /dev/null +++ b/onetime/createtables/staging/create_table_FTWET_TRS.sql @@ -0,0 +1,316 @@ + +SET search_path TO staging2; + + +drop table if exists staging2.FTWET_TRS_H1_INT; + +drop table if exists staging2.FTWET_TRS_H1_Block; + +drop table if exists staging2.FTWET_TRS_SPEC_Block; + +drop table if exists staging2.FTWET_TRS_Engine_RPM_Block; + +drop table if exists staging2.FTWET_TRS_Implement_Block; + +drop table if exists staging2.stg_process_table_ftwet_trs; + +drop table if exists staging2.stg_specific_table_ftwet_trs; + + +/* FTWET_TRS starts */ +create table staging2.FTWET_TRS_H1_INT +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.FTWET_TRS_H1_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +Report_Reference_No text, +Objective_Of_Test text, +Background_of_Test text, +Job_Order_No text, +Test_Location text, +Soil_Moisture_Content_ text, +Soil_Bulk_Density_g_cc text, +Test_Engineer text, +Test_Operator text, +Date_of_Test text, +Report_Date text, +Season text, +Type_of_Soil text, +Soil_Cone_Index_kPa text, +Field_Condition text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.FTWET_TRS_SPEC_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +Tractor_Model text, +Tractor_Make text, +Tractor_Sr_No text, +Tractor_Engine_HP text, +FIP_Type text, +hour_Meter_Reading text, +Steering_Type text, +Transmission_Type text, +Wheel_Drive_Type_WD text, +EGR_Yes_No text, +Brake_Type text, +PTO_Type text, +Standard_PTO_Speed_RPM text, +EPTO_Speed_RPM text, +Front_Tyre_Make text, +Front_Tyre_Size text, +Front_Tyre_Pressure_psi text, +Rear_Tyre_Make text, +Rear_Tyre_Size text, +Rear_Tyre_Pressure_psi text, +Tractor_Weight_kg_Front text, +Tractor_Weight_kg_Rear text, +Tractor_Weight_kg_Total text, +Ballasted_Tractor_Accessories text, +Mechanical_Ballast_Rear_in_KG text, +Water_Ballast_Rear text, +Mechanical_Ballast_Front text, +Mechanical_Ballast_Front_in_Kg text, +Total_Ballast_Weight text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.FTWET_TRS_Engine_RPM_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +Tractor_model text, +Tractor_make text, +tractor_sr_no text, +Low_Idle text, +High_Idle text, +Rated_RPM text, +Engine_to_PTO_Ratio_540_PTO text, +Engine_to_PTO_Ratio_540E_PTO text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.FTWET_TRS_Implement_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +Name_of_Implement text, +Type_of_Implement text, +Make_of_Implement text, +No_of_bottoms_Tyne_Disc_Blade text, +Cutting_Width_m text, +Implement_Weight_Kg text, +Hitch_Category text, +Span_cm_For_Mounted_Implement text, +Mast_Height_cm_For_Mounted_Implement text, +Type_of_Cage_Wheel_Half_Cage_wheel_Full_Cage_Wheel text, +Cage_Wheel_Width_mm text, +Cage_wheel_Weight text, +Cage_Wheel_inner_Outer_Ring_Dia_mm text, +Cage_Wheel_Center_Ring_Dia_mm text, +Distance_between_cage_wheel_Ring_mm_For_Full_wheel text, +No_of_angles_on_cage_wheel text, +No_of_days_of_water_logging text, +Depth_of_water_mm text, +report_template_no text , +report_template_rev_no text, +report_template_rev_date text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + + + +create TABLE staging2.stg_process_table_ftwet_trs ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 NULL, +create_time timestamp DEFAULT current_timestamp, +block_row_number int4 NULL, +block_tag text null +); + + +CREATE TABLE staging2.stg_specific_table_ftwet_trs ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 null, +create_time timestamp DEFAULT current_timestamp +); + diff --git a/onetime/createtables/staging/create_tables_BUDNI_ARC.sql b/onetime/createtables/staging/create_tables_BUDNI_ARC.sql new file mode 100755 index 0000000..8c5fc49 --- /dev/null +++ b/onetime/createtables/staging/create_tables_BUDNI_ARC.sql @@ -0,0 +1,223 @@ +drop table if exists staging2.BUDNI_ARC_Spec_H1_Block; +drop table if exists staging2.BUDNI_ARC_Perf_Atmos_Meas_Test_Block; +drop table if exists staging2.BUDNI_ARC_Test_Obs_Summary_Block; +drop table if exists staging2.stg_process_table_BUDNI_ARC; +drop table if exists staging2.stg_specific_table_BUDNI_ARC; + +create table staging2.BUDNI_ARC_Spec_H1_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +tractor_HP text, +rated_rpm text, +configuration text, +transmission_type text, +wheel_drive_type text, +FIP_type text, +steering_type text, +Engine_to_PTO_ratio text, +Ballast_Condition text, +Test_Engine_Set_RPM text, +Type_of_track text , +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.BUDNI_ARC_Perf_Atmos_Meas_Test_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +Temperature_C text, +Pressure_kPa text, +Relative_humidity text, +Mass_of_oil_before_test text, +Position_of_tractor text, +Loss_of_oil text, +Oil_pull_Over text, +Engine_oil_pressure text, +trx_record int default 1, +block_row_number int,create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.BUDNI_ARC_Test_Obs_Summary_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create TABLE staging2.stg_process_table_BUDNI_ARC ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 NULL, +create_time timestamp DEFAULT current_timestamp, +block_row_number int4 NULL, +block_tag text null +); + + +CREATE TABLE staging2.stg_specific_table_BUDNI_ARC ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 null, +create_time timestamp DEFAULT current_timestamp +); + + diff --git a/onetime/createtables/staging/create_tables_BUDNI_BRK.sql b/onetime/createtables/staging/create_tables_BUDNI_BRK.sql new file mode 100755 index 0000000..f2b454a --- /dev/null +++ b/onetime/createtables/staging/create_tables_BUDNI_BRK.sql @@ -0,0 +1,440 @@ +drop table if exists staging2.BUDNI_BRK_Spec_H1_Block; +drop table if exists staging2.BUDNI_BRK_Service_Barke_Test_Int; +drop table if exists staging2.BUDNI_BRK_service_cold_standard_maximum_Block; +drop table if exists staging2.BUDNI_BRK_service_cold_ballasted_maximum_Block; +drop table if exists staging2.BUDNI_BRK_service_cold_standard_25kmph_Block; +drop table if exists staging2.BUDNI_BRK_service_cold_ballasted_25kmph_Block; +drop table if exists staging2.BUDNI_BRK_service_fade_standard_maximum_Block; +drop table if exists staging2.BUDNI_BRK_service_fade_ballasted_25kmph_Block; +drop table if exists staging2.BUDNI_BRK_other_observations_Block; +drop table if exists staging2.BUDNI_BRK_Parking_Barke_Test_Int ; +drop table if exists staging2.BUDNI_BRK_Parking_Barke_Test_Block; +drop table if exists staging2.BUDNI_BRK_Test_Obs_Summary_Block; +drop table if exists staging2.stg_process_table_BUDNI_BRK; +drop table if exists staging2.stg_specific_table_BUDNI_BRK; + + +create table staging2.BUDNI_BRK_Spec_H1_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +tractor_HP text, +rated_rpm text, +Type_of_brake text, +Type_of_track text , +brake_free_play_lh text, +brake_free_play_rh text, +maximum_attainable_speed_kmph_unballasted text, +maximum_attainable_speed_kmph_ballasted text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_BRK_Service_Barke_Test_Int +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column1 text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_BRK_service_cold_standard_maximum_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +brake_test_type text, +brake_test_name text, +speed_condition text, +ballast_condition text, +Braking_device_control_force_N text, +Mean_deceleration_m_sec2 text, +Stopping_distance_m text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_BRK_service_cold_ballasted_maximum_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +brake_test_type text, +brake_test_name text, +speed_condition text, +ballast_condition text, +Braking_device_control_force_N text, +Mean_deceleration_m_sec2 text, +Stopping_distance_m text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_BRK_service_cold_standard_25kmph_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +brake_test_type text, +brake_test_name text, +speed_condition text, +ballast_condition text, +Braking_device_control_force_N text, +Mean_deceleration_m_sec2 text, +Stopping_distance_m text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_BRK_service_cold_ballasted_25kmph_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +brake_test_type text, +brake_test_name text, +speed_condition text, +ballast_condition text, +Braking_device_control_force_N text, +Mean_deceleration_m_sec2 text, +Stopping_distance_m text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_BRK_service_fade_standard_maximum_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +brake_test_type text, +brake_test_name text, +speed_condition text, +ballast_condition text, +Braking_device_control_force_N text, +Mean_deceleration_m_sec2 text, +Stopping_distance_m text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_BRK_service_fade_ballasted_25kmph_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +brake_test_type text, +brake_test_name text, +speed_condition text, +ballast_condition text, +Braking_device_control_force_N text, +Mean_deceleration_m_sec2 text, +Stopping_distance_m text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_BRK_other_observations_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column1 text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.budni_brk_parking_barke_test_int +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column1 text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_BRK_Parking_Barke_Test_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +particulars text, +facing text, +Braking_device_control_force text, +Efficacy_of_parking_brake text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + + +create table staging2.BUDNI_BRK_Test_Obs_Summary_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create TABLE staging2.stg_process_table_BUDNI_BRK ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 NULL, +create_time timestamp DEFAULT current_timestamp, +block_row_number int4 NULL, +block_tag text null +); + + +CREATE TABLE staging2.stg_specific_table_BUDNI_BRK ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 null, +create_time timestamp DEFAULT current_timestamp +); + + diff --git a/onetime/createtables/staging/create_tables_BUDNI_DBP.sql b/onetime/createtables/staging/create_tables_BUDNI_DBP.sql new file mode 100755 index 0000000..8387fb5 --- /dev/null +++ b/onetime/createtables/staging/create_tables_BUDNI_DBP.sql @@ -0,0 +1,214 @@ +drop table if exists staging2.BUDNI_DBP_Spec_H1_Block; + +drop table if exists staging2.BUDNI_DBP_Drawbar_Perf_Block; + +drop table if exists staging2.stg_process_table_budni_dbp; + +drop table if exists staging2.stg_specific_table_budni_dbp; + +create table staging2.BUDNI_DBP_Spec_H1_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +column13 text, +column14 text, +column15 text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_DBP_Drawbar_Perf_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +column13 text, +column14 text, +column15 text, +column16 text, +column17 text, +column18 text, +column19 text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + + +create TABLE staging2.stg_process_table_budni_dbp ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 NULL, +create_time timestamp DEFAULT current_timestamp, +block_row_number int4 NULL, +block_tag text null +); + + +CREATE TABLE staging2.stg_specific_table_budni_dbp ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 null, +create_time timestamp DEFAULT current_timestamp +); + + + diff --git a/onetime/createtables/staging/create_tables_BUDNI_FLD.sql b/onetime/createtables/staging/create_tables_BUDNI_FLD.sql new file mode 100755 index 0000000..12d645a --- /dev/null +++ b/onetime/createtables/staging/create_tables_BUDNI_FLD.sql @@ -0,0 +1,333 @@ +drop table if exists staging2.BUDNI_FLD_Spec_H1_Block; +drop table if exists staging2.BUDNI_FLD_Impl_Test_Int; +drop table if exists staging2.BUDNI_FLD_Impl_Test_Block; +drop table if exists staging2.BUDNI_FLD_Cage_Wheel_Block; +drop table if exists staging2.BUDNI_FLD_Sum_Perf_Test_Int; +drop table if exists staging2.BUDNI_FLD_Sum_Perf_Test_Block; +drop table if exists staging2.BUDNI_FLD_Test_Obs_Summary_Block; +drop table if exists staging2.stg_process_table_BUDNI_FLD; +drop table if exists staging2.stg_specific_table_BUDNI_FLD; + + +create table staging2.BUDNI_FLD_Spec_H1_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +tractor_HP text, +rated_rpm text, +configuration text, +transmission_type text, +wheel_drive_type text, +FIP_type text, +steering_type text, +Engine_to_PTO_ratio text, +Ballast_Condition text, +Test_Engine_Set_RPM text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.BUDNI_FLD_Impl_Test_INT +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_FLD_Impl_Test_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +items text, +Make text, +type text, +No_of_Disc_blades text, +Type_of_Disc_blades text, +Size_of_bottoms_blades_1_mm text, +Size_of_bottoms_blades_2_mm text, +Size_of_bottoms_blades_3_mm text, +Spacing_of_bottoms_flanges_mm text, +Lower_hitch_point_span_mm text, +Mast_height_mm text, +Overall_dimensions_mm text, +Overall_dimensions_mm_length text, +Overall_dimensions_mm_Width text, +Overall_dimensions_mm_Height text, +Gross_mass_kg text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.BUDNI_FLD_Cage_Wheel_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +Items text, +type text, +Dia_mm text, +Width_mm text, +No_and_types_of_lugs text, +Size_of_angle_section_1_mm text, +Size_of_angle_section_2_mm text, +Size_of_angle_section_3_mm text, +Length_of_lugs_mm text, +Spacing_of_lugs_mm text, +Weight_of_each_cage_wheels_kg text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_FLD_Sum_Perf_Test_Int +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_FLD_Sum_Perf_Test_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +Parameter_operation text, +Type_of_soil text, +Av_soil_moisture_Av_depth_of_standing_water_cm text, +Bulk_density_of_soil_g_cc text, +Cone_index_kgf_sq_cm_Puddling_index text, +Gear_used text, +Av_speed_of_operation_kmph text, +Av_wheel_slip_Av_Travel_reduction text, +Av_depth_of_cut_cm_Av_Depth_of_puddle_cm text, +Av_working_width_cm text, +Area_covered_ha_h text, +Fuel_consumption text, +Fuel_consumption_l_h text, +Fuel_consumption_l_ha text, +Av_draft_of_implement_kN text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_FLD_Test_Obs_Summary_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + + +create TABLE staging2.stg_process_table_BUDNI_FLD ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 NULL, +create_time timestamp DEFAULT current_timestamp, +block_row_number int4 NULL, +block_tag text null +); + + +CREATE TABLE staging2.stg_specific_table_BUDNI_FLD ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 null, +create_time timestamp DEFAULT current_timestamp +); + + diff --git a/onetime/createtables/staging/create_tables_BUDNI_HDL.sql b/onetime/createtables/staging/create_tables_BUDNI_HDL.sql new file mode 100755 index 0000000..4201d53 --- /dev/null +++ b/onetime/createtables/staging/create_tables_BUDNI_HDL.sql @@ -0,0 +1,302 @@ +drop table if exists staging2.stg_specific_table_budni_hdl; +drop table if exists staging2.stg_process_table_budni_hdl; +drop table if exists staging2.budni_hdl_Spec_H1_Block; +drop table if exists staging2.budni_hdl_power_test_Block; +drop table if exists staging2.budni_hdl_Lifting_Capacity_Test_Block; +drop table if exists staging2.budni_hdl_Maintenance_of_lift_load_int; +drop table if exists staging2.budni_hdl_Maintenance_of_lift_load_Block; +drop table if exists staging2.budni_hdl_Test_Obs_Summary_Block; + + +create table staging2.budni_hdl_Spec_H1_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +tractor_HP text, +rated_rpm text, +hydraulic_type text, +Pump_speed_at_rated_engine_speed_rpm text, +Steering_Type text, +Oil text, +Lift_Rod_type_LH text, +Lift_Rod_type_RH text, +Lift_Rod_Length_LH text, +Lift_Rod_Length_RH text, +Lower_link_Length_LH text, +Lower_link_Length_RH text, +Pump_HP text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.budni_hdl_power_test_block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +Pump_delivery_rate_at_min_pressure_and_rated_engine text, +Maximum_hydraulic_power_kW text, + Pump_delivery_rate_at_maximum_hydraulic_power_l_min text, + Pressure_at_maximum_hydraulic_power_MPa text, + Sustained_pressure_of_the_open_relief_valve_MPa text, +tapping_point_relief_valve_test text, +tapping_point_Pump_performance_test text, +tapping_point_Temperature_of_hydraulic_fluid_C text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.budni_hdl_Lifting_Capacity_Test_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.budni_hdl_Maintenance_of_lift_load_int +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.budni_hdl_Maintenance_of_lift_load_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +Force_applied_at_the_frame_kN text, +Temperature_of_hydraulic_fluid_at_the_start_of_test_C text, +Elapsed_time_minute text, +Cumulative_drop_in_height_of_lift_mm text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.budni_hdl_Test_Obs_Summary_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create TABLE staging2.stg_process_table_budni_hdl ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 NULL, +create_time timestamp DEFAULT current_timestamp, +block_row_number int4 NULL, +block_tag text null +); + + +CREATE TABLE staging2.stg_specific_table_budni_hdl ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 null, +create_time timestamp DEFAULT current_timestamp +); + + diff --git a/onetime/createtables/staging/create_tables_BUDNI_HLG.sql b/onetime/createtables/staging/create_tables_BUDNI_HLG.sql new file mode 100755 index 0000000..3bff81a --- /dev/null +++ b/onetime/createtables/staging/create_tables_BUDNI_HLG.sql @@ -0,0 +1,249 @@ +drop table if exists staging2.BUDNI_HLG_Spec_H1_Block; +drop table if exists staging2.BUDNI_HLG_Perf_Test_int; +drop table if exists staging2.BUDNI_HLG_Perf_Test_block; +drop table if exists staging2.BUDNI_HLG_Test_Obs_Summary_Block; +drop table if exists staging2.stg_process_table_BUDNI_HLG; +drop table if exists staging2.stg_specific_table_BUDNI_HLG; + + +create table staging2.BUDNI_HLG_Spec_H1_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +tractor_HP text, +rated_rpm text, +configuration text, +transmission_type text, +wheel_drive_type text, +FIP_type text, +steering_type text, +Engine_to_PTO_ratio text, +Ballast_Condition text, +Test_Engine_Set_RPM text, +Type_of_track text , +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.BUDNI_HLG_Perf_Test_int +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column3 text, +column6 text, +column8 text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_HLG_Perf_Test_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +type_of_trailer text, +Gross_mass_of_trailer_tonne text, +Height_of_trailer_hitch_above_ground_level_mm text, +Gear_used_during_the_test_for_negotiating_slopes_up_to_8 text, +Average_travel_speed_kmph text, +Average_fuel_consumption text, +l_h text, +ml_km_tonne text, +Average_distance_traveled_per_litre_of_fuel_consumption_km text, +General_observations text, +Effectiveness_of_brakes text, +Maneuverability_of_tractor_trailer_combination text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.BUDNI_HLG_Test_Obs_Summary_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create TABLE staging2.stg_process_table_BUDNI_HLG ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 NULL, +create_time timestamp DEFAULT current_timestamp, +block_row_number int4 NULL, +block_tag text null +); + + +CREATE TABLE staging2.stg_specific_table_BUDNI_HLG ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 null, +create_time timestamp DEFAULT current_timestamp +); + + diff --git a/onetime/createtables/staging/create_tables_BUDNI_LCG.sql b/onetime/createtables/staging/create_tables_BUDNI_LCG.sql new file mode 100755 index 0000000..d6a9c26 --- /dev/null +++ b/onetime/createtables/staging/create_tables_BUDNI_LCG.sql @@ -0,0 +1,203 @@ +drop table if exists staging2.BUDNI_LCG_Spec_H1_Block; + +drop table if exists staging2.BUDNI_LCG_Gravity_Test_Block; + +drop table if exists staging2.stg_specific_table_BUDNI_LCG; + +drop table if exists staging2.stg_process_table_BUDNI_LCG; + +create table staging2.BUDNI_LCG_Spec_H1_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +Tractor_HP text, +Rated_RPM text, +configuration text, +Transmission_type text, +Wheel_Drive_type text, +Wheel_Base text, +Wheel_track text, +Overall_height text, +Ballast_Condition text, +Tractor_Weight_reactions_Front text, +Tractor_Weight_reactions_Rear text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_LCG_Gravity_Test_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + + +create TABLE staging2.stg_process_table_BUDNI_LCG ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 NULL, +create_time timestamp DEFAULT current_timestamp, +block_row_number int4 NULL, +block_tag text null +); + + +CREATE TABLE staging2.stg_specific_table_BUDNI_LCG ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 null, +create_time timestamp DEFAULT current_timestamp +); + + + + diff --git a/onetime/createtables/staging/create_tables_BUDNI_NMT.sql b/onetime/createtables/staging/create_tables_BUDNI_NMT.sql new file mode 100755 index 0000000..c289b3a --- /dev/null +++ b/onetime/createtables/staging/create_tables_BUDNI_NMT.sql @@ -0,0 +1,348 @@ +drop table if exists staging2.BUDNI_NMT_Spec_H1_Block; +drop table if exists staging2.budni_nmt_noise_at_bystander_position_block; +drop table if exists staging2.BUDNI_NMT_Atmos_Cond_1_Block; +drop table if exists staging2.BUDNI_NMT_Meas_Results_1_Block; +drop table if exists staging2.budni_nmt_noise_at_operator_ear_level_block; +drop table if exists staging2.BUDNI_NMT_Atmos_Cond_2_Block; +drop table if exists staging2.BUDNI_NMT_Meas_Results_2_Block; +drop table if exists staging2.BUDNI_NMT_Test_Obs_Summary_Block; +drop table if exists staging2.stg_process_table_budni_nmt; +drop table if exists staging2.stg_specific_table_budni_nmt; + + +create table staging2.BUDNI_NMT_Spec_H1_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +tractor_HP text, +rated_rpm text, +configuration text, +transmission_type text, +wheel_drive_type text, +FIP_type text, +steering_type text, +Engine_to_PTO_ratio text, +Ballast_Condition text, +Test_Engine_Set_RPM text, +Type_of_track text , +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_NMT_Atmos_Cond_1_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +trx_record int default 1, +block_row_number int +); + +create table staging2.BUDNI_NMT_Noise_at_bystander_position_block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_NMT_Meas_Results_1_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_NMT_Noise_at_operator_ear_level_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_NMT_Atmos_Cond_2_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_NMT_Meas_Results_2_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_NMT_Test_Obs_Summary_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create TABLE staging2.stg_process_table_BUDNI_NMT ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 NULL, +create_time timestamp DEFAULT current_timestamp, +block_row_number int4 NULL, +block_tag text null +); + + +CREATE TABLE staging2.stg_specific_table_BUDNI_NMT ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 null, +create_time timestamp DEFAULT current_timestamp +); + + diff --git a/onetime/createtables/staging/create_tables_BUDNI_PTO.sql b/onetime/createtables/staging/create_tables_BUDNI_PTO.sql new file mode 100755 index 0000000..7c95eb2 --- /dev/null +++ b/onetime/createtables/staging/create_tables_BUDNI_PTO.sql @@ -0,0 +1,282 @@ +drop table if exists staging2.stg_specific_table_BUDNI_PTO; +drop table if exists staging2.stg_process_table_BUDNI_PTO; +drop table if exists staging2.BUDNI_PTO_Spec_H1_Block; +drop table if exists staging2.BUDNI_PTO_Perf_Report_block; +drop table if exists staging2.BUDNI_PTO_MMTKeyword1_Block; +drop table if exists staging2.BUDNI_PTO_MMTKeyword2_Block; +drop table if exists staging2.BUDNI_PTO_Summary_Block; + + +create table staging2.BUDNI_PTO_Spec_H1_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +tractor_HP text, +rated_rpm text, +configuration text, +transmission_type text, +wheel_drive_type text, +FIP_type text, +steering_type text, +Engine_to_PTO_ratio text, +date date, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_PTO_Perf_Report_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_PTO_MMTKeyword1_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_PTO_MMTKeyword2_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.BUDNI_PTO_Summary_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create TABLE staging2.stg_process_table_BUDNI_PTO ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 NULL, +create_time timestamp DEFAULT current_timestamp, +block_row_number int4 NULL, +block_tag text null +); + + +CREATE TABLE staging2.stg_specific_table_BUDNI_PTO ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 null, +create_time timestamp DEFAULT current_timestamp +); + + diff --git a/onetime/createtables/staging/create_tables_BUDNI_VMT.sql b/onetime/createtables/staging/create_tables_BUDNI_VMT.sql new file mode 100755 index 0000000..7d56a4b --- /dev/null +++ b/onetime/createtables/staging/create_tables_BUDNI_VMT.sql @@ -0,0 +1,224 @@ +drop table if exists staging2.BUDNI_VMT_Spec_H1_Block; +drop table if exists staging2.BUDNI_VMT_Perf_Meas_Test_Block; +drop table if exists staging2.BUDNI_VMT_Test_Obs_Summary_Block; +drop table if exists staging2.stg_process_table_BUDNI_VMT; +drop table if exists staging2.stg_specific_table_BUDNI_VMT; + + +create table staging2.BUDNI_VMT_Spec_H1_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +tractor_HP text, +rated_rpm text, +configuration text, +transmission_type text, +wheel_drive_type text, +FIP_type text, +steering_type text, +Engine_to_PTO_ratio text, +Ballast_Condition text, +Test_Engine_Set_RPM text, +Type_of_track text , +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.BUDNI_VMT_Perf_Meas_Test_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.BUDNI_VMT_Test_Obs_Summary_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create TABLE staging2.stg_process_table_BUDNI_VMT ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 NULL, +create_time timestamp DEFAULT current_timestamp, +block_row_number int4 NULL, +block_tag text null +); + + +CREATE TABLE staging2.stg_specific_table_BUDNI_VMT ( + generic_syspk int, +file_syspk bigint, +file_name varchar(1024) NULL, +file_date date NULL, +file_mnemonic varchar(1024) NULL, +sheet_number int4 NULL, +sheet_name varchar(1024) NULL, +sheet_format text, +file_sheet_mnemonic varchar(1024) NULL, +row_number int4 NULL, +file_creation_date timestamp NULL, +column1 varchar(1024) NULL, +column2 varchar(1024) NULL, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +column25 varchar(1024) NULL, +column26 varchar(1024) NULL, +column27 varchar(1024) NULL, +column28 varchar(1024) NULL, +column29 varchar(1024) NULL, +column30 varchar(1024) NULL, +column31 varchar(1024) NULL, +column32 varchar(1024) NULL, +column33 varchar(1024) NULL, +column34 varchar(1024) NULL, +column35 varchar(1024) NULL, +column36 varchar(1024) NULL, +column37 varchar(1024) NULL, +column38 varchar(1024) NULL, +column39 varchar(1024) NULL, +column40 varchar(1024) NULL, +column41 varchar(1024) NULL, +column42 varchar(1024) NULL, +column43 varchar(1024) NULL, +column44 varchar(1024) NULL, +column45 varchar(1024) NULL, +column46 varchar(1024) NULL, +column47 varchar(1024) NULL, +column48 varchar(1024) NULL, +column49 varchar(1024) NULL, +column50 varchar(1024) NULL, +column51 varchar(1024) NULL, +column52 varchar(1024) NULL, +column53 varchar(1024) NULL, +is_rownumber_fetched int4 null, +create_time timestamp DEFAULT current_timestamp +); + + diff --git a/onetime/createtables/staging/create_tables_DBOECD.sql b/onetime/createtables/staging/create_tables_DBOECD.sql new file mode 100755 index 0000000..eae450e --- /dev/null +++ b/onetime/createtables/staging/create_tables_DBOECD.sql @@ -0,0 +1,750 @@ + +SET search_path TO staging2; + +drop table if exists staging2.dboecd_test_transmission_wheels_int; +drop table if exists staging2.DBOECD_TEST_H1_Block; +drop table if EXISTS staging2.DBOECD_TEST_H1_INT ; +drop table if exists staging2.dboecd_test_engine_rpm_engine_to_pto_block; +drop table if exists staging2.dboecd_test_engine_rpm_required_pull_block; +drop table if exists staging2.dboecd_test_engine_rpm_weight_block; +drop table if exists staging2.dboecd_test_engine_rpm_tyre_details_block; +drop table if exists staging2.dboecd_test_engine_RPM_tyre_details_int; +drop table if exists staging2.dboecd_test_test_condition_block; +drop table if exists staging2.dboecd_test_drawbar_performance_selected_summary_block; +drop table if exists staging2.dboecd_test_drawbar_performance_gear_performance_block; +drop table if exists staging2.dboecd_test_drawbar_performance_fuel_consumption_block; +drop table if exists staging2.dboecd_test_test_equipment_used_block; +drop table if exists staging2.dboecd_test_measurement_uncertainty_block; +drop table if exists staging2.dboecd_test_tractor_specifications_engine_details_block; +drop table if exists staging2.dboecd_test_tractor_specifications_cylinders_block; +drop table if exists staging2.dboecd_test_tractor_specifications_fuel_and_injection_block; +drop table if exists staging2.dboecd_test_tractor_specifications_cleaner_block; +drop table if exists staging2.dboecd_test_transmission_clutch_block; +drop table if exists staging2.dboecd_test_transmission_drawbar_block; +drop table if exists staging2.dboecd_test_transmission_speed_chart_desc_block; +drop table if exists staging2.dboecd_test_transmission_wheels_block; +drop table if exists staging2.dboecd_test_transmission_fuel_lubricant_int; +drop table if exists staging2.dboecd_test_remarks_block; +drop table if exists staging2.dboecd_test_remarks_footer_block; +drop table if exists staging2.dboecd_test_transmission_fuel_lubricant_block; +drop table if exists staging2.dboecd_test_engine_rpm_rpm_block; +drop table if exists staging2.dboecd_test_transmission_speed_chart_block; +drop table if exists staging2.stg_specific_table_dboecd_test; +drop table if exists staging2.stg_process_table_dboecd_test; + +create table staging2.DBOECD_TEST_H1_INT +(syspk serial, +dummy_f text, +file_syspk int, +client_id int, +function_id int, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +c1 text, +c2 text, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBOECD_TEST_H1_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Test_Request_no text, +Sample_Receipt_Date text, +Test_report_No text, +Tractor_Model text, +Generation text, +Customer_Name text, +Test_Engineer text, +Test_Report_Date text, +No_of_Sample text, +Test_Start_Date text, +Test_End_Date text, +Tractor_Sr_No text, +Test_Standard_Refer text, +Test_Location text, +Operator_Name text, +Project_Group text, +Objective text, +Acceptance_criteria text, +block_row_number int4 NULL, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.DBOECD_test_engine_RPM_RPM_block +(syspk serial,dummy_f text,file_syspk int,client_id int,function_id int,make text,model text,file_mnemonic text,file_sheet_mnemonic text,low_idle_declared text,high_idle_declared text,low_idle_observed text,high_idle_observed text,create_time timestamp DEFAULT current_timestamp); + +create table staging2.DBOECD_test_engine_RPM_engine_to_PTO_block(syspk serial,dummy_f text,file_syspk int,client_id int,function_id int,make text,model text, file_mnemonic text,file_sheet_mnemonic text,rated_speed text,engine_to_PTO_ratio text, wheel_base_mm text,engine_power_hp text,PTO_Power_hp text,create_time timestamp DEFAULT current_timestamp); + +create table staging2.DBOECD_test_engine_RPM_required_pull_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +pull_type text, +required_pull_in_kg text, +required_power_in_hp text, +actual_pull_in_kg text, +actual_power_in_hp text, +calculated_hitch_height_mm text, +actual_hitch_height_mm text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBOECD_test_engine_RPM_weight_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +weight_kg text, +Front text, +rear text, +Total text, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.DBOECD_test_engine_RPM_tyre_details_int +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +s_no text, +tyre_details text, +front text, +rear text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBOECD_test_engine_RPM_tyre_details_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +model text, +Make text, +file_mnemonic text, +file_sheet_mnemonic text, +tyre_make text, +size text, +Ply_Rating text, +Load_Carrying_Capacity_in_Kg text, +Pressure_kg_cm2 text, +Number_of_lug text, +Number_of_no_load_lug_30m text, +Lug_Height text, +Dynamic_rolling_radius_mm text, +Wheel_Rim_Make_Size text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBOECD_test_test_condition_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +c1 text, +c2 text, +c3 text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBOECD_test_drawbar_performance_selected_summary_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +c1 text , +c2 text , +c3 text , +c4 text , +c5 text , +c6 text , +c7 text , +c8 text , +c9 text , +c10 text , +c11 text , +c12 text , +c13 text , +c14 text , +c15 text , +c16 text , +c17 text , +c18 text , +c19 text , +c20 text , +c21 text , +c22 text , +c23 text , +c24 text , +c25 text , +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBOECD_test_drawbar_performance_gear_performance_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +c1 text , +c2 text , +c3 text , +c4 text , +c5 text , +c6 text , +c7 text , +c8 text , +c9 text , +c10 text , +c11 text , +c12 text , +c13 text , +c14 text , +c15 text , +c16 text , +c17 text , +c18 text , +c19 text , +c20 text , +c21 text , +c22 text , +c23 text , +c24 text , +c25 text , +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBOECD_test_drawbar_performance_fuel_consumption_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +c1_1 text, +c2_1 text, +c1 text , +c2 text , +c3 text , +c4 text , +c5 text , +c6 text , +c7 text , +c8 text , +c9 text , +c10 text , +c11 text , +c12 text , +c13 text , +c14 text , +c15 text , +c16 text , +c17 text , +c18 text , +c19 text , +c20 text , +c21 text , +c22 text , +c23 text , +c24 text , +c25 text , +Remark text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBOECD_test_test_equipment_used_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +s_no text, +instruments text, +instruments_no text, +cali_due_date text, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.DBOECD_test_measurement_uncertainty_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +load_cell text, +rpm_meter text, +speed text, +fuel_flow_meter text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBOECD_test_tractor_specifications_engine_details_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +file_mnemonic text, +file_sheet_mnemonic text, +make_in_block text, +type text, +model_in_block text, +serial_no text, +E_P_Ratio text, +rated_speed text, +high_idle text, +low_Idle text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBOECD_test_tractor_specifications_cylinders_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +number text, +stroke text, +bore text, +capacity text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBOECD_test_tractor_specifications_fuel_and_injection_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +capacity_of_fuel_tank_lit text, +make_type_and_model_of_injection_pump text, +manufacturer_production_setting text, +make_type_and_model_of_injectors text, +make_type_and_model_of_magneto_coil_and_distributor text, +make_type_and_model_of_carburetor text, +ignition_or_injection_timing_Manual_or_automatic text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBOECD_test_tractor_specifications_cleaner_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +cleaner_type text, +make_and_model text, +type text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBOECD_test_transmission_clutch_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +clutch_type text, +steering_type text, +diameter_of_disc_mm text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBOECD_test_transmission_drawbar_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Type text, +Height_above_ground_max_mm text , +Height_above_ground_min_mm text, +Position_related_to_PTO text, +Wheel_Base text, +test_condition text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBOECD_test_transmission_speed_chart_desc_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +descr text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBOECD_test_transmission_speed_chart_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +tyre_condition text, +gear text, +forward text, +reverse text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBOECD_test_transmission_wheels_int +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Descriptions text, +Steered_wheels text, +Driving_wheel text, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.DBOECD_test_transmission_wheels_block + ( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Make_of_tyres text, +Types text, +Size text, +Maximum_permissible_load_kg text, +Ply_rating text, +Track_width_max_mm text, +Track_width_min_mm text, +Inflation_pressure_kg_cm2 text, +Location_of_driving_wheel text, +create_time timestamp DEFAULT current_timestamp + ); + + +create table staging2.DBOECD_test_transmission_fuel_lubricant_int +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Descriptions text, +Diesel_BS_IV text, +Engine_oil text, +Transmission_oil text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBOECD_test_transmission_fuel_lubricant_block + ( +syspk serial, +client_id int, +function_id int, +dummy_f text, +file_syspk int, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, + Trade_name text, +type text, +Octane_Cetane_number text, +Viscosity text, +Density_at_15C text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBOECD_test_remarks_block +( +syspk serial, +client_id int, +function_id int, +dummy_f text, +file_syspk int, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +remarks text, +parameter text, +acceptance_criteria text, +observations text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBOECD_test_remarks_footer_block +( +syspk serial, +client_id int, +function_id int, +dummy_f text, +file_syspk int, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +prepared_by text, +approved_by text, +date text, +replaces text, +revision_no text, +comments text, +rev1 text, +rev2 text, +rev3 text, +create_time timestamp DEFAULT current_timestamp +); + +create TABLE staging2.stg_process_table_dboecd_test ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 NULL, + create_time timestamp DEFAULT current_timestamp, + block_row_number int4 NULL, + block_tag text null +); + + +CREATE TABLE staging2.stg_specific_table_dboecd_test ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 null, + create_time timestamp DEFAULT current_timestamp +); \ No newline at end of file diff --git a/onetime/createtables/staging/create_tables_DBSTD.sql b/onetime/createtables/staging/create_tables_DBSTD.sql new file mode 100755 index 0000000..6c64912 --- /dev/null +++ b/onetime/createtables/staging/create_tables_DBSTD.sql @@ -0,0 +1,696 @@ +/* create block tables */ + +SET search_path TO staging2; + +drop table if exists staging2.dbstd_test_transmission_wheels_int; +drop table if exists staging2.dbstd_test_h1_int; +drop table if exists staging2.dbstd_test_engine_rpm_engine_to_pto_block; +drop table if exists staging2.dbstd_test_engine_rpm_required_pull_block; +drop table if exists staging2.dbstd_test_engine_rpm_weight_block; +drop table if exists staging2.dbstd_test_engine_rpm_tyre_details_block; +drop table if exists staging2.DBSTD_test_engine_RPM_tyre_details_int; +drop table if exists staging2.dbstd_test_test_condition_block; +drop table if exists staging2.dbstd_test_drawbar_performance_selected_summary_block; +drop table if exists staging2.dbstd_test_drawbar_performance_gear_performance_block; +drop table if exists staging2.dbstd_test_test_equipment_used_block; +drop table if exists staging2.dbstd_test_measurement_uncertainty_block; +drop table if exists staging2.dbstd_test_tractor_specifications_engine_details_block; +drop table if exists staging2.dbstd_test_tractor_specifications_cylinders_block; +drop table if exists staging2.dbstd_test_tractor_specifications_fuel_and_injection_block; +drop table if exists staging2.dbstd_test_tractor_specifications_cleaner_block; +drop table if exists staging2.dbstd_test_transmission_clutch_block; +drop table if exists staging2.dbstd_test_transmission_drawbar_block; +drop table if exists staging2.dbstd_test_transmission_speed_chart_desc_block; +drop table if exists staging2.dbstd_test_transmission_wheels_block; +drop table if exists staging2.dbstd_test_transmission_fuel_lubricant_int; +drop table if exists staging2.dbstd_test_remarks_block; +drop table if exists staging2.dbstd_test_remarks_footer_block; +drop table if exists staging2.dbstd_test_h1_block; +drop table if exists staging2.dbstd_test_transmission_fuel_lubricant_block; +drop table if exists staging2.dbstd_test_engine_rpm_rpm_block; +drop table if exists staging2.dbstd_test_transmission_speed_chart_block; +drop table if exists staging2.stg_specific_table_dbstd_test; +drop table if exists staging2.stg_process_table_dbstd_test; + +create table staging2.DBSTD_TEST_H1_INT (syspk serial,dummy_f text,file_syspk int,client_id int,function_id int,make text,model text,file_mnemonic text,file_sheet_mnemonic text,c1 text,c2 text); + +create table staging2.DBSTD_TEST_H1_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Test_Request_no text, +Sample_Receipt_Date text, +Test_report_No text, +Tractor_Model text, +Generation text, +Customer_Name text, +Test_Engineer text, +Test_Report_Date text, +No_of_Sample text, +Test_Start_Date text, +Test_End_Date text, +Tractor_Sr_No text, +Test_Standard_Refer text, +Test_Location text, +Operator_Name text, +Project_Group text, +Objective text, +Acceptance_criteria text, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.DBSTD_test_engine_RPM_RPM_block +(syspk serial,dummy_f text,file_syspk int,client_id int,function_id int,make text,model text,file_mnemonic text,file_sheet_mnemonic text,low_idle_declared text,high_idle_declared text,low_idle_observed text,high_idle_observed text,create_time timestamp DEFAULT current_timestamp); + +create table staging2.DBSTD_test_engine_RPM_engine_to_PTO_block(syspk serial,dummy_f text,file_syspk int,client_id int,function_id int,make text,model text, file_mnemonic text,file_sheet_mnemonic text,rated_speed text,engine_to_PTO_ratio text, wheel_base_mm text,engine_power_hp text,PTO_Power_hp text,create_time timestamp DEFAULT current_timestamp); + +create table staging2.DBSTD_test_engine_RPM_required_pull_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +pull_type text, +required_pull_in_kg text, +required_power_in_hp text, +actual_pull_in_kg text, +actual_power_in_hp text, +calculated_hitch_height_mm text, +actual_hitch_height_mm text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBSTD_test_engine_RPM_weight_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +weight_kg text, +Front text, +rear text, +Total text, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.DBSTD_test_engine_RPM_tyre_details_int +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +s_no text, +tyre_details text, +front text, +rear text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBSTD_test_engine_RPM_tyre_details_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +model text, +Make text, +file_mnemonic text, +file_sheet_mnemonic text, +tyre_make text, +size text, +Ply_Rating text, +Load_Carrying_Capacity_in_Kg text, +Pressure_kg_cm2 text, +Number_of_lug text, +Number_of_no_load_lug_30m text, +Lug_Height text, +Dynamic_rolling_radius_mm text, +Wheel_Rim_Make_Size text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBSTD_test_test_condition_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +c1 text, +c2 text, +c3 text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBSTD_test_drawbar_performance_selected_summary_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +c1 text , +c2 text , +c3 text , +c4 text , +c5 text , +c6 text , +c7 text , +c8 text , +c9 text , +c10 text , +c11 text , +c12 text , +c13 text , +c14 text , +c15 text , +c16 text , +c17 text , +c18 text , +c19 text , +c20 text , +c21 text , +c22 text , +c23 text , +c24 text , +c25 text , +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBSTD_test_drawbar_performance_gear_performance_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +c1 text , +c2 text , +c3 text , +c4 text , +c5 text , +c6 text , +c7 text , +c8 text , +c9 text , +c10 text , +c11 text , +c12 text , +c13 text , +c14 text , +c15 text , +c16 text , +c17 text , +c18 text , +c19 text , +c20 text , +c21 text , +c22 text , +c23 text , +c24 text , +c25 text , +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBSTD_test_test_equipment_used_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +s_no text, +instruments text, +instruments_no text, +cali_due_date text, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.DBSTD_test_measurement_uncertainty_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +load_cell text, +rpm_meter text, +speed text, +fuel_flow_meter text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBSTD_test_tractor_specifications_engine_details_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +file_mnemonic text, +file_sheet_mnemonic text, +make_in_block text, +type text, +model_in_block text, +serial_no text, +E_P_Ratio text, +rated_speed text, +high_idle text, +low_Idle text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBSTD_test_tractor_specifications_cylinders_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +number text, +stroke text, +bore text, +capacity text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBSTD_test_tractor_specifications_fuel_and_injection_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +capacity_of_fuel_tank_lit text, +make_type_and_model_of_injection_pump text, +manufacturer_production_setting text, +make_type_and_model_of_injectors text, +make_type_and_model_of_magneto_coil_and_distributor text, +make_type_and_model_of_carburetor text, +ignition_or_injection_timing_Manual_or_automatic text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBSTD_test_tractor_specifications_cleaner_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +cleaner_type text, +make_and_model text, +type text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBSTD_test_transmission_clutch_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +clutch_type text, +steering_type text, +diameter_of_disc_mm text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBSTD_test_transmission_drawbar_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Type text, +Height_above_ground_max_mm text , +Height_above_ground_min_mm text, +Position_related_to_PTO text, +Wheel_Base text, +test_condition text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBSTD_test_transmission_speed_chart_desc_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +descr text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBSTD_test_transmission_speed_chart_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +tyre_condition text, +gear text, +forward text, +reverse text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.dbstd_test_transmission_wheels_int +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Descriptions text, +Steered_wheels text, +Driving_wheel text, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.dbstd_test_transmission_wheels_block + ( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Make_of_tyres text, +Types text, +Size text, +Maximum_permissible_load_kg text, +Ply_rating text, +Track_width_max_mm text, +Track_width_min_mm text, +Inflation_pressure_kg_cm2 text, +Location_of_driving_wheel text, +create_time timestamp DEFAULT current_timestamp + ); + + +create table staging2.DBSTD_test_transmission_fuel_lubricant_int +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Descriptions text, +Diesel_BS_IV text, +Engine_oil text, +Transmission_oil text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBSTD_test_transmission_fuel_lubricant_block + ( +syspk serial, +client_id int, +function_id int, +dummy_f text, +file_syspk int, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, + Trade_name text, +type text, +Octane_Cetane_number text, +Viscosity text, +Density_at_15C text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBSTD_test_remarks_block +( +syspk serial, +client_id int, +function_id int, +dummy_f text, +file_syspk int, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +remarks text, +parameter text, +acceptance_criteria text, +observations text, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.DBSTD_test_remarks_footer_block +( +syspk serial, +client_id int, +function_id int, +dummy_f text, +file_syspk int, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +prepared_by text, +reviewed_by text, +approved_by text, +date text, +replaces text, +revision_no text, +comments text, +rev1 text, +rev2 text, +rev3 text, +create_time timestamp DEFAULT current_timestamp +); + + +create TABLE staging2.stg_process_table_dbstd_test ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 NULL, + create_time timestamp DEFAULT current_timestamp, + block_row_number int4 NULL, + block_tag text null +); + + + +CREATE TABLE staging2.stg_specific_table_dbstd_test ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 null, + create_time timestamp DEFAULT current_timestamp +); diff --git a/onetime/createtables/staging/create_tables_PTO.sql b/onetime/createtables/staging/create_tables_PTO.sql new file mode 100755 index 0000000..5619fe6 --- /dev/null +++ b/onetime/createtables/staging/create_tables_PTO.sql @@ -0,0 +1,939 @@ + +SET search_path TO staging2; + +drop table if exists staging2.stg_process_table_PTOBEN_PRF; +drop table if exists staging2.stg_specific_table_PTOBEN_PRF; +drop table if exists staging2.stg_process_table_PTOBEN_MPM; +drop table if exists staging2.stg_specific_table_PTOBEN_MPM; +drop table if exists staging2.stg_process_table_PTOBEN_GVG; +drop table if exists staging2.stg_specific_table_PTOBEN_GVG; +drop table if exists staging2.PTOBEN_PRF_tractor_specs_int; +drop table if exists staging2.PTOBEN_PRF_tractor_specs_block; +drop table if exists staging2.PTOBEN_PRF_key_performance_parameters_int; +drop table if exists staging2.PTOBEN_PRF_key_performance_parameters_block; +drop table if exists staging2.PTOBEN_PRF_varying_speed_natural_ambient_block; +drop table if exists staging2.PTOBEN_PRF_2hrs_max_power_natural_ambient_block; +drop table if exists staging2.PTOBEN_PRF_varying_load_rated_rpm_block; +drop table if exists staging2.PTOBEN_PRF_varying_load_std_pto_block; +drop table if exists staging2.PTOBEN_PRF_smoke_test_block; +drop table if exists staging2.PTOBEN_PRF_varying_speed_test_high_ambient_block; +drop table if exists staging2.PTOBEN_PRF_2hrs_max_power_test_high_ambient_block; +drop table if exists staging2.PTOBEN_PRF_engine_oil_consumption_block; +drop table if exists staging2.PTOBEN_MPM_performance_boost_natural_block; +drop table if exists staging2.PTOBEN_GVG_performance_governing_trails_block; + +create table staging2.PTOBEN_PRF_tractor_specs_int +( +file_syspk serial, +c1 text, +c2 text, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.PTOBEN_PRF_tractor_specs_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +file_mnemonic text, +file_sheet_mnemonic text, +make text, +model text, +test_standard text, +tractor_emmission text, +tractor_serial_number text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.PTOBEN_PRF_key_performance_parameters_int +( +file_syspk serial, +c1 text, +c2 text, +c3 text, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.PTOBEN_PRF_key_performance_parameters_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +file_mnemonic text, +file_sheet_mnemonic text, +make text, +model text, +test_standard text, +tractor_emmission text, +tractor_serial_number text, +test_condition text, +Engine_to_PTO_ratio text, +specific_gravity_of_fuel text, +PTO_power_hp text, +PTO_power_Kw text, +PTO_SFC_gm_hp text, +PTO_SFC_Kw_hp text, +pct_of_backup_torque text, +Maximum_Equ_crankshaft_Torque_Nm text, +Equ_Crankshaft_Torque_Maximum_Power_Nm text, +Engine_speed_at_maximum_equivalent_crankshaft_torque_rpm text, +Rated_engine_speed text, +max_torque_engine_speed text, +Engine_low_idle_speed text, +Engine_high_Idle_speed text, +Engine_oil_temp_NA text, +Coolant_temp_NA text, +Engine_oil_temp_HA text, +Coolant_temp_HA text, +Ambient_pressure_bar text, +Ambient_pressure_mm_of_hg text, +back_pressure_bar text, +back_pressure_mm_of_hg text, +Engine_oil_pressure_bar text, +exhaust_temperature_C text, +Relative_humidity_pct text, +Coolant_water_pct text, +Test_engineer text, +Test_bed text, +Place text, +Total_run_hrs text, +Test_date text, +Tooled_up text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.PTOBEN_PRF_varying_speed_natural_ambient_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +file_mnemonic text, +file_sheet_mnemonic text, +make text, +model text, +test_condition text, +c2 text, +c3 text, +c4 text, +c5 text, +c6 text, +c7 text, +c8 text, +c9 text, +c10 text, +c11 text, +c12 text, +c13 text, +c14 text, +c15 text, +c16 text, +c17 text, +c18 text, +c19 text, +c20 text, +c21 text, +c22 text, +c23 text, +c24 text, +c25 text, +c26 text, +c27 text, +c28 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.PTOBEN_PRF_2hrs_max_power_natural_ambient_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +file_mnemonic text, +file_sheet_mnemonic text, +make text, +model text, +test_condition text, +c2 text, +c3 text, +c4 text, +c5 text, +c6 text, +c7 text, +c8 text, +c9 text, +c10 text, +c11 text, +c12 text, +c13 text, +c14 text, +c15 text, +c16 text, +c17 text, +c18 text, +c19 text, +c20 text, +c21 text, +c22 text, +c23 text, +c24 text, +c25 text, +c26 text, +c27 text, +c28 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.PTOBEN_PRF_varying_load_rated_rpm_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +file_mnemonic text, +file_sheet_mnemonic text, +make text, +model text, +test_condition text, +c1 text, +c2 text, +c3 text, +c4 text, +c5 text, +c6 text, +c7 text, +c8 text, +c9 text, +c10 text, +c11 text, +c12 text, +c13 text, +c14 text, +c15 text, +c16 text, +c17 text, +c18 text, +c19 text, +c20 text, +c21 text, +c22 text, +c23 text, +c24 text, +c25 text, +c26 text, +c27 text, +c28 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.PTOBEN_PRF_varying_load_std_pto_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +file_mnemonic text, +file_sheet_mnemonic text, +make text, +model text, +test_condition text, +c1 text, +c2 text, +c3 text, +c4 text, +c5 text, +c6 text, +c7 text, +c8 text, +c9 text, +c10 text, +c11 text, +c12 text, +c13 text, +c14 text, +c15 text, +c16 text, +c17 text, +c18 text, +c19 text, +c20 text, +c21 text, +c22 text, +c23 text, +c24 text, +c25 text, +c26 text, +c27 text, +c28 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.PTOBEN_PRF_smoke_test_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +file_mnemonic text, +file_sheet_mnemonic text, +make text, +model text, +test_condition text, +c2 text, +c3 text, +c4 text, +c5 text, +c6 text, +c7 text, +c8 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.PTOBEN_PRF_varying_speed_test_high_ambient_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +file_mnemonic text, +file_sheet_mnemonic text, +make text, +model text, +test_condition text, +c2 text, +c3 text, +c4 text, +c5 text, +c6 text, +c7 text, +c8 text, +c9 text, +c10 text, +c11 text, +c12 text, +c13 text, +c14 text, +c15 text, +c16 text, +c17 text, +c18 text, +c19 text, +c20 text, +c21 text, +c22 text, +c23 text, +c24 text, +c25 text, +c26 text, +c27 text, +c28 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.PTOBEN_PRF_2hrs_max_power_test_high_ambient_block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +file_mnemonic text, +file_sheet_mnemonic text, +make text, +model text, +test_condition text, +c2 text, +c3 text, +c4 text, +c5 text, +c6 text, +c7 text, +c8 text, +c9 text, +c10 text, +c11 text, +c12 text, +c13 text, +c14 text, +c15 text, +c16 text, +c17 text, +c18 text, +c19 text, +c20 text, +c21 text, +c22 text, +c23 text, +c24 text, +c25 text, +c26 text, +c27 text, +c28 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + +CREATE TABLE staging2.PTOBEN_PRF_engine_oil_consumption_block ( + syspk serial NOT NULL, + client_id int4 NULL, + function_id int4 NULL, + file_syspk int4 NULL, + dummy_f text NULL, + file_mnemonic text NULL, + file_sheet_mnemonic text NULL, + make text NULL, + model text NULL, + test_condition text NULL, + c2 text NULL, + c3 text NULL, + c5 text NULL, + block_row_number int NULL, + trx_record int4 NULL DEFAULT 1, +create_time timestamp DEFAULT current_timestamp +); + + + + +CREATE TABLE staging2.PTOBEN_MPM_performance_boost_natural_block ( + syspk serial NOT NULL, + client_id int4 NULL, + function_id int4 NULL, + file_syspk int4 NULL, + dummy_f text NULL, + file_mnemonic text NULL, + file_sheet_mnemonic text NULL, + make text NULL, + model text NULL, + test_condition text NULL, + c2 text NULL, + c3 text NULL, + c4 text NULL, + c5 text NULL, + block_row_number int NULL, + trx_record int4 NULL DEFAULT 1, + create_time timestamp NULL DEFAULT CURRENT_TIMESTAMP +); + + +create TABLE staging2.PTOBEN_GVG_performance_governing_trails_block ( +syspk serial NOT NULL, +client_id int4 NULL, +function_id int4 NULL, +file_syspk int4 NULL, +dummy_f text NULL, +file_mnemonic text NULL, +file_sheet_mnemonic text NULL, +make text NULL, +model text NULL, +test_condition text NULL, +c1 text null, +c2 text null, +c3 text null, +c4 text null, +c5 text null, +c6 text null, +c7_1 text null, +c7 text null, +c8 text null, +c9 text null, +c10 text null, +c11 text null, +c12_1 text null, +c12 text null, +c13 text null, +c14 text null, +c15 text null, +c16 text null, +c17_1 text null, +c17 text null, +c18 text null, +c19 text null, +c20 text null, +c21 text null, +c22_1 text null, +c22 text null, +c23 text null, +c24 text null, +c25 text null, +c26 text null, +c27 text null, +c27_1 text null, +c28 text null, +c29 text null, +c30 text null, +c31 text null, +c32_1 text null, +c32 text null, +c33 text null, +c34 text null, +c35 text null, +c36 text null, +block_row_number int, +trx_record int4 NULL DEFAULT 1, +create_time timestamp NULL DEFAULT CURRENT_TIMESTAMP +); + + +/*sheet */ + +create TABLE staging2.stg_process_table_PTOBEN_PRF ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 NULL, + create_time timestamp DEFAULT current_timestamp, + block_row_number int4 NULL, + block_tag text null +); + + + +CREATE TABLE staging2.stg_specific_table_PTOBEN_PRF ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 null, + create_time timestamp DEFAULT current_timestamp +); + + +create TABLE staging2.stg_process_table_PTOBEN_MPM ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 NULL, + create_time timestamp DEFAULT current_timestamp, + block_row_number int4 NULL, + block_tag text null +); + + + +CREATE TABLE staging2.stg_specific_table_PTOBEN_MPM ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 null, + create_time timestamp DEFAULT current_timestamp +); + + + +create TABLE staging2.stg_process_table_PTOBEN_GVG ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 NULL, + create_time timestamp DEFAULT current_timestamp, + block_row_number int4 NULL, + block_tag text null +); + + + +CREATE TABLE staging2.stg_specific_table_PTOBEN_GVG ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 null, + create_time timestamp DEFAULT current_timestamp +); diff --git a/onetime/createtables/staging/create_tables_iht_cgm.sql b/onetime/createtables/staging/create_tables_iht_cgm.sql new file mode 100755 index 0000000..04f14e6 --- /dev/null +++ b/onetime/createtables/staging/create_tables_iht_cgm.sql @@ -0,0 +1,370 @@ +drop table if exists staging2.IHTCGM_CGM_H1_Int; +drop table if exists staging2.IHTCGM_CGM_H1_block; +drop table if exists staging2.IHTCGM_CGM_Weight_Tyre_Int; +drop table if exists staging2.IHTCGM_CGM_Weight_Block; +drop table if exists staging2.IHTCGM_CGM_Wheel_Block; +drop table if exists staging2.IHTCGM_CGM_Tyre_Details_Block; +drop table if exists staging2.IHTCGM_CGM_Lifting_Block; +drop table if exists staging2.IHTCGM_CGM_Results_Block; +drop table if exists staging2.IHTCGM_CGM_Footer_Block; +drop table if exists staging2.stg_specific_table_IHTCGM_CGM; +drop table if exists staging2.stg_process_table_IHTCGM_CGM; + +create table staging2.IHTCGM_CGM_H1_INT +(syspk serial,dummy_f text,file_syspk int,client_id int,function_id int +,make text,model text,file_mnemonic text,file_sheet_mnemonic text,c1 text,c2 text); + +create table staging2.IHTCGM_CGM_H1_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Test_Request_no text, +Sample_Receipt_Date text, +Test_report_No text, +Tractor_Model text, +Generation text, +Customer_Name text, +Test_Engineer text, +Test_Report_Date text, +No_of_Sample text, +Test_Start_Date text, +Test_End_Date text, +Tractor_Sr_No text, +Test_Standard_Refer text, +Test_Location text, +Operator_Name text, +Project_Group text, +Objective text, +Acceptance_Criteria text, +Remarks text, +Test_Purpose text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTCGM_CGM_Weight_Tyre_Int +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +column13 text, +column14 text, +column15 text, +column16 text, +column17 text, +column18 text, +column19 text, +column20 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTCGM_CGM_Weight_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +Weight_Reaction text, +Total_Weight_kg text, +Front_Reaction_kg text, +Rear_Reaction_kg text, +Left_Reaction_FL_RL_kg text, +Right_reaction_FR_RR_kg text, +Front_Left_Reaction_kg text, +Front_Right_Reaction_kg text, +Rear_Left_Reaction_kg text, +Rear_Right_Reaction_kg text, +Distance_of_lifting_point_from_rear_axle_mm_d1 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTCGM_CGM_Tyre_Details_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Tyre_Details text, +Tyre_Make text, +Tyre_size text, +Ply_Rating text, +Load_Carrying_Capacity text, +Pressure_kg_cm2 text, +Dynamic_rolling_radius text, +Static_rolling_radius text, +Wheel_rim_Make_size text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTCGM_CGM_Wheel_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +Wheel_Base text, +Rear_Track_Width text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTCGM_CGM_Lifting_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTCGM_CGM_Results_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +Determination_of_Horizontal_Distance_from_RAC_X text, +Determination_of_Lateral_CoOrdinate_in_Horizontal_Plane_Y text, +Determination_of_Vertical_CoOrdinate_Z text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTCGM_CGM_Footer_Block +( +syspk serial, +client_id int, +function_id int, +dummy_f text, +file_syspk int, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +prepared_by text, +reviewed_by text, +approved_by text, +replaces text, +revision_no text, +prepared_date text, +reviewed_date text, +approved_date text, +comments text, +rev1 text, +rev2 text, +rev3 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create TABLE staging2.stg_process_table_IHTCGM_CGM ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 NULL, + create_time timestamp DEFAULT current_timestamp, + block_row_number int4 NULL, + block_tag text null +); + + + +CREATE TABLE staging2.stg_specific_table_IHTCGM_CGM ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 null, + create_time timestamp DEFAULT current_timestamp +); + + diff --git a/onetime/createtables/staging/create_tables_iht_emt.sql b/onetime/createtables/staging/create_tables_iht_emt.sql new file mode 100755 index 0000000..4e2e09d --- /dev/null +++ b/onetime/createtables/staging/create_tables_iht_emt.sql @@ -0,0 +1,397 @@ +drop table if exists staging2.IHTEMT_EMT_H1_INT; +drop table if exists staging2.IHTEMT_EMT_H1_block; +drop table if exists staging2.IHTEMT_EMT_Weight_Tyre_Int; +drop table if exists staging2.IHTEMT_EMT_Weight_Block; +drop table if exists staging2.IHTEMT_EMT_Wheel_Block; +drop table if exists staging2.IHTEMT_EMT_Tyre_Details_Block; +drop table if exists staging2.IHTEMT_EMT_Steering_Block; +drop table if exists staging2.IHTEMT_EMT_Pedal_Block; +drop table if exists staging2.IHTEMT_EMT_Brake_Pedal_Block; +drop table if exists staging2.IHTEMT_EMT_Footer_Block; +drop table if exists staging2.stg_specific_table_IHTEMT_EMT; +drop table if exists staging2.stg_process_table_IHTEMT_EMT; + +create table staging2.IHTEMT_EMT_H1_INT +(syspk serial,dummy_f text,file_syspk int,client_id int,function_id int +,make text,model text,file_mnemonic text,file_sheet_mnemonic text,c1 text,c2 text); + +create table staging2.IHTEMT_EMT_H1_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Test_Request_no text, +Sample_Receipt_Date text, +Test_report_No text, +Tractor_Model text, +Generation text, +Customer_Name text, +Test_Engineer text, +Test_Report_Date text, +No_of_Sample text, +Test_Start_Date text, +Test_End_Date text, +Tractor_Sr_No text, +Test_Standard_Refer text, +Test_Location text, +Operator_Name text, +Project_Group text, +Objective text, +Acceptance_Criteria text, +Remarks text, +Test_Purpose text, +trx_record int default 1, +block_row_number int, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTEMT_EMT_Weight_Tyre_Int +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +column13 text, +column14 text, +column15 text, +column16 text, +column17 text, +column18 text, +column19 text, +column20 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTEMT_EMT_Weight_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +Weight_Reaction text, +Total_Weight_kg text, +Front_Reaction_kg text, +Rear_Reaction_kg text, +Left_Reaction_FL_RL_kg text, +Right_reaction_FR_RR_kg text, +Front_Left_Reaction_kg text, +Front_Right_Reaction_kg text, +Rear_Left_Reaction_kg text, +Rear_Right_Reaction_kg text, +Distance_of_lifting_point_from_rear_axle_mm_d1 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTEMT_EMT_Tyre_Details_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Tyre_Details text, +Tyre_Make text, +Tyre_size text, +Ply_Rating text, +Load_Carrying_Capacity text, +Pressure_kg_cm2 text, +Dynamic_rolling_radius text, +Static_rolling_radius text, +Wheel_rim_Make_size text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTEMT_EMT_Wheel_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +Wheel_Base text, +tcd text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTEMT_EMT_Steering_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column8 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTEMT_EMT_Pedal_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column8 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTEMT_EMT_Brake_Pedal_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTEMT_EMT_Footer_Block +( +syspk serial, +client_id int, +function_id int, +dummy_f text, +file_syspk int, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +prepared_by text, +reviewed_by text, +approved_by text, +replaces text, +revision_no text, +prepared_date text, +reviewed_date text, +approved_date text, +comments text, +rev1 text, +rev2 text, +rev3 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create TABLE staging2.stg_process_table_IHTEMT_EMT ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 NULL, + create_time timestamp DEFAULT current_timestamp, + block_row_number int4 NULL, + block_tag text null +); + + + +CREATE TABLE staging2.stg_specific_table_IHTEMT_EMT ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 null, + create_time timestamp DEFAULT current_timestamp +); + + diff --git a/onetime/createtables/staging/create_tables_iht_emt_std.sql b/onetime/createtables/staging/create_tables_iht_emt_std.sql new file mode 100755 index 0000000..65f3c3c --- /dev/null +++ b/onetime/createtables/staging/create_tables_iht_emt_std.sql @@ -0,0 +1,166 @@ +drop table if exists staging2.IHTEMT_STD_RAW_Data_Block; +drop table if exists staging2.stg_specific_table_IHTEMT_STD; +drop table if exists staging2.stg_process_table_IHTEMT_STD; + +create table staging2.IHTEMT_STD_RAW_Data_Block +(syspk serial, +dummy_f text, +file_syspk int, +client_id int, +function_id int, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Time_s text, +Steering_Angle text, +Effort text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + +create TABLE staging2.stg_process_table_IHTEMT_STD ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 NULL, + create_time timestamp DEFAULT current_timestamp, + block_row_number int4 NULL, + block_tag text null +); + + + +CREATE TABLE staging2.stg_specific_table_IHTEMT_STD ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 null, + create_time timestamp DEFAULT current_timestamp +); + + diff --git a/onetime/createtables/staging/create_tables_iht_ham.sql b/onetime/createtables/staging/create_tables_iht_ham.sql new file mode 100755 index 0000000..2f74982 --- /dev/null +++ b/onetime/createtables/staging/create_tables_iht_ham.sql @@ -0,0 +1,433 @@ +drop table if exists staging2.IHTHAM_HAM_H1_Int; +drop table if exists staging2.IHTHAM_HAM_H1_block; +drop table if exists staging2.IHTHAM_HAM_Tyre_Details_Block; +drop table if exists staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int; +drop table if exists staging2.IHTHAM_HAM_Engine_RPM_Block; +drop table if exists staging2.IHTHAM_HAM_Tractor_Block; +drop table if exists staging2.IHTHAM_HAM_Weight_Block; +drop table if exists staging2.IHTHAM_HAM_Drawbar_Block; +drop table if exists staging2.IHTHAM_HAM_Atmos_Cond_Block; +drop table if exists staging2.IHTHAM_HAM_Results_Block; +drop table if exists staging2.IHTHAM_HAM_Footer_Block; +drop table if exists staging2.stg_specific_table_IHTHAM_HAM; +drop table if exists staging2.stg_process_table_IHTHAM_HAM; + +create table staging2.IHTHAM_HAM_H1_INT +(syspk serial,dummy_f text,file_syspk int,client_id int,function_id int +,make text,model text,file_mnemonic text,file_sheet_mnemonic text,c1 text,c2 text); + +create table staging2.IHTHAM_HAM_H1_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Test_Request_no text, +Sample_Receipt_Date text, +Test_report_No text, +Tractor_Model text, +Generation text, +Customer_Name text, +Test_Engineer text, +Test_Report_Date text, +No_of_Sample text, +Test_Start_Date text, +Test_End_Date text, +Tractor_Sr_No text, +Test_Location text, +Operator_Name text, +Project_Group text, +Test_Standard_Refer text, +Objective text, +Acceptance_criteria text, +Remarks text, +condition text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTHAM_HAM_Tyre_Details_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Tyre_Details text, +Tyre_Make text, +Tyre_size text, +Ply_Rating text, +Load_Carrying_Capacity text, +pressure_kg_cm2 text, +No_of_lug text, +Number_of_no_load_lug_30m text, +Lug_Height text, +Dynamic_rolling_radius text, +Wheel_rim_Make_size text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +column13 text, +column14 text, +column15 text, +column16 text, +column17 text, +column18 text, +column19 text, +column20 text, +column21 text, +column22 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTHAM_HAM_Engine_RPM_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +low_idle_declared text, +low_idle_observed text, +high_idle_declared text, +high_idle_observed text, +rated_rpm_declared text, +rated_rpm_observed text, +Engine_to_PTO_Ratio text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTHAM_HAM_Weight_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +test_condition text, +Front_weight text, +Rear_weight text, +Total_weight text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTHAM_HAM_Tractor_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +Wheel_Base_mm text, +Engine_Power_hp text, +PTO_Power_hp text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTHAM_HAM_Drawbar_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +test_condition text, +Required_pull_in_kg text, +Required_Power_in_hp text, +Actual_pull_in_kg text, +actual_power_in_hp text, +Calculated_hitch_heigh_mm text, +Actual_hitch_height_mm text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTHAM_HAM_Atmos_Cond_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +Ambient_temp_C text, +humidity text, +wind_velocity text, +date text, +start_time text, +end_time text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTHAM_HAM_Results_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column3 varchar(1024) NULL, +column4 varchar(1024) NULL, +column5 varchar(1024) NULL, +column6 varchar(1024) NULL, +column7 varchar(1024) NULL, +column8 varchar(1024) NULL, +column9 varchar(1024) NULL, +column10 varchar(1024) NULL, +column11 varchar(1024) NULL, +column12 varchar(1024) NULL, +column13 varchar(1024) NULL, +column14 varchar(1024) NULL, +column15 varchar(1024) NULL, +column16 varchar(1024) NULL, +column17 varchar(1024) NULL, +column18 varchar(1024) NULL, +column19 varchar(1024) NULL, +column20 varchar(1024) NULL, +column21 varchar(1024) NULL, +column22 varchar(1024) NULL, +column23 varchar(1024) NULL, +column24 varchar(1024) NULL, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTHAM_HAM_Footer_Block +( +syspk serial, +client_id int, +function_id int, +dummy_f text, +file_syspk int, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +prepared_by text, +reviewed_by text, +approved_by text, +replaces text, +revision_no text, +prepared_date text, +reviewed_date text, +approved_date text, +comments text, +rev1 text, +rev2 text, +rev3 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create TABLE staging2.stg_process_table_IHTHAM_HAM ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 NULL, + create_time timestamp DEFAULT current_timestamp, + block_row_number int4 NULL, + block_tag text null +); + + + +CREATE TABLE staging2.stg_specific_table_IHTHAM_HAM ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 null, + create_time timestamp DEFAULT current_timestamp +); + + diff --git a/onetime/createtables/staging/create_tables_iht_hls.sql b/onetime/createtables/staging/create_tables_iht_hls.sql new file mode 100755 index 0000000..b7460b1 --- /dev/null +++ b/onetime/createtables/staging/create_tables_iht_hls.sql @@ -0,0 +1,371 @@ +drop table if exists staging2.IHTHLS_HLS_H1_Int; +drop table if exists staging2.IHTHLS_HLS_H1_block; +drop table if exists staging2.IHTHLS_HLS_Weight_Tyre_Int; +drop table if exists staging2.IHTHLS_HLS_Weight_Block; +drop table if exists staging2.IHTHLS_HLS_Wheel_Block; +drop table if exists staging2.IHTHLS_HLS_Tyre_Details_Block; +drop table if exists staging2.IHTHLS_HLS_Numeric_Int; +drop table if exists staging2.IHTHLS_HLS_Numeric_Block; +drop table if exists staging2.IHTHLS_HLS_Footer_Block; +drop table if exists staging2.stg_specific_table_IHTHLS_HLS; +drop table if exists staging2.stg_process_table_IHTHLS_HLS; + +create table staging2.IHTHLS_HLS_H1_INT +(syspk serial,dummy_f text,file_syspk int,client_id int,function_id int +,make text,model text,file_mnemonic text,file_sheet_mnemonic text,c1 text,c2 text); + +create table staging2.IHTHLS_HLS_H1_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Test_Request_no text, +Sample_Receipt_Date text, +Test_report_No text, +Tractor_Model text, +Generation text, +Customer_Name text, +Test_Engineer text, +Test_Report_Date text, +No_of_Sample text, +Test_Start_Date text, +Test_End_Date text, +Tractor_Sr_No text, +Test_Standard_Refer text, +Test_Location text, +Operator_Name text, +Project_Group text, +Objective text, +Acceptance_Criteria text, +Remarks text, +Test_Purpose text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTHLS_HLS_Weight_Tyre_Int +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +column13 text, +column14 text, +column15 text, +column16 text, +column17 text, +column18 text, +column19 text, +column20 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTHLS_HLS_Weight_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +Weight_Reaction text, +Total_Weight_kg text, +Front_Reaction_kg text, +Rear_Reaction_kg text, +Left_Reaction_FL_RL_kg text, +Right_reaction_FR_RR_kg text, +Front_Left_Reaction_kg text, +Front_Right_Reaction_kg text, +Rear_Left_Reaction_kg text, +Rear_Right_Reaction_kg text, +Distance_of_lifting_point_from_rear_axle_mm_d1 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTHLS_HLS_Tyre_Details_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Tyre_Details text, +Tyre_Make text, +Tyre_size text, +Ply_Rating text, +Load_Carrying_Capacity text, +Pressure_kg_cm2 text, +Dynamic_rolling_radius text, +Static_rolling_radius text, +Wheel_rim_Make_size text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTHLS_HLS_Wheel_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +Wheel_Base text, +Rear_Track_Width text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTHLS_HLS_Numeric_Int +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.IHTHLS_HLS_Numeric_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +TPL_load text, +Engine_RPM text, +Lifting_time_Sec text, +Lowering_time_Sec text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + + +create table staging2.IHTHLS_HLS_Footer_Block +( +syspk serial, +client_id int, +function_id int, +dummy_f text, +file_syspk int, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +prepared_by text, +reviewed_by text, +approved_by text, +replaces text, +revision_no text, +prepared_date text, +reviewed_date text, +approved_date text, +comments text, +rev1 text, +rev2 text, +rev3 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create TABLE staging2.stg_process_table_IHTHLS_HLS ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 NULL, + create_time timestamp DEFAULT current_timestamp, + block_row_number int4 NULL, + block_tag text null +); + + + +CREATE TABLE staging2.stg_specific_table_IHTHLS_HLS ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 null, + create_time timestamp DEFAULT current_timestamp +); + + diff --git a/onetime/createtables/staging/create_tables_iht_nst.sql b/onetime/createtables/staging/create_tables_iht_nst.sql new file mode 100755 index 0000000..1f709a9 --- /dev/null +++ b/onetime/createtables/staging/create_tables_iht_nst.sql @@ -0,0 +1,420 @@ +drop table if exists staging2.IHTNST_NST_H1_Int; +drop table if exists staging2.IHTNST_NST_H1_block; +drop table if exists staging2.IHTNST_NST_Tyre_Details_Block; +drop table if exists staging2.IHTNST_NST_Engine_RPM_Atmos_Int; +drop table if exists staging2.IHTNST_NST_Engine_RPM_Block; + drop table if exists staging2.IHTNST_NST_Weight_Block; +drop table if exists staging2.IHTNST_NST_Atmos_Cond_Block; +drop table if exists staging2.IHTNST_NST_STAND_Noise_Block; +drop table if exists staging2.IHTNST_NST_OEL_Noise_Block; +drop table if exists staging2.IHTNST_NST_OEL_Noise_Load_Block; +drop table if exists staging2.IHTNST_NST_Footer_Block; +drop table if exists staging2.stg_specific_table_IHTNST_NST; +drop table if exists staging2.stg_process_table_IHTNST_NST; + +create table staging2.IHTNST_NST_H1_INT +(syspk serial,dummy_f text,file_syspk int,client_id int,function_id int +,make text,model text,file_mnemonic text,file_sheet_mnemonic text,c1 text,c2 text); + +create table staging2.IHTNST_NST_H1_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Test_Request_no text, +Sample_Receipt_Date text, +Test_report_No text, +Tractor_Model text, +Generation text, +Customer_Name text, +Test_Engineer text, +Test_Report_Date text, +No_of_Sample text, +Test_Start_Date text, +Test_End_Date text, +Tractor_Sr_No text, +Test_Facility text, +Operator_Name text, +Project_Group text, +Test_Standard_Refer text, +Objective text, +condition text, +Test_Purpose text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTNST_NST_Tyre_Details_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Tyre_Details text, +Tyre_Make text, +Tyre_size text, +Ply_Rating text, +Load_Carrying_Capacity text, +Wheel_rim_Make_size text, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTNST_NST_Engine_RPM_Atmos_Int +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTNST_NST_Engine_RPM_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +low_idle_declared text, +low_idle_observed text, +high_idle_declared text, +high_idle_observed text, +rated_rpm_declared text, +rated_rpm_observed text, +Engine_to_PTO_Ratio text, +low_idle_remark text, +high_idle_remark text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTNST_NST_Weight_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +Front_weight_declared text, +Front_weight_observed text, +Rear_weight_declared text, +Rear_weight_observed text, +Total_weight_declared text, +Total_weight_observed text, +front_weight_remark text, +rear_weight_remark text, +total_weight_remark text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTNST_NST_Atmos_Cond_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +Ambient_temp_C text, +humidity text, +Pressure_kPa text, +Background_Noise text, +wind_velocity text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTNST_NST_STAND_Noise_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column1 text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +remarks text, +acceptance_criteria text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTNST_NST_OEL_Noise_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column1 text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +remarks text, +acceptance_criteria text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTNST_NST_OEL_Noise_Load_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column1 text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +remarks text, +acceptance_criteria text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTNST_NST_Footer_Block +( +syspk serial, +client_id int, +function_id int, +dummy_f text, +file_syspk int, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +prepared_by text, +reviewed_by text, +approved_by text, +replaces text, +revision_no text, +prepared_date text, +reviewed_date text, +approved_date text, +comments text, +rev1 text, +rev2 text, +rev3 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create TABLE staging2.stg_process_table_IHTNST_NST ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 NULL, + create_time timestamp DEFAULT current_timestamp, + block_row_number int4 NULL, + block_tag text null +); + + + +CREATE TABLE staging2.stg_specific_table_IHTNST_NST ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 null, + create_time timestamp DEFAULT current_timestamp +); + + diff --git a/onetime/createtables/staging/create_tables_iht_sll.sql b/onetime/createtables/staging/create_tables_iht_sll.sql new file mode 100755 index 0000000..db22729 --- /dev/null +++ b/onetime/createtables/staging/create_tables_iht_sll.sql @@ -0,0 +1,398 @@ +drop table if exists staging2.IHTSLL_SLL_H1_Int; +drop table if exists staging2.IHTSLL_SLL_H1_block; +drop table if exists staging2.IHTSLL_SLL_Weight_Tyre_Int; +drop table if exists staging2.IHTSLL_SLL_Weight_Block; +drop table if exists staging2.IHTSLL_SLL_Wheel_Block; +drop table if exists staging2.IHTSLL_SLL_Tyre_Details_Block; +drop table if exists staging2.IHTSLL_SLL_Forward_Block; +drop table if exists staging2.IHTSLL_SLL_Reverse_Block; +drop table if exists staging2.IHTSLL_SLL_Lead_Lag_Block; +drop table if exists staging2.IHTSLL_SLL_Footer_Block; +drop table if exists staging2.stg_specific_table_IHTSLL_SLL; +drop table if exists staging2.stg_process_table_IHTSLL_SLL; + +create table staging2.IHTSLL_SLL_H1_INT +(syspk serial,dummy_f text,file_syspk int,client_id int,function_id int +,make text,model text,file_mnemonic text,file_sheet_mnemonic text,c1 text,c2 text); + +create table staging2.IHTSLL_SLL_H1_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Test_Request_no text, +Sample_Receipt_Date text, +Test_report_No text, +Tractor_Model text, +Generation text, +Customer_Name text, +Test_Engineer text, +Test_Report_Date text, +No_of_Sample text, +Test_Start_Date text, +Test_End_Date text, +Tractor_Sr_No text, +Test_Standard_Refer text, +Test_Location text, +Operator_Name text, +Project_Group text, +Objective text, +Acceptance_Criteria text, +Remarks text, +Test_purpose text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTSLL_SLL_Weight_Tyre_Int +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +column13 text, +column14 text, +column15 text, +column16 text, +column17 text, +column18 text, +column19 text, +column20 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTSLL_SLL_Weight_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +Weight_Reaction text, +Total_Weight_kg text, +Front_Reaction_kg text, +Rear_Reaction_kg text, +Left_Reaction_FL_RL_kg text, +Right_reaction_FR_RR_kg text, +Front_Left_Reaction_kg text, +Front_Right_Reaction_kg text, +Rear_Left_Reaction_kg text, +Rear_Right_Reaction_kg text, +Distance_of_lifting_point_from_rear_axle_mm_d1 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTSLL_SLL_Tyre_Details_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Tyre_Details text, +Tyre_Make text, +Tyre_size text, +Ply_Rating text, +Load_Carrying_Capacity text, +Pressure_kg_cm2 text, +Dynamic_rolling_radius text, +Static_rolling_radius text, +Wheel_rim_Make_size text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTSLL_SLL_Wheel_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +Wheel_Base text, +Rear_Track_Width text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTSLL_SLL_Forward_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTSLL_SLL_Reverse_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTSLL_SLL_Lead_Lag_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTSLL_SLL_Footer_Block +( +syspk serial, +client_id int, +function_id int, +dummy_f text, +file_syspk int, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +prepared_by text, +reviewed_by text, +approved_by text, +replaces text, +revision_no text, +prepared_date text, +reviewed_date text, +approved_date text, +comments text, +rev1 text, +rev2 text, +rev3 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create TABLE staging2.stg_process_table_IHTSLL_SLL ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 NULL, + create_time timestamp DEFAULT current_timestamp, + block_row_number int4 NULL, + block_tag text null +); + + + +CREATE TABLE staging2.stg_specific_table_IHTSLL_SLL ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 null, + create_time timestamp DEFAULT current_timestamp +); + + diff --git a/onetime/createtables/staging/create_tables_ihtbt30_bt30.sql b/onetime/createtables/staging/create_tables_ihtbt30_bt30.sql new file mode 100755 index 0000000..01d257b --- /dev/null +++ b/onetime/createtables/staging/create_tables_ihtbt30_bt30.sql @@ -0,0 +1,438 @@ +drop table if exists staging2.IHTBT30_BT30_H1_INT; +drop table if exists staging2.IHTBT30_BT30_H1_block; +drop table if exists staging2.IHTBT30_BT30_Weight_Tyre_Int; +drop table if exists staging2.IHTBT30_BT30_Weight_Block; +drop table if exists staging2.IHTBT30_BT30_Tyre_Details_Block; +drop table if exists staging2.IHTBT30_BT30_Test_Res_1_Block; +drop table if exists staging2.IHTBT30_BT30_Test_Res_2_Block; +drop table if exists staging2.IHTBT30_BT30_Test_Res_3_Block; +drop table if exists staging2.IHTBT30_BT30_Test_Res_4_Block; +drop table if exists staging2.IHTBT30_BT30_Footer_Block; +drop table if exists staging2.IHTBT30_BT30_Test_Condition_Block; +drop table if exists staging2.stg_specific_table_IHTBT30_BT30; +drop table if exists staging2.stg_process_table_IHTBT30_BT30; + +create table staging2.IHTBT30_BT30_H1_INT +(syspk serial,dummy_f text,file_syspk int,client_id int,function_id int +,make text,model text,file_mnemonic text,file_sheet_mnemonic text,c1 text,c2 text); + +create table staging2.IHTBT30_BT30_H1_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Test_Request_no text, +Sample_Receipt_Date text, +Test_report_No text, +Tractor_Model text, +Generation text, +Customer_Name text, +Test_Engineer text, +Test_Report_Date text, +Test_Location text, +No_of_Sample text, +Test_Start_Date text, +Test_End_Date text, +Tractor_Sr_No text, +Test_Standard_Refer text, +Domestic_Export text, +Operator_Name text, +Project_Group text, +Platform text, +Objective text, +Test_Standard text, +Test_Standard_id text, +Test_Standard_ref text, +Remarks text, +Observations text, +Acceptance_Criteria text, +condition text, +Test_Purpose text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBT30_BT30_Weight_Tyre_Int +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +column13 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBT30_BT30_Weight_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +test_condition text, +Front text, +Rear text, +Total text, +status text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBT30_BT30_Tyre_Details_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Tyre_Details text, +Pressure_kg_cm2 text, +tyre_use_type text, +Tyre_Make text, +Tyre_size text, +Ply_Rating text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBT30_BT30_Test_Condition_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +condition text, +date text, +location text, +time text, +mode text, +Wind_Velocity_Km_hr text, +Ambient_Temperature_C text, +Humidity_RH text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBT30_BT30_Test_Res_1_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +column13 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBT30_BT30_Test_Res_2_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +column13 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBT30_BT30_Test_Res_3_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +column13 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBT30_BT30_Test_Res_4_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +column13 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBT30_BT30_Footer_Block +( +syspk serial, +client_id int, +function_id int, +dummy_f text, +file_syspk int, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +prepared_by text, +reviewed_by text, +approved_by text, +replaces text, +revision_no text, +prepared_date text, +reviewed_date text, +approved_date text, +comments text, +rev1 text, +rev2 text, +rev3 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create TABLE staging2.stg_process_table_IHTBT30_BT30 ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 NULL, + create_time timestamp DEFAULT current_timestamp, + block_row_number int4 NULL, + block_tag text null +); + + + +CREATE TABLE staging2.stg_specific_table_IHTBT30_BT30 ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 null, + create_time timestamp DEFAULT current_timestamp +); + + diff --git a/onetime/createtables/staging/create_tables_ihtbt50_bt50.sql b/onetime/createtables/staging/create_tables_ihtbt50_bt50.sql new file mode 100755 index 0000000..1b55b29 --- /dev/null +++ b/onetime/createtables/staging/create_tables_ihtbt50_bt50.sql @@ -0,0 +1,438 @@ +drop table if exists staging2.IHTBT50_BT50_H1_INT; +drop table if exists staging2.IHTBT50_BT50_H1_block; +drop table if exists staging2.IHTBT50_BT50_Weight_Tyre_Int; +drop table if exists staging2.IHTBT50_BT50_Weight_Block; +drop table if exists staging2.IHTBT50_BT50_Tyre_Details_Block; +drop table if exists staging2.IHTBT50_BT50_Test_Res_1_Block; +drop table if exists staging2.IHTBT50_BT50_Test_Res_2_Block; +drop table if exists staging2.IHTBT50_BT50_Test_Res_3_Block; +drop table if exists staging2.IHTBT50_BT50_Test_Res_4_Block; +drop table if exists staging2.IHTBT50_BT50_Footer_Block; +drop table if exists staging2.IHTBT50_BT50_Test_Condition_Block; +drop table if exists staging2.stg_specific_table_IHTBT50_BT50; +drop table if exists staging2.stg_process_table_IHTBT50_BT50; + +create table staging2.IHTBT50_BT50_H1_INT +(syspk serial,dummy_f text,file_syspk int,client_id int,function_id int +,make text,model text,file_mnemonic text,file_sheet_mnemonic text,c1 text,c2 text); + +create table staging2.IHTBT50_BT50_H1_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Test_Request_no text, +Sample_Receipt_Date text, +Test_report_No text, +Tractor_Model text, +Generation text, +Customer_Name text, +Test_Engineer text, +Test_Report_Date text, +Test_Location text, +No_of_Sample text, +Test_Start_Date text, +Test_End_Date text, +Tractor_Sr_No text, +Test_Standard_Refer text, +Domestic_Export text, +Operator_Name text, +Project_Group text, +Platform text, +Objective text, +Test_Standard text, +Test_Standard_id text, +Test_Standard_ref text, +Remarks text, +Observations text, +Acceptance_Criteria text, +condition text, +Test_Purpose text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBT50_BT50_Weight_Tyre_Int +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +column13 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBT50_BT50_Weight_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +test_condition text, +Front text, +Rear text, +Total text, +status text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBT50_BT50_Tyre_Details_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Tyre_Details text, +Pressure_kg_cm2 text, +tyre_use_type text, +Tyre_Make text, +Tyre_size text, +Ply_Rating text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBT50_BT50_Test_Condition_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +condition text, +date text, +location text, +time text, +mode text, +Wind_Velocity_Km_hr text, +Ambient_Temperature_C text, +Humidity_RH text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBT50_BT50_Test_Res_1_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +column13 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBT50_BT50_Test_Res_2_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +column13 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBT50_BT50_Test_Res_3_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +column13 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBT50_BT50_Test_Res_4_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +column13 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBT50_BT50_Footer_Block +( +syspk serial, +client_id int, +function_id int, +dummy_f text, +file_syspk int, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +prepared_by text, +reviewed_by text, +approved_by text, +replaces text, +revision_no text, +prepared_date text, +reviewed_date text, +approved_date text, +comments text, +rev1 text, +rev2 text, +rev3 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create TABLE staging2.stg_process_table_IHTBT50_BT50 ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 NULL, + create_time timestamp DEFAULT current_timestamp, + block_row_number int4 NULL, + block_tag text null +); + + + +CREATE TABLE staging2.stg_specific_table_IHTBT50_BT50 ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 null, + create_time timestamp DEFAULT current_timestamp +); + + diff --git a/onetime/createtables/staging/create_tables_ihtbtd_btd.sql b/onetime/createtables/staging/create_tables_ihtbtd_btd.sql new file mode 100755 index 0000000..4b22a95 --- /dev/null +++ b/onetime/createtables/staging/create_tables_ihtbtd_btd.sql @@ -0,0 +1,496 @@ +drop table if exists staging2.IHTBTD_BTD_H1_Int; +drop table if exists staging2.IHTBTD_BTD_H1_block; +drop table if exists staging2.IHTBTD_BTD_Weight_Tyre_Int; +drop table if exists staging2.IHTBTD_BTD_Weight_Block; +drop table if exists staging2.IHTBTD_BTD_Tyre_Details_Block; +drop table if exists staging2.IHTBTD_BTD_Test_Res_1_Block; +drop table if exists staging2.IHTBTD_BTD_Test_Res_2_Block; +drop table if exists staging2.IHTBTD_BTD_Test_Res_3_Block; +drop table if exists staging2.IHTBTD_BTD_Test_Res_4_Block; +drop table if exists staging2.IHTBTD_BTD_Test_Res_5_Block; +drop table if exists staging2.IHTBTD_BTD_Test_Res_6_Block; +drop table if exists staging2.IHTBTD_BTD_Footer_Block; +drop table if exists staging2.IHTBTD_BTD_Test_Condition_Block; +drop table if exists staging2.stg_specific_table_IHTBTD_BTD; +drop table if exists staging2.stg_process_table_IHTBTD_BTD; + +create table staging2.IHTBTD_BTD_H1_INT +(syspk serial,dummy_f text,file_syspk int,client_id int,function_id int +,make text,model text,file_mnemonic text,file_sheet_mnemonic text,c1 text,c2 text); + +create table staging2.IHTBTD_BTD_H1_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Test_Request_no text, +Sample_Receipt_Date text, +Test_report_No text, +Tractor_Model text, +Generation text, +Customer_Name text, +Test_Engineer text, +Test_Report_Date text, +Test_Location text, +No_of_Sample text, +Test_Start_Date text, +Test_End_Date text, +Tractor_Sr_No text, +Test_Standard_Refer text, +Domestic_Export text, +Operator_Name text, +Project_Group text, +Platform text, +Objective text, +Test_Standard text, +Test_Standard_id text, +Test_Standard_ref text, +Remarks text, +Observations text, +Acceptance_Criteria text, +condition text, +Test_Purpose text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBTD_BTD_Weight_Tyre_Int +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +column13 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBTD_BTD_Weight_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +test_condition text, +Front text, +Rear text, +Total text, +status text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBTD_BTD_Tyre_Details_Block +( +syspk serial, +client_id int, +function_id int, +file_syspk int, +dummy_f text, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +Tyre_Details text, +Pressure_kg_cm2 text, +tyre_use_type text, +Tyre_Make text, +Tyre_size text, +Ply_Rating text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBTD_BTD_Test_Condition_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +condition text, +date text, +location text, +time text, +mode text, +Wind_Velocity_Km_hr text, +Ambient_Temperature_C text, +Humidity_RH text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBTD_BTD_Test_Res_1_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +column13 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBTD_BTD_Test_Res_2_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +column13 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBTD_BTD_Test_Res_3_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +column13 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBTD_BTD_Test_Res_4_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +column13 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBTD_BTD_Test_Res_5_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +column13 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBTD_BTD_Test_Res_6_Block +( +syspk serial, +file_syspk int, +client_id int, +function_id int, +file_mnemonic text, +file_sheet_mnemonic text, +dummy_f text, +make text, +model text, +column2 text, +column3 text, +column4 text, +column5 text, +column6 text, +column7 text, +column8 text, +column9 text, +column10 text, +column11 text, +column12 text, +column13 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create table staging2.IHTBTD_BTD_Footer_Block +( +syspk serial, +client_id int, +function_id int, +dummy_f text, +file_syspk int, +make text, +model text, +file_mnemonic text, +file_sheet_mnemonic text, +prepared_by text, +reviewed_by text, +approved_by text, +replaces text, +revision_no text, +prepared_date text, +reviewed_date text, +approved_date text, +comments text, +rev1 text, +rev2 text, +rev3 text, +block_row_number int, +trx_record int default 1, +create_time timestamp DEFAULT current_timestamp +); + +create TABLE staging2.stg_process_table_IHTBTD_BTD ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 NULL, + create_time timestamp DEFAULT current_timestamp, + block_row_number int4 NULL, + block_tag text null +); + + + +CREATE TABLE staging2.stg_specific_table_IHTBTD_BTD ( + generic_syspk int, + file_syspk bigint, + file_name varchar(1024) NULL, + file_date date NULL, + file_mnemonic varchar(1024) NULL, + sheet_number int4 NULL, + sheet_name varchar(1024) NULL, + sheet_format text, + file_sheet_mnemonic varchar(1024) NULL, + row_number int4 NULL, + file_creation_date timestamp NULL, + column1 varchar(1024) NULL, + column2 varchar(1024) NULL, + column3 varchar(1024) NULL, + column4 varchar(1024) NULL, + column5 varchar(1024) NULL, + column6 varchar(1024) NULL, + column7 varchar(1024) NULL, + column8 varchar(1024) NULL, + column9 varchar(1024) NULL, + column10 varchar(1024) NULL, + column11 varchar(1024) NULL, + column12 varchar(1024) NULL, + column13 varchar(1024) NULL, + column14 varchar(1024) NULL, + column15 varchar(1024) NULL, + column16 varchar(1024) NULL, + column17 varchar(1024) NULL, + column18 varchar(1024) NULL, + column19 varchar(1024) NULL, + column20 varchar(1024) NULL, + column21 varchar(1024) NULL, + column22 varchar(1024) NULL, + column23 varchar(1024) NULL, + column24 varchar(1024) NULL, + column25 varchar(1024) NULL, + column26 varchar(1024) NULL, + column27 varchar(1024) NULL, + column28 varchar(1024) NULL, + column29 varchar(1024) NULL, + column30 varchar(1024) NULL, + column31 varchar(1024) NULL, + column32 varchar(1024) NULL, + column33 varchar(1024) NULL, + column34 varchar(1024) NULL, + column35 varchar(1024) NULL, + column36 varchar(1024) NULL, + column37 varchar(1024) NULL, + column38 varchar(1024) NULL, + column39 varchar(1024) NULL, + column40 varchar(1024) NULL, + column41 varchar(1024) NULL, + column42 varchar(1024) NULL, + column43 varchar(1024) NULL, + column44 varchar(1024) NULL, + column45 varchar(1024) NULL, + column46 varchar(1024) NULL, + column47 varchar(1024) NULL, + column48 varchar(1024) NULL, + column49 varchar(1024) NULL, + column50 varchar(1024) NULL, + column51 varchar(1024) NULL, + column52 varchar(1024) NULL, + column53 varchar(1024) NULL, + is_rownumber_fetched int4 null, + create_time timestamp DEFAULT current_timestamp +); + + diff --git a/onetime/dataloadfunctions/Drawbar/DBOECD_TEST_ods.sql b/onetime/dataloadfunctions/Drawbar/DBOECD_TEST_ods.sql new file mode 100755 index 0000000..1be40bd --- /dev/null +++ b/onetime/dataloadfunctions/Drawbar/DBOECD_TEST_ods.sql @@ -0,0 +1,927 @@ +--select transactional.fn_dboecd_test_trx(); + +drop function if exists staging2.fn_dboecd_test_trx; +CREATE OR REPLACE FUNCTION staging2.fn_dboecd_test_trx(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __test_instance_tractor_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + begin + +/*********************************************************** +Function Name:fn_dboecd_test_trx +Function Desc: This function populates data into trx block +File Format: DBOECD +Sheet Format: DBOECD_TEST +Creation Date: March 27 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_dboecd_test_trx() +***************************************************************/ +SET search_path TO staging2; + +insert into transactional.test_instance +( +client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +job_order_no, +sample_receipt_date, +test_report_no, +generation, +customer_name, +test_engineer, +test_report_date, +no_of_sample, +test_start_date, +test_end_date, +tractor_sr_no, +test_standard_ref, +test_location_name, +test_operator, +project_group, +acceptance_criteria, +objective_of_test, +file_mnemonic, +file_sheet_mnemonic, +date_of_test +) +select +client_id, +function_id, +file_syspk, +make, +model, +test_request_no, +date '1899-12-30' + sample_receipt_date::int * interval '1' day as sample_receipt_date , +test_report_no, +generation, +customer_name, +test_engineer, +date '1899-12-30' + test_report_date::int * interval '1' day as test_report_date , +no_of_sample, +date '1899-12-30' + test_start_date::int* interval '1' day as test_start_date , +date '1899-12-30' + test_end_date::int* interval '1' day as test_end_date , +tractor_sr_no, +test_standard_refer, +test_location, +operator_name, +project_group, +objective, +acceptance_criteria, +file_mnemonic, +file_sheet_mnemonic, +current_date +from +staging2.dboecd_test_h1_block; + +update transactional.test_instance a +set test_condition=b.c2 +from staging2.dboecd_test_test_condition_block b +where a.file_syspk=b.file_syspk; + +update transactional.test_instance a +set remarks = b.remark +from staging2.dboecd_test_drawbar_performance_fuel_consumption_block b +where a.file_syspk=b.file_syspk; + +select file_syspk into __file_syspk from staging2.dboecd_test_h1_block; +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; + + + +insert into transactional.test_instance_engine_info +(client_id, +function_id, +file_syspk, +tractor_model, +tractor_make, +low_idle_declared, +low_idle_observed, +high_idle_declared, +high_idle_observed, +file_mnemonic, +file_sheet_mnemonic +) +select client_id, +function_id, +file_syspk, +make,model, +low_idle_declared, +low_idle_observed::int, +high_idle_declared, +high_idle_observed::int, +file_mnemonic, +file_sheet_mnemonic +from staging2.DBOECD_test_engine_RPM_RPM_block; + + +update transactional.test_instance_engine_info a +set rated_rpm=b.rated_speed::int ,engine_to_pto_ratio_540_pto=b.engine_to_pto_ratio::numeric::int,engine_power_hp = b.engine_power_hp::int, +pto_power_hp = b.pto_power_hp::numeric +from +staging2.dboecd_test_engine_rpm_engine_to_pto_block b +where a.file_syspk=b.file_syspk; + +update transactional.test_instance_engine_info a +set engine_cylinder_stroke_mm=b.stroke::int,engine_cylinder_bore_mm=b.bore::numeric,engine_cylinder_no=b.number::int,engine_cylinder_capacity_ltr=b.capacity::int +from staging2.dboecd_test_tractor_specifications_cylinders_block b +where b.file_syspk=b.file_syspk; + + +update transactional.test_instance_engine_info a +set engine_type=b."type" ,engine_serial_no=b.serial_no,engine_make=b.make_in_block ,engine_model = b.model_in_block ,rated_rpm=b.rated_speed::int +from staging2.dboecd_test_tractor_specifications_engine_details_block b +where b.file_syspk=b.file_syspk; + + +insert into transactional.test_instance_tractor_info +( +client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +wheel_base_mm, +tractor_engine_hp, +pto_power_hp, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +file_syspk, +make, +model, +wheel_base_mm::int, +engine_power_hp::int, +pto_power_hp::numeric, +file_mnemonic, +file_sheet_mnemonic +from staging2.dboecd_test_engine_rpm_engine_to_pto_block; + +update transactional.test_instance_tractor_info a +set +steering_type=b.steering_type, +transmission_type=clutch_type, +transmission_disc_diam=diameter_of_disc_mm +from staging2.dboecd_test_transmission_clutch_block b +where a.file_syspk=b.file_syspk; + + +insert into transactional.test_instance_drawbar_info +( +client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +drawbar_type, +required_pull_in_kg, +actual_pull_in_kg, +required_power_in_hp, +actual_power_in_hp, +calculated_hitch_height_mm, +actual_hitch_height_mm, +file_mnemonic, +file_sheet_mnemonic +) + +select +client_id, +function_id, +file_syspk, +make, +model, +pull_type, +required_pull_in_kg::numeric , +actual_pull_in_kg::numeric , +required_power_in_hp::numeric, +actual_power_in_hp::numeric , +calculated_hitch_height_mm::numeric, +actual_hitch_height_mm::numeric, +file_mnemonic, +file_sheet_mnemonic +from + staging2.dboecd_test_engine_rpm_required_pull_block; + +update transactional.test_instance_drawbar_info a +set weight_front_kg = front::int , +weight_rear_kg = rear::int , +weight_total_kg = total::int +from staging2.dboecd_test_engine_rpm_weight_block b +where b.weight_kg='Unballast' +and a.drawbar_type='UB' +and a.file_syspk=b.file_syspk; + + +update transactional.test_instance_drawbar_info a +set weight_front_kg = front::int , +weight_rear_kg = rear::int , +weight_total_kg = total::int +from staging2.dboecd_test_engine_rpm_weight_block b +where b.weight_kg='Ballast' +and a.drawbar_type='B' +and a.file_syspk=b.file_syspk; + +update transactional.test_instance_drawbar_info a +set test_condition=b.test_condition, +drawbar_type_info=b.type, +height_above_ground_max_mm=b.height_above_ground_max_mm::numeric, +height_above_ground_min_mm=b.height_above_ground_min_mm::numeric, +position_related_to_pto=b.position_related_to_pto, +wheel_base=b.wheel_base +from staging2.dboecd_test_transmission_drawbar_block b +where a.drawbar_type=b.test_condition +and a.file_syspk=b.file_syspk; + +update transactional.test_instance_drawbar_info set drawbar_type_name='Un-Ballasted' where drawbar_type='UB'; +update transactional.test_instance_drawbar_info set drawbar_type_name='Ballasted' where drawbar_type='B'; + +insert into transactional.test_instance_tyre_info +( +client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +tyre_type, +tyre_make, +tyre_size, +tyre_ply_rating, +tyre_load_carrying_capacity, +tyre_pressure_kg_per_cm2, +tyre_number_of_lug, +tyre_number_of_no_load_lug_30m, +tyre_lug_height, +tyre_dynamic_rolling_radius_mm, +tyre_wheel_rim_make_and_size, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +file_syspk, +make, +model, +dummy_f, +tyre_make, +size, +ply_rating::int, +load_carrying_capacity_in_kg, +pressure_kg_cm2::numeric, +number_of_lug::int, +number_of_no_load_lug_30m::int, +lug_height::numeric, +dynamic_rolling_radius_mm::numeric, +wheel_rim_make_size, +file_mnemonic, +file_sheet_mnemonic + from staging2.DBOECD_test_engine_RPM_tyre_details_block ; + + insert into transactional.drawbar_perf_results_summary + ( + client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +gear_number_and_range, +travel_speed_km_per_hr, +drawbar_power_kw, +drawbar_power_hp, +drawbar_pull_kgf, +drawbar_pull_kn, +engine_speed_min_1, +fan_speed_min_1, +wheel_slip_pct_front, +no_of_load_lugs_front, +wheel_slip_pct_rear, +fuel_consumption_l_per_h, +fuel_consumption_kg_per_kwh, +fuel_consumption_g_per_kwh, +fuel_consumption_kwh_per_l, +temp_engine_oil_c, +temp_trans_oil_c, +temp_coolant_c, +temp_fuel_in_c, +temp_fuel_out_c, +atm_conditions_rh_pct, +atm_conditions_temp_c, +atm_conditions_pressure_kpa, +file_mnemonic, +file_sheet_mnemonic +) + select + client_id, +function_id, +file_syspk, +make, +model, + c1, + c2::numeric, +c3::numeric, +c4::numeric, +c5::int, +c6::numeric, +c7::int, +c8::int, +c9::numeric, +c10::numeric, +c11::numeric, +c12::numeric, +c13::numeric, +c14::numeric, +c15::numeric, +c16::int, +c17::int, +c18::int, +c19::int, +c20::int, +c21::numeric, +c22::numeric, +c23::numeric, +file_mnemonic, +file_sheet_mnemonic + from staging2.dboecd_test_drawbar_performance_selected_summary_block; + +insert into transactional.drawbar_perf_oecd_results + ( + client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +srl_no, +test_condition , +gear_number_and_range, +travel_speed_km_per_hr, +drawbar_power_kw, +drawbar_power_hp, +drawbar_pull_kgf, +drawbar_pull_kn, +engine_speed_min_1, +fan_speed_min_1, +wheel_slip_pct_front, +no_of_load_lugs_front, +wheel_slip_pct_rear, +fuel_consumption_l_per_h, +fuel_consumption_kg_per_kwh, +fuel_consumption_g_per_kwh, +fuel_consumption_kwh_per_l, +temp_engine_oil_c, +temp_trans_oil_c, +temp_coolant_c, +temp_fuel_in_c, +temp_fuel_out_c, +atm_conditions_rh_pct, +atm_conditions_temp_c, +atm_conditions_pressure_kpa, +file_mnemonic, +file_sheet_mnemonic +) + select + client_id, +function_id, +file_syspk, +make, +model, +c1_1, + c2_1, + c1, + c2::numeric, +c3::numeric, +c4::numeric, +c5::int, +c6::numeric, +c7::int, +c8::int, +c9::numeric, +c10::numeric, +c11::numeric, +c12::numeric, +c13::numeric, +c14::numeric, +c15::numeric, +c16::int, +c17::int, +c18::int, +c19::int, +c20::int, +c21::numeric, +c22::numeric, +c23::numeric, +file_mnemonic, +file_sheet_mnemonic +from staging2.dboecd_test_drawbar_performance_fuel_consumption_block; + + +insert into transactional.drawbar_perf_results + ( client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +gear_number_and_range, +travel_speed_km_per_hr, +drawbar_power_kw, +drawbar_power_hp, +drawbar_pull_kgf, +drawbar_pull_kn, +engine_speed_min_1, +fan_speed_min_1, +wheel_slip_pct_front, +no_of_load_lugs_front, +wheel_slip_pct_rear, +fuel_consumption_l_per_h, +fuel_consumption_kg_per_kwh, +fuel_consumption_g_per_kwh, +fuel_consumption_kwh_per_l, +temp_engine_oil_c, +temp_trans_oil_c, +temp_coolant_c, +temp_fuel_in_c, +temp_fuel_out_c, +atm_conditions_rh_pct, +atm_conditions_temp_c, +atm_conditions_pressure_kpa, +file_mnemonic, +file_sheet_mnemonic +) + select + client_id, +function_id, +file_syspk, +make, +model, + c1, + c2::numeric, +c3::numeric, +c4::numeric, +c5::int, +c6::numeric, +c7::int, +c8::int, +c9::numeric, +c10::numeric, +c11::numeric, +c12::numeric, +c13::numeric, +c14::numeric, +c15::numeric, +c16::int, +c17::int, +c18::int, +c19::int, +c20::int, +c21::numeric, +c22::numeric, +c23::numeric, +file_mnemonic, +file_sheet_mnemonic + from staging2.dboecd_test_drawbar_performance_gear_performance_block; + + + insert into transactional.test_instance_equipment_info + (client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +srl_no, +instrument_name, +instrument_serial_no, +calibration_due_date, +file_mnemonic, +file_sheet_mnemonic ) +select + client_id, +function_id, +file_syspk, +make, +model, + s_no::int, + instruments, + instruments_no, + date '1899-12-30' + cali_due_date::int * interval '1' day as cali_due_date, + file_mnemonic, +file_sheet_mnemonic + from staging2.DBOECD_test_test_equipment_used_block; + +insert into transactional.test_instance_measurement_uncertainty +( +client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +load_cell, +rpm_meter, +speed, +fuel_flow_meter, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +file_syspk, +make, +model, +load_cell, +rpm_meter, +speed, +fuel_flow_meter, +file_mnemonic, +file_sheet_mnemonic +from +staging2.dboecd_test_measurement_uncertainty_block; + +insert into transactional.test_instance_tractor_info_misc +( +client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +capacity_of_fuel_tank_ltr, +make_type_and_model_of_injection_pump, +manufacturers_production_setting, +make_type_and_model_of_injectors, +make_type_and_model_of_magneto_coil_and_distributor, +make_type_and_model_of_carburetor, +ignition_or_injection_timing, +file_mnemonic, +file_sheet_mnemonic +) +select + client_id, +function_id, +file_syspk, +make, +model, +regexp_replace(capacity_of_fuel_tank_lit,'[^0-9]', '', 'g')::int, +make_type_and_model_of_injection_pump, +manufacturer_production_setting, +make_type_and_model_of_injectors, +make_type_and_model_of_magneto_coil_and_distributor, +make_type_and_model_of_carburetor, +ignition_or_injection_timing_manual_or_automatic, +file_mnemonic, +file_sheet_mnemonic +from +staging2.dboecd_test_tractor_specifications_fuel_and_injection_block; + + +update transactional.test_instance_tractor_info_misc a +set aircleaner_make_model=b.make_and_model +from staging2.dboecd_test_tractor_specifications_cleaner_block b +where b.cleaner_type='Air cleaner' +and a.file_syspk=b.file_syspk; + + +update transactional.test_instance_tractor_info_misc a +set aircleaner_type=b.type +from staging2.dboecd_test_tractor_specifications_cleaner_block b +where cleaner_type='Air cleaner' +and a.file_syspk=b.file_syspk; + + +update transactional.test_instance_tractor_info_misc a +set precleaner_make_model=b.make_and_model +from staging2.dboecd_test_tractor_specifications_cleaner_block b +where cleaner_type='Precleaner (if fitted)' +and a.file_syspk=b.file_syspk; + +update transactional.test_instance_tractor_info_misc a +set precleaner_type=b.type +from staging2.dboecd_test_tractor_specifications_cleaner_block b +where cleaner_type='Precleaner (if fitted)' +and a.file_syspk=b.file_syspk; + + +update staging2.dboecd_test_transmission_speed_chart_block a +set tyre_condition=b.descr +from staging2.dboecd_test_transmission_speed_chart_desc_block b +where a.file_syspk=b.file_syspk; + + +insert into transactional.test_instance_gear_speed_chart +( +client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +forward_reverse, +gear, +speed_kmph, +tyre_condition, +file_mnemonic, +file_sheet_mnemonic +) +select + client_id, +function_id, +file_syspk, +make, +model, + 'forward', + gear, + cast(coalesce(nullif(forward,''),'0') as numeric), + tyre_condition, + file_mnemonic, +file_sheet_mnemonic + from + staging2.dboecd_test_transmission_speed_chart_block; + + + insert into transactional.test_instance_gear_speed_chart +( +client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +forward_reverse, +gear, +speed_kmph, +tyre_condition, +file_mnemonic, +file_sheet_mnemonic +) +select + client_id, +function_id, +file_syspk, +make, +model, + 'reverse', + gear, + cast(coalesce(nullif(reverse,''),'0') as numeric), + tyre_condition, + file_mnemonic, +file_sheet_mnemonic + from + staging2.dboecd_test_transmission_speed_chart_block; + + + +insert into transactional.Test_instance_wheels_info +(client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +steered_driving_wheel, +location_of_driving_wheel, +make_of_tyres, +wheel_types, +wheel_size, +maximum_permissible_load_kg, +ply_rating, +track_width_max_mm, +track_width_min_mm, +inflation_pressure_kg_per_cm2, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +file_syspk, +make, +model, +dummy_f, +location_of_driving_wheel, +make_of_tyres, +types, +size, +maximum_permissible_load_kg::int, +ply_rating::int, +track_width_max_mm::int, +track_width_min_mm::int, +inflation_pressure_kg_cm2::numeric, +file_mnemonic, +file_sheet_mnemonic +from staging2.dboecd_test_transmission_wheels_block; + + +insert into transactional.Test_instance_fuel_lubricant_info +( +client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +trade_name, +fuel_lubricant_type, +octane_per_cetane_number, +viscocity, +density_at_15c, +file_mnemonic, +file_sheet_mnemonic +) +select + client_id, +function_id, +file_syspk, +make, +model, + trade_name, + type, + octane_cetane_number::numeric, + viscosity, +density_at_15c, +file_mnemonic, +file_sheet_mnemonic +from + staging2.dboecd_test_transmission_fuel_lubricant_block ; + + +insert into transactional.drawbar_perf_observations +( +client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +test_parameter , +acceptance_criteria , +observation , +remarks, +file_mnemonic, +file_sheet_mnemonic +) +select + client_id, +function_id, +file_syspk, +make, +model, + parameter, + acceptance_criteria , + observations, + remarks, + file_mnemonic, +file_sheet_mnemonic +from staging2.dboecd_test_remarks_block; + +update transactional.test_instance a +set +report_prepared_by=b.prepared_by, +--report_reviewed_by=b.reviewed_by, +report_approved_by=b.approved_by, +report_template_replaces=b.replaces, +report_template_rev_no=b.revision_no, +report_template_rev_Date=b.rev3, +report_template_no=b.rev1, +report_title=b.comments +from staging2.dboecd_test_remarks_footer_block b +where a.file_syspk=b.file_syspk; + + + +update transactional.test_instance_engine_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_drawbar_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.test_instance_tyre_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.drawbar_perf_results_summary +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.drawbar_perf_results +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.drawbar_perf_observations +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.drawbar_perf_oecd_results +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_equipment_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.test_instance_measurement_uncertainty +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.test_instance_tractor_info_misc +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.test_instance_gear_speed_chart +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.Test_instance_wheels_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.Test_instance_fuel_lubricant_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + + +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk; + +update transactional.drawbar_perf_observations +set test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.drawbar_perf_results_summary +set test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.drawbar_perf_oecd_results +set test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + + +update transactional.drawbar_perf_results +set test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + + + +update transactional.test_instance_engine_info +set test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_drawbar_info +set test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.test_instance_tyre_info +set test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_equipment_info +set test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.test_instance_measurement_uncertainty +set test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.test_instance_tractor_info_misc +set test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.test_instance_gear_speed_chart +set test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.Test_instance_wheels_info +set test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.Test_instance_fuel_lubricant_info +set test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_dboecd_test_trx', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; diff --git a/onetime/dataloadfunctions/Drawbar/DBOECD_TEST_stg2.sql b/onetime/dataloadfunctions/Drawbar/DBOECD_TEST_stg2.sql new file mode 100755 index 0000000..4e2ea43 --- /dev/null +++ b/onetime/dataloadfunctions/Drawbar/DBOECD_TEST_stg2.sql @@ -0,0 +1,1472 @@ +drop function if exists staging2.fn_dboecd_test_block; +CREATE OR REPLACE FUNCTION staging2.fn_dboecd_test_block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + + begin + +/************************************************************* +Function Name:fn_dboecd_test_block +Function Desc: This function populates data into staging 2 block +File Format: DBOECD +Sheet Format: DBOECD_TEST +Creation Date: March 25 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_dboecd_test_block(p_client_id,p_function_id, p_file_mnemonic, +p_file_sheet_mnemonic, p_file_syspk) +***************************************************************/ + +SET search_path TO staging2; + +/* to process multiple files - re-runnability*/ +truncate table staging2.dboecd_test_transmission_wheels_int; +truncate table staging2.dboecd_test_h1_int; +truncate table staging2.dboecd_test_engine_rpm_engine_to_pto_block; +truncate table staging2.dboecd_test_engine_rpm_required_pull_block; +truncate table staging2.dboecd_test_engine_rpm_weight_block; +truncate table staging2.dboecd_test_engine_rpm_tyre_details_block; +truncate table staging2.dboecd_test_engine_RPM_tyre_details_int; +truncate table staging2.dboecd_test_test_condition_block; +truncate table staging2.dboecd_test_drawbar_performance_selected_summary_block; +truncate table staging2.dboecd_test_drawbar_performance_gear_performance_block; +truncate table staging2.dboecd_test_drawbar_performance_fuel_consumption_block; +truncate table staging2.dboecd_test_test_equipment_used_block; +truncate table staging2.dboecd_test_measurement_uncertainty_block; +truncate table staging2.dboecd_test_tractor_specifications_engine_details_block; +truncate table staging2.dboecd_test_tractor_specifications_cylinders_block; +truncate table staging2.dboecd_test_tractor_specifications_fuel_and_injection_block; +truncate table staging2.dboecd_test_tractor_specifications_cleaner_block; +truncate table staging2.dboecd_test_transmission_clutch_block; +truncate table staging2.dboecd_test_transmission_drawbar_block; +truncate table staging2.dboecd_test_transmission_speed_chart_desc_block; +truncate table staging2.dboecd_test_transmission_wheels_block; +truncate table staging2.dboecd_test_transmission_fuel_lubricant_int; +truncate table staging2.dboecd_test_remarks_block; +truncate table staging2.dboecd_test_remarks_footer_block; +truncate table staging2.dboecd_test_h1_block; +truncate table staging2.dboecd_test_transmission_fuel_lubricant_block; +truncate table staging2.dboecd_test_engine_rpm_rpm_block; +truncate table staging2.dboecd_test_transmission_speed_chart_block; +truncate table staging2.stg_specific_table_dboecd_test; +truncate table staging2.stg_process_table_dboecd_test; +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/*run specific data */ +execute 'insert into staging2.stg_specific_table_dboecd_test +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_dboecd_test; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for DBOECD Test', + detail = 'No data in table stg_specific_table_dboecd_test', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + +/* standardizing keywords */ +update staging2.stg_specific_table_dboecd_test set column3='Remarks:' where column3 like 'Remarks:%'; +update staging2.stg_specific_table_dboecd_test set column15='Objective' where column15 like 'Objective%'; + +update staging2.stg_specific_table_dboecd_test set column3 = TRIM (TRAILING FROM column3 ); +update staging2.stg_specific_table_dboecd_test set column3 = TRIM (LEADING FROM column3 ); + +/* To process repeated keywords */ +--update transactional.source_config set F1_modified = TRIM (TRAILING FROM F1_modified) ; +--update transactional.source_config set F1_modified = TRIM (LEADING FROM F1_modified) ; +update transactional.source_config set F1_source=F1_modified ; +--update transactional.source_config set F1_source = TRIM (TRAILING FROM F1_source); +--update transactional.source_config set F1_source = TRIM (LEADING FROM F1_source); + +/*updating row numbers in source_config table*/ + +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_dboecd_test b +where trim(upper(F1_modified))=trim(upper(column3)) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update staging2.stg_specific_table_dboecd_test a +set is_rownumber_fetched=1 +from transactional.source_config b +where trim(upper(F1_modified))=trim(upper(column3)) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* update null for the last keyword as read end beacause of overlap of multiple formats*/ +execute 'update transactional.source_config a +set row_read_end = null ,run_time=current_timestamp +where f1_modified =''Remarks:'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers for each block */ + +execute 'insert into staging2.stg_process_table_dboecd_test +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_dboecd_test a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Request no.'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_dboecd_test +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag from staging2.stg_specific_table_dboecd_test a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Engine (RPM)'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_dboecd_test +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag from staging2.stg_specific_table_dboecd_test a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test condition'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_dboecd_test +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag from staging2.stg_specific_table_dboecd_test a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Drawbar Performance Test Results (Selected Summary)'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_dboecd_test +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_dboecd_test a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Drawbar Performance Test Results (Gear Performance Test)'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_dboecd_test +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_dboecd_test a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''3.3.2'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_dboecd_test +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_dboecd_test a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test equipment’s used'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'insert into staging2.stg_process_table_dboecd_test +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_dboecd_test a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Tractor specification'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_dboecd_test +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_dboecd_test a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Transmission'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'insert into staging2.stg_process_table_dboecd_test +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_dboecd_test a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Remarks:'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/*selecting tactor make*/ +select column6 into __make from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_tractor_specifications' and trim(' :' from column4)='Make'; + +/*selecting tractor model*/ +select column6 into __model from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_Test_H1' and trim(column3)='Tractor Model'; + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBOECD_TEST_H1_BLOCK',__file_mnemonic,__file_sheet_mnemonic,1); +err_block:='DBOECD_TEST_H1_BLOCK'; + +/*selecting first block column and their data*/ +insert into staging2.DBOECD_TEST_H1_INT (c1,c2,block_row_number) +select a.column3,column6,block_row_number from staging2.stg_process_table_dboecd_test a where block_tag='DBOECD_Test_H1' +union +select a.column9,column12,block_row_number from staging2.stg_process_table_dboecd_test a where block_tag='DBOECD_Test_H1' +order by column3,"block_row_number"; + +/*execute if using old format*/ +update staging2.stg_process_table_dboecd_test set column11 = null +where column11 ='-'; +update staging2.stg_process_table_dboecd_test set column12 = null +where column12 = '-'; +update staging2.stg_process_table_dboecd_test set column9 = null +where column9 ='-'; +update staging2.stg_process_table_dboecd_test set column21 = null +where column21 = '-'; +update staging2.stg_process_table_dboecd_test set column12 = null +where column12 = '..'; +update staging2.stg_process_table_dboecd_test set column8 = null +where column8 = '.'; +update staging2.stg_process_table_dboecd_test set column20 = trim(' Kg' from column20) +where block_row_number =7 and block_tag = 'DBOECD_test_transmission'; +update staging2.stg_process_table_dboecd_test set column23 = trim(' Kg' from column23) +where block_row_number =7 and block_tag = 'DBOECD_test_transmission'; + +/*selecting objective column and its data*/ +insert into staging2.DBOECD_TEST_H1_INT (c1,c2) +select 'Objective',column15 +from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_Test_H1' +and row_number= +( +select row_number+1 from +staging2.stg_process_table_dboecd_test a +where column15='Objective' +and block_tag='DBOECD_Test_H1' +); + +/*selecting acceptance criteria column and its data*/ +insert into staging2.dboecd_TEST_H1_INT (c1,c2) +select 'Acceptance criteria',column15 +from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_Test_H1' +and row_number= +( +select row_number+1 from +staging2.stg_process_table_dboecd_test a +where trim(':' from column15)='Acceptance criteria' +and block_tag='DBOECD_Test_H1' +); + +/*filling h1 block by transposing h1 int block*/ +insert into staging2.DBOECD_TEST_H1_Block +( +dummy_f, +Customer_Name, +Generation, +No_of_Sample, +Operator_Name, +Project_Group, +Sample_Receipt_Date, +Test_End_Date, +Test_Engineer, +Test_Location, +Test_Report_Date, +Test_Request_no, +Test_Standard_Refer, +Test_Start_Date, +Test_report_No, +Tractor_Model, +Tractor_Sr_No, +Objective, +Acceptance_criteria +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{c2}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[c2::text]) AS val + FROM staging2.DBOECD_TEST_H1_INT + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text, + a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text); + + + /*deleting dummy null record and filling make, model and other id's*/ +delete from staging2.DBOECD_TEST_H1_Block where dummy_f is null ; + execute 'update staging2.DBOECD_TEST_H1_Block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBOECD_TEST_H1_Block set client_id='||p_client_id||''; + execute 'update staging2.DBOECD_TEST_H1_Block set function_id='||p_function_id||''; + execute 'update staging2.DBOECD_TEST_H1_Block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.DBOECD_TEST_H1_Block set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.DBOECD_TEST_H1_Block set make=__make; + update staging2.DBOECD_TEST_H1_Block set model=__model; + + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBOECD_TEST_H1_BLOCK'); + +/* engine_RPM_RPM_block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBOECD_test_engine_RPM_RPM_block',__file_mnemonic,__file_sheet_mnemonic,2); +err_block:='DBOECD_test_engine_RPM_RPM_block'; +insert into staging2.DBOECD_test_engine_RPM_RPM_block(dummy_f) values ('dummy'); + +update staging2.DBOECD_test_engine_RPM_RPM_block +set low_idle_declared=(select column6 from +staging2.stg_process_table_dboecd_test where block_row_number=2 and column3='Low Idle RPM' and block_tag='DBOECD_test_engine_RPM') +where dummy_f='dummy'; + +update staging2.DBOECD_test_engine_RPM_RPM_block +set low_idle_observed=(select column8 from +staging2.stg_process_table_dboecd_test where block_row_number=2 and column3='Low Idle RPM' and block_tag='DBOECD_test_engine_RPM') +where dummy_f='dummy'; + +update staging2.DBOECD_test_engine_RPM_RPM_block +set high_idle_declared=(select column6 from +staging2.stg_process_table_dboecd_test where block_row_number=3 and column3='High Idle RPM' and block_tag='DBOECD_test_engine_RPM') +where dummy_f='dummy'; + +update staging2.DBOECD_test_engine_RPM_RPM_block +set high_idle_observed=(select column8 from +staging2.stg_process_table_dboecd_test where block_row_number=3 and column3='High Idle RPM' and block_tag='DBOECD_test_engine_RPM') +where dummy_f='dummy'; + +execute 'update staging2.DBOECD_test_engine_RPM_RPM_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBOECD_test_engine_RPM_RPM_block set client_id='||p_client_id||''; + execute 'update staging2.DBOECD_test_engine_RPM_RPM_block set function_id='||p_function_id||''; + execute 'update staging2.DBOECD_test_engine_RPM_RPM_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.DBOECD_test_engine_RPM_RPM_block set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.DBOECD_test_engine_RPM_RPM_block set make=__make; + update staging2.DBOECD_test_engine_RPM_RPM_block set model=__model; + + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBOECD_test_engine_RPM_RPM_block'); + +/*engine_rpm_engine_to_pto_block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'dboecd_test_engine_rpm_engine_to_pto_block',__file_mnemonic,__file_sheet_mnemonic,3); +err_block:='dboecd_test_engine_rpm_engine_to_pto_block'; + +insert into staging2.dboecd_test_engine_rpm_engine_to_pto_block(dummy_f) values ('dummy'); + +update staging2.DBOECD_test_engine_RPM_engine_to_PTO_block set rated_speed= +(select column6 from staging2.stg_process_table_dboecd_test a +where a.block_tag='DBOECD_test_engine_RPM' +and block_row_number=4 ) +where dummy_f='dummy'; + +update staging2.DBOECD_test_engine_RPM_engine_to_PTO_block set engine_to_PTO_ratio= +(select column6 from staging2.stg_process_table_dboecd_test a +where a.block_tag='DBOECD_test_engine_RPM' +and block_row_number=5 ) +where dummy_f='dummy'; + +update staging2.DBOECD_test_engine_RPM_engine_to_PTO_block set wheel_base_mm= +(select column6 from staging2.stg_process_table_dboecd_test a +where a.block_tag='DBOECD_test_engine_RPM' +and block_row_number=6 ) +where dummy_f='dummy'; + +update staging2.DBOECD_test_engine_RPM_engine_to_PTO_block set engine_power_hp= +(select column6 from staging2.stg_process_table_dboecd_test a +where a.file_mnemonic='DBOECD' and a.file_sheet_mnemonic='DBOECD_TEST' and a.block_tag='DBOECD_test_engine_RPM' +and block_row_number=7 ) +where dummy_f='dummy'; + +update staging2.DBOECD_test_engine_RPM_engine_to_PTO_block set PTO_Power_hp= +(select column6 from staging2.stg_process_table_dboecd_test a +where a.file_mnemonic='DBOECD' and a.file_sheet_mnemonic='DBOECD_TEST' and a.block_tag='DBOECD_test_engine_RPM' +and block_row_number=8 ) +where dummy_f='dummy'; + +execute 'update staging2.DBOECD_test_engine_RPM_engine_to_PTO_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBOECD_test_engine_RPM_engine_to_PTO_block set client_id='||p_client_id||''; + execute 'update staging2.DBOECD_test_engine_RPM_engine_to_PTO_block set function_id='||p_function_id||''; + execute 'update staging2.DBOECD_test_engine_RPM_engine_to_PTO_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.DBOECD_test_engine_RPM_engine_to_PTO_block set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.DBOECD_test_engine_RPM_engine_to_PTO_block set make=__make; + update staging2.DBOECD_test_engine_RPM_engine_to_PTO_block set model=__model; + + perform fw_core.fn_jobctl_block_end(__file_syspk,'dboecd_test_engine_rpm_engine_to_pto_block'); + +/*engine_RPM_required_pull_block */ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBOECD_test_engine_RPM_required_pull_block',__file_mnemonic,__file_sheet_mnemonic,4); +err_block:='DBOECD_test_engine_RPM_required_pull_block'; + + +insert into staging2.DBOECD_test_engine_RPM_required_pull_block ( pull_type) values ('UB'), ('B'); + +update staging2.DBOECD_test_engine_RPM_required_pull_block +set required_pull_in_kg=(select column7 from staging2.stg_process_table_dboecd_test a +where a.block_tag='DBOECD_test_engine_RPM' +and column3='Required pull in (kg)') +where pull_type='UB'; + +update staging2.DBOECD_test_engine_RPM_required_pull_block +set required_pull_in_kg=(select column9 from staging2.stg_process_table_dboecd_test a +where a.block_tag='DBOECD_test_engine_RPM' +and column3='Required pull in (kg)') +where pull_type='B'; + +update staging2.DBOECD_test_engine_RPM_required_pull_block +set required_power_in_hp=(select column7 from staging2.stg_process_table_dboecd_test a +where a.block_tag='DBOECD_test_engine_RPM' +and column3='Required Power in hp') +where pull_type='UB'; + +update staging2.DBOECD_test_engine_RPM_required_pull_block +set required_power_in_hp=(select column9 from staging2.stg_process_table_dboecd_test a +where a.block_tag='DBOECD_test_engine_RPM' +and column3='Required Power in hp') +where pull_type='B'; + +update staging2.DBOECD_test_engine_RPM_required_pull_block +set actual_pull_in_kg=(select column7 from staging2.stg_process_table_dboecd_test a +where a.block_tag='DBOECD_test_engine_RPM' +and column3='Actual pull in (kg)') +where pull_type='UB'; + +update staging2.DBOECD_test_engine_RPM_required_pull_block +set actual_pull_in_kg=(select column9 from staging2.stg_process_table_dboecd_test a +where a.block_tag='DBOECD_test_engine_RPM' +and column3='Actual pull in (kg)') +where pull_type='B'; + +update staging2.DBOECD_test_engine_RPM_required_pull_block +set actual_power_in_hp=(select column7 from staging2.stg_process_table_dboecd_test a +where a.block_tag='DBOECD_test_engine_RPM' +and column3='actual power in hp') +where pull_type='UB'; + +update staging2.DBOECD_test_engine_RPM_required_pull_block +set actual_power_in_hp=(select column9 from staging2.stg_process_table_dboecd_test a +where a.block_tag='DBOECD_test_engine_RPM' +and column3='actual power in hp') +where pull_type='B'; + +update staging2.DBOECD_test_engine_RPM_required_pull_block +set calculated_hitch_height_mm=(select column7 from staging2.stg_process_table_dboecd_test a +where a.block_tag='DBOECD_test_engine_RPM' +and column3='Calculated hitch height (mm)') +where pull_type='UB'; + +update staging2.DBOECD_test_engine_RPM_required_pull_block +set calculated_hitch_height_mm=(select column9 from staging2.stg_process_table_dboecd_test a +where a.block_tag='DBOECD_test_engine_RPM' +and column3='Calculated hitch height (mm)') +where pull_type='B'; + +update staging2.DBOECD_test_engine_RPM_required_pull_block +set actual_hitch_height_mm=(select column7 from staging2.stg_process_table_dboecd_test a +where a.block_tag='DBOECD_test_engine_RPM' +and column3='Actual hitch height (mm)') +where pull_type='UB'; + +update staging2.DBOECD_test_engine_RPM_required_pull_block +set actual_hitch_height_mm=(select column9 from staging2.stg_process_table_dboecd_test a +where a.block_tag='DBOECD_test_engine_RPM' +and column3='Actual hitch height (mm)') +where pull_type='B'; + +execute 'update staging2.DBOECD_test_engine_RPM_required_pull_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBOECD_test_engine_RPM_required_pull_block set client_id='||p_client_id||''; + execute 'update staging2.DBOECD_test_engine_RPM_required_pull_block set function_id='||p_function_id||''; + execute 'update staging2.DBOECD_test_engine_RPM_required_pull_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.DBOECD_test_engine_RPM_required_pull_block set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.DBOECD_test_engine_RPM_required_pull_block set make=__make; + update staging2.DBOECD_test_engine_RPM_required_pull_block set model=__model; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'DBOECD_test_engine_RPM_required_pull_block'); + +/* RPM_weight_block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBOECD_test_engine_RPM_weight_block',__file_mnemonic,__file_sheet_mnemonic,5); +err_block:='DBOECD_test_engine_RPM_weight_block'; + +insert into staging2.DBOECD_test_engine_RPM_weight_block( +weight_kg , +Front , +rear , +Total +) +select column10,column13,column17,column22 from staging2.stg_process_table_dboecd_test a +where a.block_tag='DBOECD_test_engine_RPM' +and block_row_number in(2,3); + +execute 'update staging2.DBOECD_test_engine_RPM_weight_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBOECD_test_engine_RPM_weight_block set client_id='||p_client_id||''; + execute 'update staging2.DBOECD_test_engine_RPM_weight_block set function_id='||p_function_id||''; + execute 'update staging2.DBOECD_test_engine_RPM_weight_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.DBOECD_test_engine_RPM_weight_block set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.DBOECD_test_engine_RPM_weight_block set make=__make; + update staging2.DBOECD_test_engine_RPM_weight_block set model=__model; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'DBOECD_test_engine_RPM_weight_block'); + +/*rpm tyre details block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBOECD_test_engine_RPM_tyre_details_block',__file_mnemonic,__file_sheet_mnemonic,6); +err_block:='DBOECD_test_engine_RPM_tyre_details_block'; + + insert into staging2.DBOECD_test_engine_RPM_tyre_details_int +( s_no,tyre_details,front,rear) + +select column10,column11,column15,column20 +from staging2.stg_process_table_dboecd_test a +where a.block_tag='DBOECD_test_engine_RPM' +and block_row_number >=5 and block_row_number<=14 +order by block_row_number; + + +execute 'update staging2.DBOECD_test_engine_RPM_tyre_details_int set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBOECD_test_engine_RPM_tyre_details_int set client_id='||p_client_id||''; + execute 'update staging2.DBOECD_test_engine_RPM_tyre_details_int set function_id='||p_function_id||''; + execute 'update staging2.DBOECD_test_engine_RPM_tyre_details_int set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.DBOECD_test_engine_RPM_tyre_details_int set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.DBOECD_test_engine_RPM_tyre_details_int set make=__make; + update staging2.DBOECD_test_engine_RPM_tyre_details_int set model=__model; + +/*rpm tyre details block*/ + +insert into staging2.DBOECD_test_engine_RPM_tyre_details_block +( +dummy_f, +tyre_Make, +size, +Ply_Rating, +Load_Carrying_Capacity_in_Kg, +Pressure_kg_cm2, +Number_of_lug, +Number_of_no_load_lug_30m, +Lug_Height, +Dynamic_rolling_radius_mm, +Wheel_Rim_Make_Size +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{front,rear}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[front::text,rear::text]) AS val + FROM staging2.DBOECD_test_engine_RPM_tyre_details_int + ORDER BY generate_series(1,15),2' + ) t ( col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text + ,a_10 text); + + delete from staging2.DBOECD_test_engine_RPM_tyre_details_block where dummy_f is null; + +execute 'update staging2.DBOECD_test_engine_RPM_tyre_details_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBOECD_test_engine_RPM_tyre_details_block set client_id='||p_client_id||''; + execute 'update staging2.DBOECD_test_engine_RPM_tyre_details_block set function_id='||p_function_id||''; + execute 'update staging2.DBOECD_test_engine_RPM_tyre_details_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.DBOECD_test_engine_RPM_tyre_details_block set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.DBOECD_test_engine_RPM_tyre_details_block set make=__make; + update staging2.DBOECD_test_engine_RPM_tyre_details_block set model=__model; + + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBOECD_test_engine_RPM_tyre_details_block'); + +/* test condition block */ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBOECD_test_test_condition_block',__file_mnemonic,__file_sheet_mnemonic,7); +err_block:='DBOECD_test_test_condition_block'; + + +insert into staging2.DBOECD_test_test_condition_block(c1,c2,c3) +select column3 c1,column10 c2,column15 c3 +from staging2.stg_process_table_dboecd_test a +where a.block_tag='DBOECD_test_test_condition'; + + +execute 'update staging2.DBOECD_test_test_condition_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBOECD_test_test_condition_block set client_id='||p_client_id||''; + execute 'update staging2.DBOECD_test_test_condition_block set function_id='||p_function_id||''; + execute 'update staging2.DBOECD_test_test_condition_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.DBOECD_test_test_condition_block set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.DBOECD_test_test_condition_block set make=__make; + update staging2.DBOECD_test_test_condition_block set model=__model; + +update staging2.dboecd_test_test_condition_block +set c3='B' +where c2='Ballasted'; + + +update staging2.dboecd_test_test_condition_block +set c3='UB' +where c2='Un-ballasted'; + + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBOECD_test_test_condition_block'); + +/* performance_selected_summary_block */ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBOECD_test_drawbar_performance_selected_summary_block',__file_mnemonic,__file_sheet_mnemonic,8); + +err_block:='DBOECD_test_drawbar_performance_selected_summary_block'; + +insert into staging2.DBOECD_test_drawbar_performance_selected_summary_block(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16,c17,c18,c19,c20,c21,c22,c23,c24,c25) +select column3 c1, +column4 c2, +column5 c3, +column6 c4, +column7 c5, +column8 c6, +column9 c7, +column10 c8, +column11 c9, +column12 c10, +column13 c11, +column14 c12, +column15 c13, +column16 c14, +column17 c15, +column18 c16, +column19 c17, +column20 c18, +column21 c19, +column22 c20, +column23 c21, +column24 c22, +column25 c23, +column26 c24, +column27 c25 +from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_drawbar_performance_selected_summary' +and block_row_number>3; + + + +execute 'update staging2.DBOECD_test_drawbar_performance_selected_summary_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBOECD_test_drawbar_performance_selected_summary_block set client_id='||p_client_id||''; + execute 'update staging2.DBOECD_test_drawbar_performance_selected_summary_block set function_id='||p_function_id||''; + execute 'update staging2.DBOECD_test_drawbar_performance_selected_summary_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.DBOECD_test_drawbar_performance_selected_summary_block set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.DBOECD_test_drawbar_performance_selected_summary_block set make=__make; + update staging2.DBOECD_test_drawbar_performance_selected_summary_block set model=__model; + + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBOECD_test_drawbar_performance_selected_summary_block'); + + /* Fuel_consumption_block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'dboecd_test_drawbar_performance_fuel_consumption_block',__file_mnemonic,__file_sheet_mnemonic,9); + err_block:='dboecd_test_drawbar_performance_fuel_consumption_block'; + + +insert into staging2.dboecd_test_drawbar_performance_fuel_consumption_block(c1_1,c2_1,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16,c17,c18,c19,c20,c21,c22,c23,c24,c25) +with fuel_consumtion_data as( +select column3 c1, +column4 c2, +column5 c3, +column6 c4, +column7 c5, +column8 c6, +column9 c7, +column10 c8, +column11 c9, +column12 c10, +column13 c11, +column14 c12, +column15 c13, +column16 c14, +column17 c15, +column18 c16, +column19 c17, +column20 c18, +column21 c19, +column22 c20, +column23 c21, +column24 c22, +column25 c23, +column26 c24, +column27 c25, +block_row_number +from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_fuel_consumption' and column5 is not null +and block_row_number>3), +data_required as +( +select column3 as c1_1,column4 as c2_1 from staging2.stg_process_table_dboecd_test a where block_tag='DBOECD_test_fuel_consumption' +and block_row_number>3 and column5 is null +), +stag1_info_table as +(select c1_1,c2_1,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16,c17,c18,c19,c20,c21,c22,c23,c24,c25 +from (select *,row_number() over () as rn from data_required) t1, +(select *,row_number() over () as rn from fuel_consumtion_data)t2 +where t1.rn = t2.rn) +select * from stag1_info_table; + +update staging2.dboecd_test_drawbar_performance_fuel_consumption_block set Remark = (select replace(column3,'Remark: ','') from staging2.stg_process_table_dboecd_test where column3 like 'Remark%' and block_tag='DBOECD_test_fuel_consumption'); + + +execute 'update staging2.dboecd_test_drawbar_performance_fuel_consumption_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.dboecd_test_drawbar_performance_fuel_consumption_block set client_id='||p_client_id||''; + execute 'update staging2.dboecd_test_drawbar_performance_fuel_consumption_block set function_id='||p_function_id||''; + execute 'update staging2.dboecd_test_drawbar_performance_fuel_consumption_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.dboecd_test_drawbar_performance_fuel_consumption_block set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.dboecd_test_drawbar_performance_fuel_consumption_block set make=__make; + update staging2.dboecd_test_drawbar_performance_fuel_consumption_block set model=__model; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'dboecd_test_drawbar_performance_fuel_consumption_block'); + + /* performance_gear_summary_block */ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBOECD_test_drawbar_performance_gear_performance_block',__file_mnemonic,__file_sheet_mnemonic,10); + err_block:='DBOECD_test_drawbar_performance_gear_performance_block'; + + + insert into staging2.DBOECD_test_drawbar_performance_gear_performance_block (c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16,c17,c18,c19,c20,c21,c22,c23,c24,c25) +select column3 c1, +column4 c2, +column5 c3, +column6 c4, +column7 c5, +column8 c6, +column9 c7, +column10 c8, +column11 c9, +column12 c10, +column13 c11, +column14 c12, +column15 c13, +column16 c14, +column17 c15, +column18 c16, +column19 c17, +column20 c18, +column21 c19, +column22 c20, +column23 c21, +column24 c22, +column25 c23, +column26 c24, +column27 c25 +from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_drawbar_performance_gear_performance' +and block_row_number>3; + + + +execute 'update staging2.DBOECD_test_drawbar_performance_gear_performance_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBOECD_test_drawbar_performance_gear_performance_block set client_id='||p_client_id||''; + execute 'update staging2.DBOECD_test_drawbar_performance_gear_performance_block set function_id='||p_function_id||''; + execute 'update staging2.DBOECD_test_drawbar_performance_gear_performance_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.DBOECD_test_drawbar_performance_gear_performance_block set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.DBOECD_test_drawbar_performance_gear_performance_block set make=__make; + update staging2.DBOECD_test_drawbar_performance_gear_performance_block set model=__model; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'DBOECD_test_drawbar_performance_gear_performance_block'); + + /*test_equipment_used_block */ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBOECD_test_test_equipment_used_block',__file_mnemonic,__file_sheet_mnemonic,11); + err_block:='DBOECD_test_test_equipment_used_block'; + + + insert into staging2.DBOECD_test_test_equipment_used_block( s_no,instruments,instruments_no,cali_due_date) +select column3,column4,column8,column12 +from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_test_equipment' +and block_row_number>2; + +execute 'update staging2.DBOECD_test_test_equipment_used_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBOECD_test_test_equipment_used_block set client_id='||p_client_id||''; + execute 'update staging2.DBOECD_test_test_equipment_used_block set function_id='||p_function_id||''; + execute 'update staging2.DBOECD_test_test_equipment_used_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.DBOECD_test_test_equipment_used_block set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.DBOECD_test_test_equipment_used_block set make=__make; + update staging2.DBOECD_test_test_equipment_used_block set model=__model; + + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBOECD_test_test_equipment_used_block'); + +/*measurement_uncertainty_block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBOECD_test_measurement_uncertainty_block',__file_mnemonic,__file_sheet_mnemonic,12); + err_block:='DBOECD_test_measurement_uncertainty_block'; + + + insert into staging2.DBOECD_test_measurement_uncertainty_block(dummy_f) values ('dummy'); + +update staging2.DBOECD_test_measurement_uncertainty_block set load_cell= +(select column20 from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_test_equipment' and trim(' :' from column15)='Load cell'); + +update staging2.DBOECD_test_measurement_uncertainty_block set rpm_meter= +(select column20 from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_test_equipment' and trim(' :' from column15)='RPM Meter'); + +update staging2.DBOECD_test_measurement_uncertainty_block set speed= +(select column20 from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_test_equipment' and trim(' :' from column15)='Speed'); + + +update staging2.DBOECD_test_measurement_uncertainty_block set fuel_flow_meter= +(select column20 from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_test_equipment' and trim(' :' from column15)='Fuel Flow meter'); + + + +execute 'update staging2.DBOECD_test_measurement_uncertainty_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBOECD_test_measurement_uncertainty_block set client_id='||p_client_id||''; + execute 'update staging2.DBOECD_test_measurement_uncertainty_block set function_id='||p_function_id||''; + execute 'update staging2.DBOECD_test_measurement_uncertainty_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.DBOECD_test_measurement_uncertainty_block set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.DBOECD_test_measurement_uncertainty_block set make=__make; + update staging2.DBOECD_test_measurement_uncertainty_block set model=__model; + + +perform fw_core.fn_jobctl_block_end(__file_syspk,'DBOECD_test_measurement_uncertainty_block'); + + /*tractor_specifications_engine_details_block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBOECD_test_tractor_specifications_engine_details_block',__file_mnemonic,__file_sheet_mnemonic,13); + err_block:='DBOECD_test_tractor_specifications_engine_details_block'; + + + insert into staging2.DBOECD_test_tractor_specifications_engine_details_block(dummy_f) +values ('dummy'); + +update staging2.DBOECD_test_tractor_specifications_engine_details_block +set make_in_block=(select column6 from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_tractor_specifications' +and trim(' :' from column4)='Make' +) +where dummy_f is not null; + + +update staging2.DBOECD_test_tractor_specifications_engine_details_block +set type=(select column6 from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_tractor_specifications' +and trim(' :' from column4)='Type' +) +where dummy_f is not null; + +update staging2.DBOECD_test_tractor_specifications_engine_details_block +set model_in_block=(select column6 from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_tractor_specifications' +and trim(' :' from column4)='Model' +) +where dummy_f is not null; + + +update staging2.DBOECD_test_tractor_specifications_engine_details_block +set serial_no=(select column6 from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_tractor_specifications' +and trim(' :' from column4)='Serial No' +) +where dummy_f is not null; + + +update staging2.DBOECD_test_tractor_specifications_engine_details_block +set E_P_ratio=(select column6 from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_tractor_specifications' +and trim(' :' from column4)='E/P Ratio' +) +where dummy_f is not null; + +update staging2.DBOECD_test_tractor_specifications_engine_details_block +set rated_speed=(select column6 from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_tractor_specifications' +and trim(' :' from column4)='Rated Speed' +) +where dummy_f is not null; + +update staging2.DBOECD_test_tractor_specifications_engine_details_block +set high_idle=(select column6 from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_tractor_specifications' +and trim(' :' from column4)='High Idle' +) +where dummy_f is not null; + +update staging2.DBOECD_test_tractor_specifications_engine_details_block +set high_idle=(select column6 from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_tractor_specifications' +and trim(' :' from column4)='High Idle' +) +where dummy_f is not null; + +update staging2.DBOECD_test_tractor_specifications_engine_details_block +set low_idle=(select replace(column8,'Low Idle:- ','') from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_tractor_specifications' +and trim(column4)='High Idle' +) +where dummy_f is not null; + + +execute 'update staging2.DBOECD_test_tractor_specifications_engine_details_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBOECD_test_tractor_specifications_engine_details_block set client_id='||p_client_id||''; + execute 'update staging2.DBOECD_test_tractor_specifications_engine_details_block set function_id='||p_function_id||''; + execute 'update staging2.DBOECD_test_tractor_specifications_engine_details_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.DBOECD_test_tractor_specifications_engine_details_block set file_mnemonic='''||p_file_mnemonic||''''; + + + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBOECD_test_tractor_specifications_engine_details_block'); + + /*tractor_specifications_cylinders_block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBOECD_test_tractor_specifications_cylinders_block',__file_mnemonic,__file_sheet_mnemonic,14); + err_block:='DBOECD_test_tractor_specifications_cylinders_block'; + + + insert into staging2.DBOECD_test_tractor_specifications_cylinders_block(dummy_f) +values ('dummy'); + +update staging2.DBOECD_test_tractor_specifications_cylinders_block +set number=(select column11 from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_tractor_specifications' +and trim(' :' from column9)='Number' +) +where dummy_f is not null; + +update staging2.DBOECD_test_tractor_specifications_cylinders_block +set stroke=(select column11 from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_tractor_specifications' +and trim(' :' from column9)='Stroke' +) +where dummy_f is not null; + +update staging2.DBOECD_test_tractor_specifications_cylinders_block +set bore=(select column11 from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_tractor_specifications' +and trim(' :' from column9)='Bore' +) +where dummy_f is not null; + +update staging2.DBOECD_test_tractor_specifications_cylinders_block +set capacity=(select column11 from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_tractor_specifications' +and trim(' :' from column9)='Capacity' +) +where dummy_f is not null; + + +execute 'update staging2.DBOECD_test_tractor_specifications_cylinders_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBOECD_test_tractor_specifications_cylinders_block set client_id='||p_client_id||''; + execute 'update staging2.DBOECD_test_tractor_specifications_cylinders_block set function_id='||p_function_id||''; + execute 'update staging2.DBOECD_test_tractor_specifications_cylinders_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.DBOECD_test_tractor_specifications_cylinders_block set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.DBOECD_test_tractor_specifications_cylinders_block set make=__make; + update staging2.DBOECD_test_tractor_specifications_cylinders_block set model=__model; + + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBOECD_test_tractor_specifications_cylinders_block'); + + /*fuel_and_injection_block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBOECD_test_tractor_specifications_fuel_and_injection_block',__file_mnemonic,__file_sheet_mnemonic,15); + err_block:='DBOECD_test_tractor_specifications_fuel_and_injection_block'; + + + insert into staging2.DBOECD_test_tractor_specifications_fuel_and_injection_block(dummy_f) +values ('dummy'); + +update staging2.DBOECD_test_tractor_specifications_fuel_and_injection_block +set Make_type_and_model_of_injection_pump=(select column17 from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_tractor_specifications' +and trim(column12)='Make, type and model of injection pump' +) +where dummy_f is not null; + +update staging2.DBOECD_test_tractor_specifications_fuel_and_injection_block +set capacity_of_fuel_tank_lit=(select column17 from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_tractor_specifications' +and trim('. :-' from column12)='Capacity of fuel tank, lit' +) +where dummy_f is not null; + +update staging2.DBOECD_test_tractor_specifications_fuel_and_injection_block +set Make_type_and_model_of_injection_pump=(select column17 from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_tractor_specifications' +and trim(' :-' from column12)='Make, type and model of injection pump' +) +where dummy_f is not null; + +update staging2.DBOECD_test_tractor_specifications_fuel_and_injection_block +set Manufacturer_production_setting=(select column17 from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_tractor_specifications' +and trim(' :-' from column12)='Manufacturers production setting' +) +where dummy_f is not null; + +update staging2.DBOECD_test_tractor_specifications_fuel_and_injection_block +set Make_type_and_model_of_injectors=(select column17 from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_tractor_specifications' +and trim(' :-' from column12)='Make, type and model of injectors' +) +where dummy_f is not null; + +update staging2.DBOECD_test_tractor_specifications_fuel_and_injection_block +set Make_type_and_model_of_magneto_coil_and_distributor=(select column17 from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_tractor_specifications' +and trim(' :-' from column12)='Make, type and model of magneto, coil and distributor' +) +where dummy_f is not null; + +update staging2.DBOECD_test_tractor_specifications_fuel_and_injection_block +set Make_type_and_model_of_carburetor=(select column17 from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_tractor_specifications' +and trim(' :-' from column12)='Make, type and model of carburetor' +) +where dummy_f is not null; + +update staging2.DBOECD_test_tractor_specifications_fuel_and_injection_block +set Ignition_or_injection_timing_Manual_or_automatic=(select column17 from staging2.stg_process_table_dboecd_test a +where block_tag='DBOECD_test_tractor_specifications' +and trim(' :-' from column12)='Ignition or injection timing (Manual or automatic)' +) +where dummy_f is not null; + + +execute 'update staging2.DBOECD_test_tractor_specifications_fuel_and_injection_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBOECD_test_tractor_specifications_fuel_and_injection_block set client_id='||p_client_id||''; + execute 'update staging2.DBOECD_test_tractor_specifications_fuel_and_injection_block set function_id='||p_function_id||''; + execute 'update staging2.DBOECD_test_tractor_specifications_fuel_and_injection_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.DBOECD_test_tractor_specifications_fuel_and_injection_block set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.DBOECD_test_tractor_specifications_fuel_and_injection_block set make=__make; + update staging2.DBOECD_test_tractor_specifications_fuel_and_injection_block set model=__model; + + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBOECD_test_tractor_specifications_fuel_and_injection_block'); + + /*tractor_specifications_cleaner_block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBOECD_test_tractor_specifications_cleaner_block',__file_mnemonic,__file_sheet_mnemonic,16); + err_block:='DBOECD_test_tractor_specifications_cleaner_block'; + + + insert into staging2.DBOECD_test_tractor_specifications_cleaner_block(cleaner_type) +values ('Air cleaner'),('Precleaner (if fitted)'); + +update staging2.DBOECD_test_tractor_specifications_cleaner_block +set make_and_model = +(select column23 from staging2.stg_process_table_dboecd_test a where + block_tag='DBOECD_test_tractor_specifications' +and column21='Make and model' and block_row_number=3) +where cleaner_type='Air cleaner'; + +update staging2.DBOECD_test_tractor_specifications_cleaner_block +set type= +(select column23 from staging2.stg_process_table_dboecd_test a where + block_tag='DBOECD_test_tractor_specifications' +and column21='Type' and block_row_number=5) +where cleaner_type='Air cleaner'; + +update staging2.DBOECD_test_tractor_specifications_cleaner_block +set make_and_model = +(select column23 from staging2.stg_process_table_dboecd_test a where + block_tag='DBOECD_test_tractor_specifications' +and column21='Make and model' and block_row_number=7) +where cleaner_type='Precleaner (if fitted)'; + +update staging2.DBOECD_test_tractor_specifications_cleaner_block +set type= +(select column23 from staging2.stg_process_table_dboecd_test a where +block_tag='DBOECD_test_tractor_specifications' +and column21='Type' and block_row_number=9) +where cleaner_type='Precleaner (if fitted)'; + + +execute 'update staging2.DBOECD_test_tractor_specifications_cleaner_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBOECD_test_tractor_specifications_cleaner_block set client_id='||p_client_id||''; + execute 'update staging2.DBOECD_test_tractor_specifications_cleaner_block set function_id='||p_function_id||''; + execute 'update staging2.DBOECD_test_tractor_specifications_cleaner_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.DBOECD_test_tractor_specifications_cleaner_block set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.DBOECD_test_tractor_specifications_cleaner_block set make=__make; + update staging2.DBOECD_test_tractor_specifications_cleaner_block set model=__model; + + + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBOECD_test_tractor_specifications_cleaner_block'); + + /*transmission_clutch_block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBOECD_test_transmission_clutch_block',__file_mnemonic,__file_sheet_mnemonic,17); + err_block:='DBOECD_test_transmission_clutch_block'; + + + insert into staging2.DBOECD_test_transmission_clutch_block(dummy_f) values ('dummy'); + + +update staging2.DBOECD_test_transmission_clutch_block a +set clutch_type=( +select column6 from staging2.stg_process_table_dboecd_test b +where trim(' :' from b.column3)='Type' and block_row_number=2 and b.block_tag='DBOECD_test_transmission') +where dummy_F='dummy'; + +update staging2.DBOECD_test_transmission_clutch_block a +set steering_type=( +select column6 from staging2.stg_process_table_dboecd_test b +where trim(' :' from b.column3)='Type' and block_row_number=5 and b.block_tag='DBOECD_test_transmission') +where dummy_F='dummy'; + +update staging2.DBOECD_test_transmission_clutch_block a +set diameter_of_disc_mm=( +select column6 from staging2.stg_process_table_dboecd_test b +where trim(' :' from b.column3)='Diameter of disc, mm' and b.block_tag='DBOECD_test_transmission') +where dummy_F='dummy'; + + +execute 'update staging2.DBOECD_test_transmission_clutch_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBOECD_test_transmission_clutch_block set client_id='||p_client_id||''; + execute 'update staging2.DBOECD_test_transmission_clutch_block set function_id='||p_function_id||''; + execute 'update staging2.DBOECD_test_transmission_clutch_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.DBOECD_test_transmission_clutch_block set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.DBOECD_test_transmission_clutch_block set make=__make; + update staging2.DBOECD_test_transmission_clutch_block set model=__model; + + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBOECD_test_transmission_clutch_block'); + + /*transmission_drawbar_block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBOECD_test_transmission_drawbar_block',__file_mnemonic,__file_sheet_mnemonic,18); + err_block:='DBOECD_test_transmission_drawbar_block'; + +insert into staging2.DBOECD_test_transmission_drawbar_block(dummy_f) values ('dummy'); + +update staging2.DBOECD_test_transmission_drawbar_block a +set type=( +select column8 from staging2.stg_process_table_dboecd_test b +where trim(' :' from b.column3)='Type' and block_row_number=7 and b.block_tag='DBOECD_test_transmission') +where dummy_F='dummy'; + +update staging2.DBOECD_test_transmission_drawbar_block a +set Height_above_ground_max_mm=( +select column8 from staging2.stg_process_table_dboecd_test b +where trim(' :' from b.column3)='Height above ground (max), mm' and block_row_number=9 and b.block_tag='DBOECD_test_transmission') +where dummy_F='dummy'; + +update staging2.DBOECD_test_transmission_drawbar_block a +set Height_above_ground_min_mm=( +select column8 from staging2.stg_process_table_dboecd_test b +where trim(' :' from b.column3)='Height above ground (min), mm' and block_row_number=11 and b.block_tag='DBOECD_test_transmission') +where dummy_F='dummy'; + +update staging2.DBOECD_test_transmission_drawbar_block a +set Position_related_to_PTO=( +select column8 from staging2.stg_process_table_dboecd_test b +where trim(' :' from b.column3)='Position related to PTO' and block_row_number=13 and b.block_tag='DBOECD_test_transmission') +where dummy_F='dummy'; + +update staging2.DBOECD_test_transmission_drawbar_block a +set Wheel_Base=( +select column8 from staging2.stg_process_table_dboecd_test b +where trim(' :' from b.column3)='Wheel Base' and block_row_number=15 and b.block_tag='DBOECD_test_transmission') +where dummy_F='dummy'; + + execute 'update staging2.DBOECD_test_transmission_drawbar_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBOECD_test_transmission_drawbar_block set client_id='||p_client_id||''; + execute 'update staging2.DBOECD_test_transmission_drawbar_block set function_id='||p_function_id||''; + execute 'update staging2.DBOECD_test_transmission_drawbar_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.DBOECD_test_transmission_drawbar_block set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.DBOECD_test_transmission_drawbar_block set make=__make; + update staging2.DBOECD_test_transmission_drawbar_block set model=__model; + + update staging2.dboecd_test_transmission_drawbar_block a +set test_condition=b.c3 +from staging2.dboecd_test_test_condition_block b +where a.file_syspk=b.file_syspk; + + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBOECD_test_transmission_drawbar_block'); + +/*transmission_speed_chart_desc_block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBOECD_test_transmission_speed_chart_desc_block',__file_mnemonic,__file_sheet_mnemonic,19); + err_block:='DBOECD_test_transmission_speed_chart_desc_block'; + +insert into staging2.DBOECD_test_transmission_speed_chart_desc_block +(descr) +select column10 +from +staging2.stg_process_table_dboecd_test b +where b.block_tag='DBOECD_test_transmission' +and block_row_number=1; + + +execute 'update staging2.DBOECD_test_transmission_speed_chart_desc_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBOECD_test_transmission_speed_chart_desc_block set client_id='||p_client_id||''; + execute 'update staging2.DBOECD_test_transmission_speed_chart_desc_block set function_id='||p_function_id||''; + execute 'update staging2.DBOECD_test_transmission_speed_chart_desc_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.DBOECD_test_transmission_speed_chart_desc_block set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.DBOECD_test_transmission_speed_chart_desc_block set make=__make; + update staging2.DBOECD_test_transmission_speed_chart_desc_block set model=__model; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'DBOECD_test_transmission_speed_chart_desc_block'); + +/*transmission_speed_chart_desc_block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBOECD_test_transmission_speed_chart_block',__file_mnemonic,__file_sheet_mnemonic,20); + /*transmission_speed_chart_block*/ + err_block:='DBOECD_test_transmission_speed_chart_block'; + + insert into staging2.DBOECD_test_transmission_speed_chart_block +(gear,forward,reverse) +select column10,column11, column13 from +staging2.stg_process_table_dboecd_test b +where b.block_tag='DBOECD_test_transmission' +and block_row_number>=3; + + +execute 'update staging2.dboecd_test_transmission_speed_chart_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.dboecd_test_transmission_speed_chart_block set client_id='||p_client_id||''; + execute 'update staging2.dboecd_test_transmission_speed_chart_block set function_id='||p_function_id||''; + execute 'update staging2.dboecd_test_transmission_speed_chart_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.dboecd_test_transmission_speed_chart_block set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.dboecd_test_transmission_speed_chart_block set make=__make; + update staging2.dboecd_test_transmission_speed_chart_block set model=__model; + delete from staging2.dboecd_test_transmission_speed_chart_block where gear is null; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'DBOECD_test_transmission_speed_chart_block'); + +/*transmission_wheels_in*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBOECD_test_transmission_wheels_block',__file_mnemonic,__file_sheet_mnemonic,21); + err_block:='DBOECD_test_transmission_wheels_block'; + +insert into staging2.DBOECD_test_transmission_wheels_int(Descriptions,Steered_wheels,Driving_wheel) +select column15,column20,column23 from staging2.stg_process_table_dboecd_test b +where b.block_tag='DBOECD_test_transmission' +and block_row_number>=3 and block_row_number<=11 +order by block_row_number; + +update staging2.DBOECD_test_transmission_wheels_int +set Driving_wheel=Steered_wheels +where trim(' :' from Descriptions)='Location of driving wheel' +and Driving_wheel =''; + + +execute 'update staging2.DBOECD_test_transmission_wheels_int set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBOECD_test_transmission_wheels_int set client_id='||p_client_id||''; + execute 'update staging2.DBOECD_test_transmission_wheels_int set function_id='||p_function_id||''; + execute 'update staging2.DBOECD_test_transmission_wheels_int set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.DBOECD_test_transmission_wheels_int set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.DBOECD_test_transmission_wheels_int set make=__make; + update staging2.DBOECD_test_transmission_wheels_int set model=__model; + + + /*transmission_wheels_block*/ +insert into staging2.dboecd_test_transmission_wheels_block + ( + dummy_f, + Location_of_driving_wheel, +Make_of_tyres, +types, +size, +Maximum_permissible_load_kg, +Ply_rating, +Track_width_max_mm, +Track_width_min_mm, +Inflation_pressure_kg_cm2 + + ) + SELECT * +FROM crosstab( + 'SELECT unnest(''{steered_wheels,driving_wheel}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[steered_wheels::text,driving_wheel::text]) AS val + FROM staging2.dboecd_test_transmission_wheels_int + ORDER BY generate_series(1,10),2' + ) t ( col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text); + +delete from dboecd_test_transmission_wheels_block where dummy_f is null; + + +execute 'update staging2.dboecd_test_transmission_wheels_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.dboecd_test_transmission_wheels_block set client_id='||p_client_id||''; + execute 'update staging2.dboecd_test_transmission_wheels_block set function_id='||p_function_id||''; + execute 'update staging2.dboecd_test_transmission_wheels_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.dboecd_test_transmission_wheels_block set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.dboecd_test_transmission_wheels_block set make=__make; + update staging2.dboecd_test_transmission_wheels_block set model=__model; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'DBOECD_test_transmission_wheels_block'); + +/*transmission_fuel_lubricant*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBOECD_test_transmission_fuel_lubricant_block',__file_mnemonic,__file_sheet_mnemonic,22); + err_block:='DBOECD_test_transmission_fuel_lubricant_block'; + + +insert into staging2.DBOECD_test_transmission_fuel_lubricant_int( Descriptions,Diesel_BS_IV,Engine_oil,Transmission_oil) +select column15,column18,column20,column23 from staging2.stg_process_table_dboecd_test b +where b.block_tag='DBOECD_test_transmission' +and block_row_number>=14 and block_row_number<=18 +order by block_row_number; + + +execute 'update staging2.DBOECD_test_transmission_fuel_lubricant_int set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBOECD_test_transmission_fuel_lubricant_int set client_id='||p_client_id||''; + execute 'update staging2.DBOECD_test_transmission_fuel_lubricant_int set function_id='||p_function_id||''; + execute 'update staging2.DBOECD_test_transmission_fuel_lubricant_int set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.DBOECD_test_transmission_fuel_lubricant_int set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.DBOECD_test_transmission_fuel_lubricant_int set make=__make; + update staging2.DBOECD_test_transmission_fuel_lubricant_int set model=__model; + + +/*transmission_fuel_lubricant_block*/ +insert into staging2.DBOECD_test_transmission_fuel_lubricant_block + ( + dummy_f, + Trade_name, +type, +Octane_Cetane_number, +Viscosity, +Density_at_15C +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{diesel_bs_iv,engine_oil,transmission_oil}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[diesel_bs_iv::text,engine_oil::text,transmission_oil::text]) AS val + FROM staging2.DBOECD_test_transmission_fuel_lubricant_int + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text); + + delete from DBOECD_test_transmission_fuel_lubricant_block where dummy_f is null; + +execute 'update staging2.DBOECD_test_transmission_fuel_lubricant_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBOECD_test_transmission_fuel_lubricant_block set client_id='||p_client_id||''; + execute 'update staging2.DBOECD_test_transmission_fuel_lubricant_block set function_id='||p_function_id||''; + execute 'update staging2.DBOECD_test_transmission_fuel_lubricant_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.DBOECD_test_transmission_fuel_lubricant_block set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.DBOECD_test_transmission_fuel_lubricant_block set make=__make; + update staging2.DBOECD_test_transmission_fuel_lubricant_block set model=__model; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'DBOECD_test_transmission_fuel_lubricant_block'); + +/*DBOECD_test_remarks_block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBOECD_test_remarks_block',__file_mnemonic,__file_sheet_mnemonic,23); + err_block:='DBOECD_test_remarks_block'; + +insert into staging2.DBOECD_test_remarks_block +( +remarks , +parameter , +acceptance_criteria, +observations +) +select column3,column13,column15,column23 from staging2.stg_process_table_dboecd_test b +where b.block_tag='DBOECD_test_remarks' +and block_row_number>3 and block_row_number<=5; + + +execute 'update staging2.DBOECD_test_remarks_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBOECD_test_remarks_block set client_id='||p_client_id||''; + execute 'update staging2.DBOECD_test_remarks_block set function_id='||p_function_id||''; + execute 'update staging2.DBOECD_test_remarks_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.DBOECD_test_remarks_block set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.DBOECD_test_remarks_block set make=__make; + update staging2.DBOECD_test_remarks_block set model=__model; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'DBOECD_test_remarks_block'); + +/*DBOECD_test_remarks_footer_block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBOECD_test_remarks_footer_block',__file_mnemonic,__file_sheet_mnemonic,24); + err_block:='DBOECD_test_remarks_footer_block'; + +insert into staging2.DBOECD_test_remarks_footer_block(dummy_f) values ('dummy'); + +update staging2.DBOECD_test_remarks_footer_block a +set prepared_by=( select column7 from staging2.stg_process_table_dboecd_test b +where b.block_tag='DBOECD_test_remarks' +and trim(column3)='Prepared by' ) +where dummy_F='dummy'; + +update staging2.DBOECD_test_remarks_footer_block a +set approved_by=( select column7 from staging2.stg_process_table_dboecd_test b +where b.block_tag='DBOECD_test_remarks' +and trim(column3)='Approved by' ) +where dummy_F='dummy'; + +update staging2.DBOECD_test_remarks_footer_block a +set comments=( select column3 from staging2.stg_process_table_dboecd_test b +where b.block_tag='DBOECD_test_remarks' +and block_row_number=9 ) +where dummy_F='dummy'; + +update staging2.DBOECD_test_remarks_footer_block a +set rev1=( select column3 from staging2.stg_process_table_dboecd_test b +where b.block_tag='DBOECD_test_remarks' +and block_row_number=10 ) +where dummy_F='dummy'; + + +update staging2.DBOECD_test_remarks_footer_block a +set rev2=( select column9 from staging2.stg_process_table_dboecd_test b +where b.block_tag='DBOECD_test_remarks' +and block_row_number=10 ) +where dummy_F='dummy'; + +update staging2.DBOECD_test_remarks_footer_block a +set rev3=( select column18 from staging2.stg_process_table_dboecd_test b +where b.block_tag='DBOECD_test_remarks' +and block_row_number=10 ) +where dummy_F='dummy'; + +update staging2.DBOECD_test_remarks_footer_block a +set replaces=( select column23 from staging2.stg_process_table_dboecd_test b +where b.block_tag='DBOECD_test_remarks' +and block_row_number=6) +where dummy_F='dummy'; + +update staging2.DBOECD_test_remarks_footer_block a +set revision_no=( select column23 from staging2.stg_process_table_dboecd_test b +where b.block_tag='DBOECD_test_remarks' +and block_row_number=7) +where dummy_F='dummy'; + +update staging2.DBOECD_test_remarks_footer_block a +set date=( select column19 from staging2.stg_process_table_dboecd_test b +where b.block_tag='DBOECD_test_remarks' +and block_row_number=6) +where dummy_F='dummy'; + +update staging2.DBOECD_test_remarks_footer_block a +set date=( select column19 from staging2.stg_process_table_dboecd_test b +where b.block_tag='DBOECD_test_remarks' +and block_row_number=7 and column9 is not null) +where dummy_F='dummy'; + + +execute 'update staging2.DBOECD_test_remarks_footer_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBOECD_test_remarks_footer_block set client_id='||p_client_id||''; + execute 'update staging2.DBOECD_test_remarks_footer_block set function_id='||p_function_id||''; + execute 'update staging2.DBOECD_test_remarks_footer_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.DBOECD_test_remarks_footer_block set file_mnemonic='''||p_file_mnemonic||''''; + update staging2.DBOECD_test_remarks_footer_block set make=__make; + update staging2.DBOECD_test_remarks_footer_block set model=__model; +perform fw_core.fn_jobctl_block_end(__file_syspk,'DBOECD_test_remarks_footer_block'); + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_dboecd_test_block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; diff --git a/onetime/dataloadfunctions/Drawbar/DBSTD_TEST_ods.sql b/onetime/dataloadfunctions/Drawbar/DBSTD_TEST_ods.sql new file mode 100755 index 0000000..e5d30f0 --- /dev/null +++ b/onetime/dataloadfunctions/Drawbar/DBSTD_TEST_ods.sql @@ -0,0 +1,862 @@ +drop function if exists staging2.fn_dbstd_test_trx; +CREATE OR REPLACE FUNCTION staging2.fn_dbstd_test_trx(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS text AS $$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __test_instance_tractor_id int; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + begin + +/************************************************************ +Function Name:fn_dbstd_test_trx +Function Desc: This function populates data into ODS +File Format: DBSTD +Sheet Format: DBSTD_TEST +Creation Date: March 25 2021 +Updation Date: +Author: compegence team +Function Call: select staging.fn_dbstd_test_trx() +***************************************************************/ + + +SET search_path TO staging2; +select syspk from transactional.test_master into __test_master_id where test_type ='Drawbar'; + +/* ODS */ +insert into transactional.test_instance +( +client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +job_order_no, +sample_receipt_date, +test_report_no, +generation, +customer_name, +test_engineer, +test_report_date, +no_of_sample, +test_start_date, +test_end_date, +tractor_sr_no, +test_standard_ref, +test_location_name, +test_operator, +project_group, +acceptance_criteria, +objective_of_test, +date_of_test, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +file_syspk, +make, +model, +test_request_no, +date '1899-12-30' + sample_receipt_date::numeric * interval '1' day as sample_receipt_date , +test_report_no, +generation, +customer_name, +test_engineer, +date '1899-12-30' + test_report_date::numeric * interval '1' day as test_report_date , +no_of_sample, +date '1899-12-30' + test_start_date::numeric* interval '1' day as test_start_date , +date '1899-12-30' + test_end_date::numeric* interval '1' day as test_end_date , +tractor_sr_no, +test_standard_refer, +test_location, +operator_name, +project_group, +objective, +acceptance_criteria, +current_date, +file_mnemonic, +file_sheet_mnemonic +from +staging2.dbstd_test_h1_block; + +update transactional.test_instance a +set test_condition=b.c2 +from staging2.dbstd_test_test_condition_block b +where a.file_syspk=b.file_syspk; + +update transactional.test_instance +set test_file_name =(select a.file_name from staging1.staging_generic_table a where file_syspk = __file_syspk limit 1) +where file_syspk = __file_syspk; + + +/* ODS */ + +insert into transactional.test_instance_engine_info +(client_id,function_id,file_syspk,tractor_model,tractor_make,low_idle_declared,low_idle_observed,high_idle_declared,high_idle_observed,file_mnemonic, +file_sheet_mnemonic) +select client_id,function_id,file_syspk,make,model,low_idle_declared,low_idle_observed::numeric,high_idle_declared,high_idle_observed::numeric,file_mnemonic,file_sheet_mnemonic +from staging2.DBSTD_test_engine_RPM_RPM_block; + +update transactional.test_instance_engine_info a +set engine_to_pto_ratio_540_pto=b.engine_to_pto_ratio::numeric,engine_power_hp = b.engine_power_hp::numeric, +pto_power_hp = b.pto_power_hp::numeric +from +staging2.dbstd_test_engine_rpm_engine_to_pto_block b +where a.file_syspk=b.file_syspk; + +update transactional.test_instance_engine_info a +set engine_cylinder_stroke_mm=b.stroke::numeric,engine_cylinder_bore_mm=b.bore::numeric,engine_cylinder_no=b.number::numeric, +engine_cylinder_capacity_ltr=regexp_replace(b.capacity,'[^0-9]', '', 'g')::int +from staging2.dbstd_test_tractor_specifications_cylinders_block b +where a.file_syspk=b.file_syspk; + +update transactional.test_instance_engine_info a +set engine_serial_no=serial_no,engine_type=type,rated_rpm=rated_speed::numeric,engine_make=b.make_in_block ,engine_model = b.model_in_block +from staging2.dbstd_test_tractor_specifications_engine_details_block b +where a.file_syspk=b.file_syspk; + +/*ODS */ +insert into transactional.test_instance_tractor_info +( +client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +wheel_base_mm, +tractor_engine_hp, +pto_power_hp, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +file_syspk, +make, +model, +wheel_base_mm::numeric, +engine_power_hp::numeric, +pto_power_hp::numeric, +file_mnemonic, +file_sheet_mnemonic +from dbstd_test_engine_rpm_engine_to_pto_block; + +update transactional.test_instance_tractor_info a +set +steering_type=b.steering_type, +transmission_type=clutch_type, +transmission_disc_diam=diameter_of_disc_mm +from staging2.dbstd_test_transmission_clutch_block b +where a.file_syspk=b.file_syspk; + +/*ODS */ +insert into transactional.test_instance_drawbar_info +( +client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +drawbar_type, +required_pull_in_kg, +actual_pull_in_kg, +required_power_in_hp, +actual_power_in_hp, +calculated_hitch_height_mm, +actual_hitch_height_mm, +file_mnemonic, +file_sheet_mnemonic +) + +select +client_id, +function_id, +file_syspk, +make, +model, +pull_type, +required_pull_in_kg::numeric , +actual_pull_in_kg::numeric , +required_power_in_hp::numeric, +actual_power_in_hp::numeric , +calculated_hitch_height_mm::numeric, +actual_hitch_height_mm::numeric , +file_mnemonic, +file_sheet_mnemonic +from + staging2.dbstd_test_engine_rpm_required_pull_block; + +update transactional.test_instance_drawbar_info a +set weight_front_kg = front::numeric , +weight_rear_kg = rear::numeric , +weight_total_kg = total::numeric +from staging2.dbstd_test_engine_rpm_weight_block b +where b.weight_kg='Unballast' +and a.drawbar_type='UB' +and a.file_syspk=b.file_syspk; + + +update transactional.test_instance_drawbar_info a +set weight_front_kg = front::numeric , +weight_rear_kg = rear::numeric , +weight_total_kg = total::numeric +from staging2.dbstd_test_engine_rpm_weight_block b +where b.weight_kg='Ballast' +and a.drawbar_type='B' +and a.file_syspk=b.file_syspk; + +update transactional.test_instance_drawbar_info a +set test_condition=b.test_condition, +drawbar_type_info=b.type, +height_above_ground_max_mm=b.height_above_ground_max_mm::numeric, +height_above_ground_min_mm=b.height_above_ground_min_mm::numeric, +position_related_to_pto=b.position_related_to_pto, +wheel_base=b.wheel_base +from staging2.dbstd_test_transmission_drawbar_block b +where a.drawbar_type=b.test_condition +and a.file_syspk=b.file_syspk; + +update transactional.test_instance_drawbar_info set drawbar_type_name='UnBallasted' where drawbar_type='UB'; +update transactional.test_instance_drawbar_info set drawbar_type_name='Ballasted' where drawbar_type='B'; + +/* ODS */ +insert into transactional.test_instance_tyre_info +( +client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +tyre_type, +tyre_make, +tyre_size, +tyre_ply_rating, +tyre_load_carrying_capacity, +tyre_pressure_kg_per_cm2, +tyre_number_of_lug, +tyre_number_of_no_load_lug_30m, +tyre_lug_height, +tyre_dynamic_rolling_radius_mm, +tyre_wheel_rim_make_and_size, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +file_syspk, +make, +model, +dummy_f, +tyre_make, +size, +ply_rating::numeric, +load_carrying_capacity_in_kg, +pressure_kg_cm2::numeric, +number_of_lug::numeric, +number_of_no_load_lug_30m::numeric, +lug_height::numeric, +dynamic_rolling_radius_mm::numeric, +wheel_rim_make_size , +file_mnemonic, +file_sheet_mnemonic +from staging2.DBSTD_test_engine_RPM_tyre_details_block ; + +/* ODS */ + +insert into transactional.drawbar_perf_results_summary + ( +client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +gear_number_and_range, +travel_speed_km_per_hr, +drawbar_power_kw, +drawbar_power_hp, +drawbar_pull_kgf, +drawbar_pull_kn, +engine_speed_min_1, +fan_speed_min_1, +wheel_slip_pct_front, +no_of_load_lugs_front, +wheel_slip_pct_rear, +fuel_consumption_l_per_h, +fuel_consumption_kg_per_kwh, +fuel_consumption_g_per_kwh, +fuel_consumption_kwh_per_l, +temp_engine_oil_c, +temp_trans_oil_c, +temp_coolant_c, +temp_fuel_in_c, +temp_fuel_out_c, +atm_conditions_rh_pct, +atm_conditions_temp_c, +atm_conditions_pressure_kpa, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +file_syspk, +make, +model, +c1, +c2::numeric, +c3::numeric, +c4::numeric, +c5::numeric, +c6::numeric, +c7::numeric, +c8::numeric, +c9::numeric, +c10::numeric, +c11::numeric, +c12::numeric, +c13::numeric, +c14::numeric, +c15::numeric, +c16::numeric, +c17::numeric, +c18::numeric, +c19::numeric, +c20::numeric, +c21::numeric, +c22::numeric, +c23::numeric, +file_mnemonic, +file_sheet_mnemonic +from staging2.dbstd_test_drawbar_performance_selected_summary_block; + +/* ODS */ +insert into transactional.drawbar_perf_results +(client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +gear_number_and_range, +travel_speed_km_per_hr, +drawbar_power_kw, +drawbar_power_hp, +drawbar_pull_kgf, +drawbar_pull_kn, +engine_speed_min_1, +fan_speed_min_1, +wheel_slip_pct_front, +no_of_load_lugs_front, +wheel_slip_pct_rear, +fuel_consumption_l_per_h, +fuel_consumption_kg_per_kwh, +fuel_consumption_g_per_kwh, +fuel_consumption_kwh_per_l, +temp_engine_oil_c, +temp_trans_oil_c, +temp_coolant_c, +temp_fuel_in_c, +temp_fuel_out_c, +atm_conditions_rh_pct, +atm_conditions_temp_c, +atm_conditions_pressure_kpa, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +file_syspk, +make, +model, +c1, +c2::numeric, +c3::numeric, +c4::numeric, +c5::numeric, +c6::numeric, +c7::numeric, +c8::numeric, +c9::numeric, +c10::numeric, +c11::numeric, +c12::numeric, +c13::numeric, +c14::numeric, +c15::numeric, +c16::numeric, +c17::numeric, +c18::numeric, +c19::numeric, +c20::numeric, +c21::numeric, +c22::numeric, +c23::numeric, +file_mnemonic, +file_sheet_mnemonic +from staging2.dbstd_test_drawbar_performance_gear_performance_block; + +/* ODS */ +insert into transactional.test_instance_equipment_info +(client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +srl_no,instrument_name,instrument_serial_no,calibration_due_date,file_mnemonic, +file_sheet_mnemonic) +select +client_id, +function_id, +file_syspk, +make, +model, +s_no::numeric, +instruments, +instruments_no, +date '1899-12-30' + cali_due_date::numeric * interval '1' day as cali_due_date , +file_mnemonic, +file_sheet_mnemonic +from staging2.DBSTD_test_test_equipment_used_block; + +/* ODS */ +insert into transactional.test_instance_measurement_uncertainty +( +client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +load_cell, +rpm_meter, +speed, +fuel_flow_meter, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +file_syspk, +make, +model, +load_cell, +rpm_meter, +speed, +fuel_flow_meter , +file_mnemonic, +file_sheet_mnemonic +from +staging2.dbstd_test_measurement_uncertainty_block; + +/* ODS */ +insert into transactional.test_instance_tractor_info_misc +( +client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +capacity_of_fuel_tank_ltr, +make_type_and_model_of_injection_pump, +manufacturers_production_setting, +make_type_and_model_of_injectors, +make_type_and_model_of_magneto_coil_and_distributor, +make_type_and_model_of_carburetor, +ignition_or_injection_timing, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +file_syspk, +make, +model, +regexp_replace(capacity_of_fuel_tank_lit,'[^0-9]', '', 'g')::numeric, +make_type_and_model_of_injection_pump, +manufacturer_production_setting, +make_type_and_model_of_injectors, +make_type_and_model_of_magneto_coil_and_distributor, +make_type_and_model_of_carburetor, +ignition_or_injection_timing_manual_or_automatic, +file_mnemonic, +file_sheet_mnemonic +from +staging2.dbstd_test_tractor_specifications_fuel_and_injection_block; + + +update transactional.test_instance_tractor_info_misc a +set aircleaner_make_model=b.make_and_model +from staging2.dbstd_test_tractor_specifications_cleaner_block b +where b.cleaner_type='Air cleaner' +and a.file_syspk=b.file_syspk; + + +update transactional.test_instance_tractor_info_misc a +set aircleaner_type=b.type +from staging2.dbstd_test_tractor_specifications_cleaner_block b +where cleaner_type='Air cleaner' +and a.file_syspk=b.file_syspk; + + +update transactional.test_instance_tractor_info_misc a +set precleaner_make_model=b.make_and_model +from staging2.dbstd_test_tractor_specifications_cleaner_block b +where cleaner_type='Precleaner (if fitted)' +and a.file_syspk=b.file_syspk; + +update transactional.test_instance_tractor_info_misc a +set precleaner_type=b.type +from staging2.dbstd_test_tractor_specifications_cleaner_block b +where cleaner_type='Precleaner (if fitted)' +and a.file_syspk=b.file_syspk; + + +update staging2.dbstd_test_transmission_speed_chart_block a +set tyre_condition=b.descr +from staging2.dbstd_test_transmission_speed_chart_desc_block b +where a.file_syspk=b.file_syspk; + +/* ODS */ + +insert into transactional.test_instance_gear_speed_chart +( +client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +forward_reverse, +gear, +speed_kmph, +tyre_condition, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +file_syspk, +make, +model, +'forward', +gear, +cast(coalesce(nullif(forward,''),'0') as numeric), +tyre_condition, +file_mnemonic, +file_sheet_mnemonic +from +staging2.dbstd_test_transmission_speed_chart_block; + +/* ODs */ +insert into transactional.test_instance_gear_speed_chart +( +client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +forward_reverse, +gear, +speed_kmph, +tyre_condition, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +file_syspk, +make, +model, +'reverse', +gear, +cast(coalesce(nullif(reverse,''),'0') as numeric), +tyre_condition, +file_mnemonic, +file_sheet_mnemonic +from +staging2.dbstd_test_transmission_speed_chart_block; + +/* ODS */ +insert into transactional.Test_instance_wheels_info +(client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +steered_driving_wheel, +location_of_driving_wheel, +make_of_tyres, +wheel_types, +wheel_size, +maximum_permissible_load_kg, +ply_rating, +track_width_max_mm, +track_width_min_mm, +inflation_pressure_kg_per_cm2, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +file_syspk, +make, +model, +dummy_f, +location_of_driving_wheel, +make_of_tyres, +types, +size, +regexp_replace(maximum_permissible_load_kg,'[^0-9]', '', 'g')::int, +regexp_replace(ply_rating,'[^0-9]', '', 'g')::int, +track_width_max_mm::numeric, +track_width_min_mm::numeric, +inflation_pressure_kg_cm2::numeric, + file_mnemonic, +file_sheet_mnemonic +from staging2.dbstd_test_transmission_wheels_block; + +update staging2.dbstd_test_transmission_wheels_block a +set location_of_driving_wheel=(select location_of_driving_wheel from +staging2.dbstd_test_transmission_wheels_block b where location_of_driving_wheel is not null) +where location_of_driving_wheel is null; + +/* ODS */ +insert into transactional.Test_instance_fuel_lubricant_info +( +client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +trade_name, +fuel_lubricant_type, +octane_per_cetane_number, +viscocity, +density_at_15c, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +file_syspk, +make, +model, +trade_name, +type, +octane_cetane_number::numeric, +viscosity, +density_at_15c, +file_mnemonic, +file_sheet_mnemonic +from +staging2.dbstd_test_transmission_fuel_lubricant_block ; + +/* ODS */ +insert into transactional.drawbar_perf_observations +( +client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +test_parameter , +acceptance_criteria , +observation , +remarks , +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +file_syspk, +make, +model, +parameter, +acceptance_criteria , +observations, +remarks , +file_mnemonic, +file_sheet_mnemonic +from staging2.dbstd_test_remarks_block; + +update transactional.test_instance a +set +report_prepared_by=b.prepared_by, +report_reviewed_by=b.reviewed_by, +report_approved_by=b.approved_by, +report_template_replaces=b.replaces, +report_template_rev_no=b.revision_no, +report_template_rev_Date=b.rev3, +report_template_no=b.rev1, +report_title=b.comments, +test_master_id = __test_master_id +from staging2.dbstd_test_remarks_footer_block b +where a.file_syspk=b.file_syspk; + +select file_syspk into __file_syspk from staging2.dbstd_test_h1_block; +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk; + +update transactional.test_instance a +set +report_prepared_by=b.prepared_by, +report_reviewed_by=b.reviewed_by, +report_approved_by=b.approved_by, +report_template_replaces=b.replaces, +report_template_rev_no=b.revision_no, +report_template_rev_Date=b.rev3, +report_template_no=b.rev1, +report_title=b.comments, +test_tractor_id = __test_instance_tractor_id, +test_master_id = __test_master_id +from staging2.dbstd_test_remarks_footer_block b +where a.file_syspk=b.file_syspk; + + +update transactional.test_instance_engine_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_drawbar_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.test_instance_tyre_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.drawbar_perf_results_summary +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.drawbar_perf_results +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.test_instance_equipment_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.test_instance_measurement_uncertainty +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.test_instance_tractor_info_misc +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.test_instance_gear_speed_chart +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.Test_instance_wheels_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.Test_instance_fuel_lubricant_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.drawbar_perf_observations +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + + +update transactional.drawbar_perf_observations +set test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.drawbar_perf_results_summary +set test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.drawbar_perf_results +set test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_engine_info +set test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_drawbar_info +set test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.test_instance_tyre_info +set test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_equipment_info +set test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.test_instance_measurement_uncertainty +set test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.test_instance_tractor_info_misc +set test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.test_instance_gear_speed_chart +set test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.Test_instance_wheels_info +set test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.Test_instance_fuel_lubricant_info +set test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + + +err_context := ''; +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_DBSTD_test_block', err_state, err_msg, err_detail, err_hint, err_context,'success'); +return err_context; + +EXCEPTION when OTHERS then + +GET STACKED DIAGNOSTICS + err_state = returned_sqlstate, + err_msg = message_text, + err_detail = pg_exception_detail, + err_hint = pg_exception_hint, + err_context = pg_exception_context; + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_DBSTD_test_block', err_state, err_msg, err_detail, err_hint, err_context,'error'); +return err_context; + +end +$$ LANGUAGE plpgsql; + diff --git a/onetime/dataloadfunctions/Drawbar/DBSTD_TEST_stg2.sql b/onetime/dataloadfunctions/Drawbar/DBSTD_TEST_stg2.sql new file mode 100755 index 0000000..b6795f7 --- /dev/null +++ b/onetime/dataloadfunctions/Drawbar/DBSTD_TEST_stg2.sql @@ -0,0 +1,1358 @@ +drop function if exists staging2.fn_dbstd_test_block; +CREATE OR REPLACE FUNCTION staging2.fn_dbstd_test_block(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS text AS $$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare err_block text; + + begin + +/************************************************************ +Function Name:fn_dbstd_test_block +Function Desc: This function populates data into staging 2 block +File Format: DBSTD +Sheet Format: DBSTD_TEST +Creation Date: March 25 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_dbstd_test_block(p_client_id,p_function_id, p_file_mnemonic, +p_file_sheet_mnemonic, p_file_syspk) +Function call ex: select staging2.fn_dbstd_test_block(1,2,'DBSTD','DBSTD_TEST',262) +***************************************************************/ + + +SET search_path TO staging2; + +/* to process multiple files - re-runnability*/ + +truncate table staging2.dbstd_test_transmission_wheels_int; +truncate table staging2.dbstd_test_h1_int; +truncate table staging2.dbstd_test_engine_rpm_engine_to_pto_block; +truncate table staging2.dbstd_test_engine_rpm_required_pull_block; +truncate table staging2.dbstd_test_engine_rpm_weight_block; +truncate table staging2.dbstd_test_engine_rpm_tyre_details_block; +truncate table staging2.DBSTD_test_engine_RPM_tyre_details_int; +truncate table staging2.dbstd_test_test_condition_block; +truncate table staging2.dbstd_test_drawbar_performance_selected_summary_block; +truncate table staging2.dbstd_test_drawbar_performance_gear_performance_block; +truncate table staging2.dbstd_test_test_equipment_used_block; +truncate table staging2.dbstd_test_measurement_uncertainty_block; +truncate table staging2.dbstd_test_tractor_specifications_engine_details_block; +truncate table staging2.dbstd_test_tractor_specifications_cylinders_block; +truncate table staging2.dbstd_test_tractor_specifications_fuel_and_injection_block; +truncate table staging2.dbstd_test_tractor_specifications_cleaner_block; +truncate table staging2.dbstd_test_transmission_clutch_block; +truncate table staging2.dbstd_test_transmission_drawbar_block; +truncate table staging2.dbstd_test_transmission_speed_chart_desc_block; +truncate table staging2.dbstd_test_transmission_wheels_block; +truncate table staging2.dbstd_test_transmission_fuel_lubricant_int; +truncate table staging2.dbstd_test_remarks_block; +truncate table staging2.dbstd_test_remarks_footer_block; +truncate table staging2.dbstd_test_h1_block; +truncate table staging2.dbstd_test_transmission_fuel_lubricant_block; +truncate table staging2.dbstd_test_engine_rpm_rpm_block; +truncate table staging2.dbstd_test_transmission_speed_chart_block; +truncate table staging2.stg_specific_table_dbstd_test; +truncate table staging2.stg_process_table_dbstd_test; + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/*run specific data */ +execute 'insert into staging2.stg_specific_table_dbstd_test +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + + +/* standardizing keywords */ +update staging2.stg_specific_table_dbstd_test set column3='Remarks' where column3 like 'Remarks%'; +update staging2.stg_specific_table_dbstd_test set column15='Objective' where column15 like 'Objective%'; + +update staging2.stg_specific_table_dbstd_test set column3 = TRIM (TRAILING FROM column3 ); +update staging2.stg_specific_table_dbstd_test set column3 = TRIM (LEADING FROM column3 ); + +/* To process repeated keywords */ +update transactional.source_config set F1_modified = TRIM (TRAILING FROM F1_modified) ; +update transactional.source_config set F1_modified = TRIM (LEADING FROM F1_modified) ; +update transactional.source_config set F1_source=F1_modified ; +update transactional.source_config set F1_source = TRIM (TRAILING FROM F1_source); +update transactional.source_config set F1_source = TRIM (LEADING FROM F1_source); + +/*updating row numbers in source_config table*/ +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_dbstd_test b +where trim(upper(F1_modified))=trim(upper(column3)) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update staging2.stg_specific_table_dbstd_test a +set is_rownumber_fetched=1 +from transactional.source_config b +where trim(upper(F1_modified))=trim(upper(column3)) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* update null for the last keyword as read end beacause of overlap of multiple formats*/ +execute 'update transactional.source_config a +set row_read_end = null ,run_time=current_timestamp +where f1_modified =''Remarks'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers*/ + +execute 'insert into staging2.stg_process_table_dbstd_test +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_dbstd_test a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Request no.'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_dbstd_test +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag from staging2.stg_specific_table_dbstd_test a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Engine (RPM)'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_dbstd_test +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag from staging2.stg_specific_table_dbstd_test a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test condition'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_dbstd_test +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag from staging2.stg_specific_table_dbstd_test a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Drawbar Performance Test Results (Selected Summary)'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_dbstd_test +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_dbstd_test a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Drawbar Performance Test Results (Gear Performance Test)'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'insert into staging2.stg_process_table_dbstd_test +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_dbstd_test a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test equipments used'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'insert into staging2.stg_process_table_dbstd_test +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_dbstd_test a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Tractor specification'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_dbstd_test +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_dbstd_test a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Transmission'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'insert into staging2.stg_process_table_dbstd_test +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_dbstd_test a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Remarks'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/*selecting tactor make*/ +select column6 into __make from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_tractor_specifications' and trim(column4)='Make' ; + +select column6 into __model from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_Test_H1' and trim(column3) = 'Tractor Model'; + +/*block starts - DBSTD_TEST_H1_BLOCK */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBSTD_TEST_H1_BLOCK',__file_mnemonic,__file_sheet_mnemonic,1); + +insert into staging2.DBSTD_TEST_H1_INT (c1,c2) +select a.column3,column6 from staging2.stg_process_table_dbstd_test a where block_tag='DBSTD_Test_H1'; + +insert into staging2.DBSTD_TEST_H1_INT (c1,c2) +select a.column9,column12 from staging2.stg_process_table_dbstd_test a where block_tag='DBSTD_Test_H1'; + +insert into staging2.DBSTD_TEST_H1_INT (c1,c2) +select 'Objective',column15 +from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_Test_H1' +and row_number= +( +select row_number+1 from +staging2.stg_process_table_dbstd_test a +where column15='Objective' +and block_tag='DBSTD_Test_H1' +); + +insert into staging2.DBSTD_TEST_H1_INT (c1,c2) +select 'Acceptance criteria',column15 +from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_Test_H1' +and row_number= +( +select row_number+1 from +staging2.stg_process_table_dbstd_test a +where column15='Acceptance criteria' +and block_tag='DBSTD_Test_H1' +); + +insert into staging2.DBSTD_TEST_H1_Block +( +dummy_f, +Test_Request_no, +Sample_Receipt_Date, +Test_report_No, +Tractor_Model, +Generation, +Customer_Name, +Test_Engineer, +Test_Report_Date, +No_of_Sample, +Test_Start_Date, +Test_End_Date, +Tractor_Sr_No, +Test_Standard_Refer, +Test_Location, +Operator_Name, +Project_Group, +Objective, +Acceptance_criteria +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{c2}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[c2::text]) AS val + FROM staging2.DBSTD_TEST_H1_INT + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text, + a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text); + + + delete from staging2.DBSTD_TEST_H1_Block where dummy_f is null ; + execute 'update staging2.DBSTD_TEST_H1_Block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBSTD_TEST_H1_Block set client_id='||p_client_id||''; + execute 'update staging2.DBSTD_TEST_H1_Block set function_id='||p_function_id||''; + update staging2.DBSTD_TEST_H1_Block set make=__make; + update staging2.DBSTD_TEST_H1_Block set model=__model; + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBSTD_TEST_H1_BLOCK'); + + /* block DBSTD_test_engine_RPM_RPM_block */ + perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBSTD_test_engine_RPM_RPM_block',__file_mnemonic,__file_sheet_mnemonic,2); + +insert into staging2.DBSTD_test_engine_RPM_RPM_block(dummy_f) values ('dummy'); + +update staging2.DBSTD_test_engine_RPM_RPM_block +set low_idle_declared=(select column6 from +staging2.stg_process_table_dbstd_test where block_row_number=2 and column3='Low Idle RPM' and block_tag='DBSTD_test_engine_RPM') +where dummy_f='dummy'; + +update staging2.DBSTD_test_engine_RPM_RPM_block +set low_idle_observed=(select column8 from +staging2.stg_process_table_dbstd_test where block_row_number=2 and column3='Low Idle RPM' and block_tag='DBSTD_test_engine_RPM') +where dummy_f='dummy'; + +update staging2.DBSTD_test_engine_RPM_RPM_block +set high_idle_declared=(select column6 from +staging2.stg_process_table_dbstd_test where block_row_number=3 and column3='High Idle RPM' and block_tag='DBSTD_test_engine_RPM') +where dummy_f='dummy'; + +update staging2.DBSTD_test_engine_RPM_RPM_block +set high_idle_observed=(select column8 from +staging2.stg_process_table_dbstd_test where block_row_number=3 and column3='High Idle RPM' and block_tag='DBSTD_test_engine_RPM') +where dummy_f='dummy'; + + +execute 'update staging2.DBSTD_test_engine_RPM_RPM_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBSTD_test_engine_RPM_RPM_block set client_id='||p_client_id||''; + execute 'update staging2.DBSTD_test_engine_RPM_RPM_block set function_id='||p_function_id||''; + update staging2.DBSTD_test_engine_RPM_RPM_block set make=__make; + update staging2.DBSTD_test_engine_RPM_RPM_block set model=__model; + + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBSTD_test_engine_RPM_RPM_block'); + + /* block DBSTD_test_engine_RPM_engine_to_PTO_block*/ + + perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'dbstd_test_engine_rpm_engine_to_pto_block',__file_mnemonic,__file_sheet_mnemonic,3); +insert into staging2.DBSTD_test_engine_RPM_engine_to_PTO_block(dummy_f) values ('dummy'); + + +update staging2.DBSTD_test_engine_RPM_engine_to_PTO_block set rated_speed= +(select column6 from staging2.stg_process_table_dbstd_test a +where a.block_tag='DBSTD_test_engine_RPM' +and block_row_number=4 ) +where dummy_f='dummy'; + +update staging2.DBSTD_test_engine_RPM_engine_to_PTO_block set engine_to_PTO_ratio= +(select column6 from staging2.stg_process_table_dbstd_test a +where a.block_tag='DBSTD_test_engine_RPM' +and block_row_number=5 ) +where dummy_f='dummy'; + +update staging2.DBSTD_test_engine_RPM_engine_to_PTO_block set wheel_base_mm= +(select column6 from staging2.stg_process_table_dbstd_test a +where a.block_tag='DBSTD_test_engine_RPM' +and block_row_number=6 ) +where dummy_f='dummy'; + + +update staging2.DBSTD_test_engine_RPM_engine_to_PTO_block set engine_power_hp= +(select column6 from staging2.stg_process_table_dbstd_test a +where a.file_mnemonic='DBSTD' and a.file_sheet_mnemonic='DBSTD_TEST' and a.block_tag='DBSTD_test_engine_RPM' +and block_row_number=7 ) +where dummy_f='dummy'; + +update staging2.DBSTD_test_engine_RPM_engine_to_PTO_block set PTO_Power_hp= +(select column6 from staging2.stg_process_table_dbstd_test a +where a.file_mnemonic='DBSTD' and a.file_sheet_mnemonic='DBSTD_TEST' and a.block_tag='DBSTD_test_engine_RPM' +and block_row_number=8 ) +where dummy_f='dummy'; + + +execute 'update staging2.DBSTD_test_engine_RPM_engine_to_PTO_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBSTD_test_engine_RPM_engine_to_PTO_block set client_id='||p_client_id||''; + execute 'update staging2.DBSTD_test_engine_RPM_engine_to_PTO_block set function_id='||p_function_id||''; + update staging2.DBSTD_test_engine_RPM_engine_to_PTO_block set make=__make; + update staging2.DBSTD_test_engine_RPM_engine_to_PTO_block set model=__model; + + perform fw_core.fn_jobctl_block_end(__file_syspk,'dbstd_test_engine_rpm_engine_to_pto_block'); + +/* block DBSTD_test_engine_RPM_required_pull_block */ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBSTD_test_engine_RPM_required_pull_block',__file_mnemonic,__file_sheet_mnemonic,4); + +insert into staging2.DBSTD_test_engine_RPM_required_pull_block ( pull_type) values ('UB'), ('B'); + +update staging2.DBSTD_test_engine_RPM_required_pull_block +set required_pull_in_kg=(select column7 from staging2.stg_process_table_dbstd_test a +where a.block_tag='DBSTD_test_engine_RPM' +and column3='Required pull in (kg)') +where pull_type='UB'; + +update staging2.DBSTD_test_engine_RPM_required_pull_block +set required_pull_in_kg=(select column9 from staging2.stg_process_table_dbstd_test a +where a.block_tag='DBSTD_test_engine_RPM' +and column3='Required pull in (kg)') +where pull_type='B'; + +update staging2.DBSTD_test_engine_RPM_required_pull_block +set required_power_in_hp=(select column7 from staging2.stg_process_table_dbstd_test a +where a.block_tag='DBSTD_test_engine_RPM' +and column3='Required Power in hp') +where pull_type='UB'; + +update staging2.DBSTD_test_engine_RPM_required_pull_block +set required_power_in_hp=(select column9 from staging2.stg_process_table_dbstd_test a +where a.block_tag='DBSTD_test_engine_RPM' +and column3='Required Power in hp') +where pull_type='B'; + +update staging2.DBSTD_test_engine_RPM_required_pull_block +set actual_pull_in_kg=(select column7 from staging2.stg_process_table_dbstd_test a +where a.block_tag='DBSTD_test_engine_RPM' +and column3='Actual pull in (kg)') +where pull_type='UB'; + +update staging2.DBSTD_test_engine_RPM_required_pull_block +set actual_pull_in_kg=(select column9 from staging2.stg_process_table_dbstd_test a +where a.block_tag='DBSTD_test_engine_RPM' +and column3='Actual pull in (kg)') +where pull_type='B'; + +update staging2.DBSTD_test_engine_RPM_required_pull_block +set actual_power_in_hp=(select column7 from staging2.stg_process_table_dbstd_test a +where a.block_tag='DBSTD_test_engine_RPM' +and column3='actual power in hp') +where pull_type='UB'; + +update staging2.DBSTD_test_engine_RPM_required_pull_block +set actual_power_in_hp=(select column9 from staging2.stg_process_table_dbstd_test a +where a.block_tag='DBSTD_test_engine_RPM' +and column3='actual power in hp') +where pull_type='B'; + +update staging2.DBSTD_test_engine_RPM_required_pull_block +set calculated_hitch_height_mm=(select column7 from staging2.stg_process_table_dbstd_test a +where a.block_tag='DBSTD_test_engine_RPM' +and column3='Calculated hitch height (mm)') +where pull_type='UB'; + +update staging2.DBSTD_test_engine_RPM_required_pull_block +set calculated_hitch_height_mm=(select column9 from staging2.stg_process_table_dbstd_test a +where a.block_tag='DBSTD_test_engine_RPM' +and column3='Calculated hitch height (mm)') +where pull_type='B'; + +update staging2.DBSTD_test_engine_RPM_required_pull_block +set actual_hitch_height_mm=(select column7 from staging2.stg_process_table_dbstd_test a +where a.block_tag='DBSTD_test_engine_RPM' +and column3='Actual hitch height (mm)') +where pull_type='UB'; + +update staging2.DBSTD_test_engine_RPM_required_pull_block +set actual_hitch_height_mm=(select column9 from staging2.stg_process_table_dbstd_test a +where a.block_tag='DBSTD_test_engine_RPM' +and column3='Actual hitch height (mm)') +where pull_type='B'; + + +execute 'update staging2.DBSTD_test_engine_RPM_required_pull_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBSTD_test_engine_RPM_required_pull_block set client_id='||p_client_id||''; + execute 'update staging2.DBSTD_test_engine_RPM_required_pull_block set function_id='||p_function_id||''; + update staging2.DBSTD_test_engine_RPM_required_pull_block set make=__make; + update staging2.DBSTD_test_engine_RPM_required_pull_block set model=__model; + + + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBSTD_test_engine_RPM_required_pull_block'); + + /* block DBSTD_test_engine_RPM_weight_block */ + perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBSTD_test_engine_RPM_weight_block',__file_mnemonic,__file_sheet_mnemonic,5); + +insert into staging2.DBSTD_test_engine_RPM_weight_block( +weight_kg , +Front , +rear , +Total +) +select column10,column13,column17,column22 from staging2.stg_process_table_dbstd_test a +where a.block_tag='DBSTD_test_engine_RPM' +and block_row_number in(2,3); + + +execute 'update staging2.DBSTD_test_engine_RPM_weight_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBSTD_test_engine_RPM_weight_block set client_id='||p_client_id||''; + execute 'update staging2.DBSTD_test_engine_RPM_weight_block set function_id='||p_function_id||''; + update staging2.DBSTD_test_engine_RPM_weight_block set make=__make; + update staging2.DBSTD_test_engine_RPM_weight_block set model=__model; +perform fw_core.fn_jobctl_block_end(__file_syspk,'DBSTD_test_engine_RPM_weight_block'); + +/*block - rpm tyre details block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBSTD_test_engine_RPM_tyre_details_block',__file_mnemonic,__file_sheet_mnemonic,6); + +insert into staging2.DBSTD_test_engine_RPM_tyre_details_int +( s_no,tyre_details,front,rear) + +select column10,column11,column15,column20 +from staging2.stg_process_table_dbstd_test a +where a.block_tag='DBSTD_test_engine_RPM' +and block_row_number >=5 and block_row_number<=14; + + +execute 'update staging2.DBSTD_test_engine_RPM_tyre_details_int set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBSTD_test_engine_RPM_tyre_details_int set client_id='||p_client_id||''; + execute 'update staging2.DBSTD_test_engine_RPM_tyre_details_int set function_id='||p_function_id||''; + update staging2.DBSTD_test_engine_RPM_tyre_details_int set make=__make; + update staging2.DBSTD_test_engine_RPM_tyre_details_int set model=__model; + +insert into staging2.DBSTD_test_engine_RPM_tyre_details_block +( +dummy_f, +tyre_Make, +size, +Ply_Rating, +Load_Carrying_Capacity_in_Kg, +Pressure_kg_cm2, +Number_of_lug, +Number_of_no_load_lug_30m, +Lug_Height, +Dynamic_rolling_radius_mm, +Wheel_Rim_Make_Size +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{front,rear}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[front::text,rear::text]) AS val + FROM staging2.DBSTD_test_engine_RPM_tyre_details_int + ORDER BY generate_series(1,15),2' + ) t ( col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text + ,a_10 text); + + delete from staging2.DBSTD_test_engine_RPM_tyre_details_block where dummy_f is null; + +execute 'update staging2.DBSTD_test_engine_RPM_tyre_details_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBSTD_test_engine_RPM_tyre_details_block set client_id='||p_client_id||''; + execute 'update staging2.DBSTD_test_engine_RPM_tyre_details_block set function_id='||p_function_id||''; + update staging2.DBSTD_test_engine_RPM_tyre_details_block set make=__make; + update staging2.DBSTD_test_engine_RPM_tyre_details_block set model=__model; + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBSTD_test_engine_RPM_tyre_details_block'); + + /* block DBSTD_test_test_condition_block */ + perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBSTD_test_test_condition_block',__file_mnemonic,__file_sheet_mnemonic,7); + +insert into staging2.DBSTD_test_test_condition_block(c1,c2,c3) +select column3 c1,column10 c2,column15 c3 +from staging2.stg_process_table_dbstd_test a +where a.block_tag='DBSTD_test_test_condition'; + + +execute 'update staging2.DBSTD_test_test_condition_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBSTD_test_test_condition_block set client_id='||p_client_id||''; + execute 'update staging2.DBSTD_test_test_condition_block set function_id='||p_function_id||''; + update staging2.DBSTD_test_test_condition_block set make=__make; + update staging2.DBSTD_test_test_condition_block set model=__model; + +update staging2.dbstd_test_test_condition_block +set c3='B' +where c2='Ballasted'; + +update staging2.dbstd_test_test_condition_block +set c3='UB' +where c2='Un-ballasted'; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'DBSTD_test_test_condition_block'); + +/* block DBSTD_test_drawbar_performance_selected_summary_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBSTD_test_drawbar_performance_selected_summary_block',__file_mnemonic,__file_sheet_mnemonic,8); + +insert into staging2.DBSTD_test_drawbar_performance_selected_summary_block(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16,c17,c18,c19,c20,c21,c22,c23,c24,c25) +select column3 c1, +column4 c2, +column5 c3, +column6 c4, +column7 c5, +column8 c6, +column9 c7, +column10 c8, +column11 c9, +column12 c10, +column13 c11, +column14 c12, +column15 c13, +column16 c14, +column17 c15, +column18 c16, +column19 c17, +column20 c18, +column21 c19, +column22 c20, +column23 c21, +column24 c22, +column25 c23, +column26 c24, +column27 c25 +from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_drawbar_performance_selected_summary' +and block_row_number>3; + + +execute 'update staging2.DBSTD_test_drawbar_performance_selected_summary_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBSTD_test_drawbar_performance_selected_summary_block set client_id='||p_client_id||''; + execute 'update staging2.DBSTD_test_drawbar_performance_selected_summary_block set function_id='||p_function_id||''; + update staging2.DBSTD_test_drawbar_performance_selected_summary_block set make=__make; + update staging2.DBSTD_test_drawbar_performance_selected_summary_block set model=__model; + + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBSTD_test_drawbar_performance_selected_summary_block'); + +/* block DBSTD_test_drawbar_performance_gear_performance_block */ + + /* DBSTD_test_drawbar_performance_gear_performance_block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBSTD_test_drawbar_performance_gear_performance_block',__file_mnemonic,__file_sheet_mnemonic,9); + +insert into staging2.DBSTD_test_drawbar_performance_gear_performance_block (c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16,c17,c18,c19,c20,c21,c22,c23,c24,c25) +select column3 c1, +column4 c2, +column5 c3, +column6 c4, +column7 c5, +column8 c6, +column9 c7, +column10 c8, +column11 c9, +column12 c10, +column13 c11, +column14 c12, +column15 c13, +column16 c14, +column17 c15, +column18 c16, +column19 c17, +column20 c18, +column21 c19, +column22 c20, +column23 c21, +column24 c22, +column25 c23, +column26 c24, +column27 c25 +from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_drawbar_performance_gear_performance' +and block_row_number>3; + + +execute 'update staging2.DBSTD_test_drawbar_performance_gear_performance_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBSTD_test_drawbar_performance_gear_performance_block set client_id='||p_client_id||''; + execute 'update staging2.DBSTD_test_drawbar_performance_gear_performance_block set function_id='||p_function_id||''; + update staging2.DBSTD_test_drawbar_performance_gear_performance_block set make=__make; + update staging2.DBSTD_test_drawbar_performance_gear_performance_block set model=__model; + + + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBSTD_test_drawbar_performance_gear_performance_block'); + +/* block DBSTD_test_test_equipment_used_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBSTD_test_test_equipment_used_block',__file_mnemonic,__file_sheet_mnemonic,10); + + insert into staging2.DBSTD_test_test_equipment_used_block( s_no,instruments,instruments_no,cali_due_date) +select column3,column4,column8,column12 +from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_test_equipment' +and block_row_number>2; + + + +execute 'update staging2.DBSTD_test_test_equipment_used_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBSTD_test_test_equipment_used_block set client_id='||p_client_id||''; + execute 'update staging2.DBSTD_test_test_equipment_used_block set function_id='||p_function_id||''; + update staging2.DBSTD_test_test_equipment_used_block set make=__make; + update staging2.DBSTD_test_test_equipment_used_block set model=__model; + + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBSTD_test_test_equipment_used_block'); + +/* block DBSTD_test_measurement_uncertainty_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBSTD_test_measurement_uncertainty_block',__file_mnemonic,__file_sheet_mnemonic,11); + +insert into staging2.DBSTD_test_measurement_uncertainty_block(dummy_f) values ('dummy'); + +update staging2.DBSTD_test_measurement_uncertainty_block set load_cell= +(select column20 from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_test_equipment' and trim(column15)='Load cell'); + +update staging2.DBSTD_test_measurement_uncertainty_block set rpm_meter= +(select column20 from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_test_equipment' and trim(column15)='RPM Meter'); + +update staging2.DBSTD_test_measurement_uncertainty_block set speed= +(select column20 from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_test_equipment' and trim(column15)='Speed'); + + +update staging2.DBSTD_test_measurement_uncertainty_block set fuel_flow_meter= +(select column20 from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_test_equipment' and trim(column15)='Fuel Flow meter'); + + + +execute 'update staging2.DBSTD_test_measurement_uncertainty_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBSTD_test_measurement_uncertainty_block set client_id='||p_client_id||''; + execute 'update staging2.DBSTD_test_measurement_uncertainty_block set function_id='||p_function_id||''; + update staging2.DBSTD_test_measurement_uncertainty_block set make=__make; + update staging2.DBSTD_test_measurement_uncertainty_block set model=__model; + + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBSTD_test_measurement_uncertainty_block'); + + /* block DBSTD_test_tractor_specifications_engine_details_block */ + + /*tractor_specifications_engine_details_block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBSTD_test_tractor_specifications_engine_details_block',__file_mnemonic,__file_sheet_mnemonic,12); + +insert into staging2.DBSTD_test_tractor_specifications_engine_details_block(dummy_f) +values ('dummy'); + +update staging2.DBSTD_test_tractor_specifications_engine_details_block +set make_in_block=(select column6 from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_tractor_specifications' +and trim(column4)='Make' +) +where dummy_f is not null; + + +update staging2.DBSTD_test_tractor_specifications_engine_details_block +set type=(select column6 from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_tractor_specifications' +and trim(column4)='Type' +) +where dummy_f is not null; + +update staging2.DBSTD_test_tractor_specifications_engine_details_block +set model_in_block=(select column6 from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_tractor_specifications' +and trim(column4)='Model' +) +where dummy_f is not null; + + +update staging2.DBSTD_test_tractor_specifications_engine_details_block +set serial_no=(select column6 from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_tractor_specifications' +and trim(column4)='Serial No' +) +where dummy_f is not null; + + +update staging2.DBSTD_test_tractor_specifications_engine_details_block +set E_P_ratio=(select column6 from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_tractor_specifications' +and trim(column4)='E P Ratio' +) +where dummy_f is not null; + +update staging2.DBSTD_test_tractor_specifications_engine_details_block +set rated_speed=(select column6 from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_tractor_specifications' +and trim(column4)='Rated Speed' +) +where dummy_f is not null; + +update staging2.DBSTD_test_tractor_specifications_engine_details_block +set high_idle=(select column6 from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_tractor_specifications' +and trim(column4)='High Idle' +) +where dummy_f is not null; + +update staging2.DBSTD_test_tractor_specifications_engine_details_block +set high_idle=(select column6 from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_tractor_specifications' +and trim(column4)='High Idle' +) +where dummy_f is not null; + +update staging2.DBSTD_test_tractor_specifications_engine_details_block +set low_idle=(select column8 from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_tractor_specifications' +and trim(column4)='High Idle' +) +where dummy_f is not null; + + +execute 'update staging2.DBSTD_test_tractor_specifications_engine_details_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBSTD_test_tractor_specifications_engine_details_block set client_id='||p_client_id||''; + execute 'update staging2.DBSTD_test_tractor_specifications_engine_details_block set function_id='||p_function_id||''; + + + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBSTD_test_tractor_specifications_engine_details_block'); + + /* block DBSTD_test_tractor_specifications_cylinders_block */ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBSTD_test_tractor_specifications_cylinders_block',__file_mnemonic,__file_sheet_mnemonic,13); + +insert into staging2.DBSTD_test_tractor_specifications_cylinders_block(dummy_f) +values ('dummy'); + +update staging2.DBSTD_test_tractor_specifications_cylinders_block +set number=(select column11 from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_tractor_specifications' +and trim(column9)='Number' +) +where dummy_f is not null; + +update staging2.DBSTD_test_tractor_specifications_cylinders_block +set stroke=(select column11 from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_tractor_specifications' +and trim(column9)='Stroke' +) +where dummy_f is not null; + +update staging2.DBSTD_test_tractor_specifications_cylinders_block +set bore=(select column11 from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_tractor_specifications' +and trim(column9)='Bore' +) +where dummy_f is not null; + +update staging2.DBSTD_test_tractor_specifications_cylinders_block +set capacity=(select column11 from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_tractor_specifications' +and trim(column9)='Capacity' +) +where dummy_f is not null; + + +execute 'update staging2.DBSTD_test_tractor_specifications_cylinders_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBSTD_test_tractor_specifications_cylinders_block set client_id='||p_client_id||''; + execute 'update staging2.DBSTD_test_tractor_specifications_cylinders_block set function_id='||p_function_id||''; + update staging2.DBSTD_test_tractor_specifications_cylinders_block set make=__make; + update staging2.DBSTD_test_tractor_specifications_cylinders_block set model=__model; + + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBSTD_test_tractor_specifications_cylinders_block'); + +/*block fuel_and_injection_block*/ + perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBSTD_test_tractor_specifications_fuel_and_injection_block',__file_mnemonic,__file_sheet_mnemonic,14); + +insert into staging2.DBSTD_test_tractor_specifications_fuel_and_injection_block(dummy_f) +values ('dummy'); + +update staging2.DBSTD_test_tractor_specifications_fuel_and_injection_block +set Make_type_and_model_of_injection_pump=(select column17 from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_tractor_specifications' +and trim(column12)='Make, type and model of injection pump' +) +where dummy_f is not null; + +update staging2.DBSTD_test_tractor_specifications_fuel_and_injection_block +set capacity_of_fuel_tank_lit=(select column17 from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_tractor_specifications' +and trim(column12)='Capacity of fuel tank lit' +) +where dummy_f is not null; + +update staging2.DBSTD_test_tractor_specifications_fuel_and_injection_block +set Make_type_and_model_of_injection_pump=(select column17 from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_tractor_specifications' +and trim(column12)='Make, type and model of injection pump' +) +where dummy_f is not null; + +update staging2.DBSTD_test_tractor_specifications_fuel_and_injection_block +set Manufacturer_production_setting=(select column17 from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_tractor_specifications' +and trim(column12)='Manufacturers production setting' +) +where dummy_f is not null; + +update staging2.DBSTD_test_tractor_specifications_fuel_and_injection_block +set Make_type_and_model_of_injectors=(select column17 from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_tractor_specifications' +and trim(column12)='Make, type and model of injectors' +) +where dummy_f is not null; + +update staging2.DBSTD_test_tractor_specifications_fuel_and_injection_block +set Make_type_and_model_of_magneto_coil_and_distributor=(select column17 from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_tractor_specifications' +and trim(column12)='Make, type and model of magneto, coil and distributor' +) +where dummy_f is not null; + +update staging2.DBSTD_test_tractor_specifications_fuel_and_injection_block +set Make_type_and_model_of_carburetor=(select column17 from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_tractor_specifications' +and trim(column12)='Make, type and model of carburetor' +) +where dummy_f is not null; + +update staging2.DBSTD_test_tractor_specifications_fuel_and_injection_block +set Ignition_or_injection_timing_Manual_or_automatic=(select column17 from staging2.stg_process_table_dbstd_test a +where block_tag='DBSTD_test_tractor_specifications' +and trim(column12)='Ignition or injection timing (Manual or automatic)' +) +where dummy_f is not null; + + +execute 'update staging2.DBSTD_test_tractor_specifications_fuel_and_injection_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBSTD_test_tractor_specifications_fuel_and_injection_block set client_id='||p_client_id||''; + execute 'update staging2.DBSTD_test_tractor_specifications_fuel_and_injection_block set function_id='||p_function_id||''; + update staging2.DBSTD_test_tractor_specifications_fuel_and_injection_block set make=__make; + update staging2.DBSTD_test_tractor_specifications_fuel_and_injection_block set model=__model; + + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBSTD_test_tractor_specifications_fuel_and_injection_block'); + + /*tractor_specifications_cleaner_block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBSTD_test_tractor_specifications_cleaner_block',__file_mnemonic,__file_sheet_mnemonic,15); + +insert into staging2.DBSTD_test_tractor_specifications_cleaner_block(cleaner_type) +values ('Air cleaner'),('Precleaner (if fitted)'); + +update staging2.DBSTD_test_tractor_specifications_cleaner_block +set type= +(select column23 from staging2.stg_process_table_dbstd_test a where + block_tag='DBSTD_test_tractor_specifications' +and column21='Type' and block_row_number=5) +where cleaner_type='Air cleaner'; + +update staging2.DBSTD_test_tractor_specifications_cleaner_block +set type= +(select column23 from staging2.stg_process_table_dbstd_test a where +block_tag='DBSTD_test_tractor_specifications' +and column21='Type' and block_row_number=9) +where cleaner_type='Precleaner (if fitted)'; + + +execute 'update staging2.DBSTD_test_tractor_specifications_cleaner_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBSTD_test_tractor_specifications_cleaner_block set client_id='||p_client_id||''; + execute 'update staging2.DBSTD_test_tractor_specifications_cleaner_block set function_id='||p_function_id||''; + update staging2.DBSTD_test_tractor_specifications_cleaner_block set make=__make; + update staging2.DBSTD_test_tractor_specifications_cleaner_block set model=__model; + + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBSTD_test_tractor_specifications_cleaner_block'); + + + /*transmission_clutch_block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBSTD_test_transmission_clutch_block',__file_mnemonic,__file_sheet_mnemonic,16); + +insert into staging2.DBSTD_test_transmission_clutch_block(dummy_f) values ('dummy'); + + +update staging2.DBSTD_test_transmission_clutch_block a +set clutch_type=( +select column6 from staging2.stg_process_table_dbstd_test b +where b.column3='Type' and block_row_number=2 and b.block_tag='DBSTD_test_transmission') +where dummy_F='dummy'; + +update staging2.DBSTD_test_transmission_clutch_block a +set steering_type=( +select column6 from staging2.stg_process_table_dbstd_test b +where b.column3='Type' and block_row_number=5 and b.block_tag='DBSTD_test_transmission') +where dummy_F='dummy'; + +update staging2.DBSTD_test_transmission_clutch_block a +set diameter_of_disc_mm=( +select column6 from staging2.stg_process_table_dbstd_test b +where trim(b.column3)='Diameter of disc, mm' and b.block_tag='DBSTD_test_transmission') +where dummy_F='dummy'; + + +execute 'update staging2.DBSTD_test_transmission_clutch_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBSTD_test_transmission_clutch_block set client_id='||p_client_id||''; + execute 'update staging2.DBSTD_test_transmission_clutch_block set function_id='||p_function_id||''; + update staging2.DBSTD_test_transmission_clutch_block set make=__make; + update staging2.DBSTD_test_transmission_clutch_block set model=__model; + + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBSTD_test_transmission_clutch_block'); + + /*transmission_drawbar_block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBSTD_test_transmission_drawbar_block',__file_mnemonic,__file_sheet_mnemonic,17); + +insert into staging2.DBSTD_test_transmission_drawbar_block(dummy_f) values ('dummy'); + +update staging2.DBSTD_test_transmission_drawbar_block a +set type=( +select column8 from staging2.stg_process_table_dbstd_test b +where trim(b.column3)='Type' and block_row_number=7 and b.block_tag='DBSTD_test_transmission') +where dummy_F='dummy'; + +update staging2.DBSTD_test_transmission_drawbar_block a +set Height_above_ground_max_mm=( +select column8 from staging2.stg_process_table_dbstd_test b +where trim(b.column3)='Height above ground (max) mm' and block_row_number=9 and b.block_tag='DBSTD_test_transmission') +where dummy_F='dummy'; + +update staging2.DBSTD_test_transmission_drawbar_block a +set Height_above_ground_max_mm=( +select column8 from staging2.stg_process_table_dbstd_test b +where trim(b.column3)='Height above ground (max) mm' and block_row_number=9 and b.block_tag='DBSTD_test_transmission') +where dummy_F='dummy'; + +update staging2.DBSTD_test_transmission_drawbar_block a +set Height_above_ground_min_mm=( +select column8 from staging2.stg_process_table_dbstd_test b +where trim(b.column3)='Height above ground (min) mm' and block_row_number=11 and b.block_tag='DBSTD_test_transmission') +where dummy_F='dummy'; + +update staging2.DBSTD_test_transmission_drawbar_block a +set Position_related_to_PTO=( +select column8 from staging2.stg_process_table_dbstd_test b +where trim(b.column3)='Position related to PTO' and block_row_number=13 and b.block_tag='DBSTD_test_transmission') +where dummy_F='dummy'; + +update staging2.DBSTD_test_transmission_drawbar_block a +set Wheel_Base=( +select column8 from staging2.stg_process_table_dbstd_test b +where trim(b.column3)='Wheel Base' and block_row_number=15 and b.block_tag='DBSTD_test_transmission') +where dummy_F='dummy'; + + + +execute 'update staging2.DBSTD_test_transmission_drawbar_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBSTD_test_transmission_drawbar_block set client_id='||p_client_id||''; + execute 'update staging2.DBSTD_test_transmission_drawbar_block set function_id='||p_function_id||''; + update staging2.DBSTD_test_transmission_drawbar_block set make=__make; + update staging2.DBSTD_test_transmission_drawbar_block set model=__model; + + +update staging2.dbstd_test_transmission_drawbar_block a +set test_condition=b.c3 +from staging2.dbstd_test_test_condition_block b +where a.file_syspk=b.file_syspk; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'DBSTD_test_transmission_drawbar_block'); + +/*transmission_speed_chart_desc_block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBSTD_test_transmission_speed_chart_desc_block',__file_mnemonic,__file_sheet_mnemonic,18); + +insert into staging2.DBSTD_test_transmission_speed_chart_desc_block +( +descr) +select column10 +from +staging2.stg_process_table_dbstd_test b +where b.block_tag='DBSTD_test_transmission' +and block_row_number=1; + + +execute 'update staging2.DBSTD_test_transmission_speed_chart_desc_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBSTD_test_transmission_speed_chart_desc_block set client_id='||p_client_id||''; + execute 'update staging2.DBSTD_test_transmission_speed_chart_desc_block set function_id='||p_function_id||''; + update staging2.DBSTD_test_transmission_speed_chart_desc_block set make=__make; + update staging2.DBSTD_test_transmission_speed_chart_desc_block set model=__model; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'DBSTD_test_transmission_speed_chart_desc_block'); + +/*transmission_speed_chart_desc_block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBSTD_test_transmission_speed_chart_block',__file_mnemonic,__file_sheet_mnemonic,19); + +insert into staging2.DBSTD_test_transmission_speed_chart_block +(gear,forward,reverse) +select column10,column11, column13 from +staging2.stg_process_table_dbstd_test b +where b.block_tag='DBSTD_test_transmission' +and block_row_number>=3; + +update staging2.dbstd_test_transmission_speed_chart_block a +set reverse= b.first_value from (SELECT + syspk, reverse, value_partition, first_value(reverse) over (partition by value_partition order by syspk) +FROM ( + SELECT + syspk, + reverse, + sum(case when reverse is null then 0 else 1 end) over (order by syspk) as value_partition + FROM staging2.dbstd_test_transmission_speed_chart_block + ORDER BY syspk ASC +) as q) b where a.syspk = b.syspk; + + +execute 'update staging2.dbstd_test_transmission_speed_chart_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.dbstd_test_transmission_speed_chart_block set client_id='||p_client_id||''; + execute 'update staging2.dbstd_test_transmission_speed_chart_block set function_id='||p_function_id||''; + update staging2.dbstd_test_transmission_speed_chart_block set make=__make; + update staging2.dbstd_test_transmission_speed_chart_block set model=__model; + delete from staging2.dbstd_test_transmission_speed_chart_block where gear is null; + + + perform fw_core.fn_jobctl_block_end(__file_syspk,'DBSTD_test_transmission_speed_chart_block'); + +/*transmission_wheels_in*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBSTD_test_transmission_wheels_block',__file_mnemonic,__file_sheet_mnemonic,20); + + +insert into staging2.DBSTD_test_transmission_wheels_int(Descriptions,Steered_wheels,Driving_wheel) +select column15,column20,column23 from staging2.stg_process_table_dbstd_test b +where b.block_tag='DBSTD_test_transmission' +and block_row_number>=3 and block_row_number<=11 order by block_row_number; + +update staging2.DBSTD_test_transmission_wheels_int +set Driving_wheel=Steered_wheels +where trim(Descriptions)='Location of driving wheel' +and Driving_wheel =''; + +execute 'update staging2.DBSTD_test_transmission_wheels_int set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBSTD_test_transmission_wheels_int set client_id='||p_client_id||''; + execute 'update staging2.DBSTD_test_transmission_wheels_int set function_id='||p_function_id||''; + update staging2.DBSTD_test_transmission_wheels_int set make=__make; + update staging2.DBSTD_test_transmission_wheels_int set model=__model; + + +insert into staging2.dbstd_test_transmission_wheels_block + ( + dummy_f, + Location_of_driving_wheel, +Make_of_tyres, +types, +size, +Maximum_permissible_load_kg, +Ply_rating, +Track_width_max_mm, +Track_width_min_mm, +Inflation_pressure_kg_cm2 + + ) + SELECT * +FROM crosstab( + 'SELECT unnest(''{steered_wheels,driving_wheel}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[steered_wheels::text,driving_wheel::text]) AS val + FROM staging2.dbstd_test_transmission_wheels_int + ORDER BY generate_series(1,10),2' + ) t ( col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text); + +delete from dbstd_test_transmission_wheels_block where dummy_f is null; + + +execute 'update staging2.dbstd_test_transmission_wheels_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.dbstd_test_transmission_wheels_block set client_id='||p_client_id||''; + execute 'update staging2.dbstd_test_transmission_wheels_block set function_id='||p_function_id||''; + update staging2.dbstd_test_transmission_wheels_block set make=__make; + update staging2.dbstd_test_transmission_wheels_block set model=__model; + + +insert into staging2.DBSTD_test_transmission_fuel_lubricant_int( Descriptions,Diesel_BS_IV,Engine_oil,Transmission_oil) +select column15,column18,column20,column23 from staging2.stg_process_table_dbstd_test b +where b.block_tag='DBSTD_test_transmission' +and block_row_number>=14 and block_row_number<=18 order by block_row_number; + + +execute 'update staging2.DBSTD_test_transmission_fuel_lubricant_int set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBSTD_test_transmission_fuel_lubricant_int set client_id='||p_client_id||''; + execute 'update staging2.DBSTD_test_transmission_fuel_lubricant_int set function_id='||p_function_id||''; + update staging2.DBSTD_test_transmission_fuel_lubricant_int set make=__make; + update staging2.DBSTD_test_transmission_fuel_lubricant_int set model=__model; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'DBSTD_test_transmission_wheels_block'); + +/*transmission_fuel_lubricant*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBSTD_test_transmission_fuel_lubricant_block',__file_mnemonic,__file_sheet_mnemonic,21); + + +insert into staging2.DBSTD_test_transmission_fuel_lubricant_block + ( + dummy_f, + Trade_name, +type, +Octane_Cetane_number, +Viscosity, +Density_at_15C +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{diesel_bs_iv,engine_oil,transmission_oil}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[diesel_bs_iv::text,engine_oil::text,transmission_oil::text]) AS val + FROM staging2.DBSTD_test_transmission_fuel_lubricant_int + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text); + + delete from DBSTD_test_transmission_fuel_lubricant_block where dummy_f is null; + +execute 'update staging2.DBSTD_test_transmission_fuel_lubricant_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBSTD_test_transmission_fuel_lubricant_block set client_id='||p_client_id||''; + execute 'update staging2.DBSTD_test_transmission_fuel_lubricant_block set function_id='||p_function_id||''; + update staging2.DBSTD_test_transmission_fuel_lubricant_block set make=__make; + update staging2.DBSTD_test_transmission_fuel_lubricant_block set model=__model; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'DBSTD_test_transmission_fuel_lubricant_block'); + +/*DBSTD_test_remarks_block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBSTD_test_remarks_block',__file_mnemonic,__file_sheet_mnemonic,22); + +insert into staging2.DBSTD_test_remarks_block +( +remarks , +parameter , +acceptance_criteria, +observations +) +select column3,column13,column15,column23 from staging2.stg_process_table_dbstd_test b +where b.block_tag='DBSTD_test_remarks' +and block_row_number>3 and block_row_number<=5; + + +execute 'update staging2.DBSTD_test_remarks_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBSTD_test_remarks_block set client_id='||p_client_id||''; + execute 'update staging2.DBSTD_test_remarks_block set function_id='||p_function_id||''; + update staging2.DBSTD_test_remarks_block set make=__make; + update staging2.DBSTD_test_remarks_block set model=__model; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'DBSTD_test_remarks_block'); + +/*DBSTD_test_remarks_footer_block*/ +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'DBSTD_test_remarks_footer_block',__file_mnemonic,__file_sheet_mnemonic,23); + +insert into staging2.DBSTD_test_remarks_footer_block(dummy_f) values ('dummy'); + +update staging2.DBSTD_test_remarks_footer_block a +set prepared_by=( select column7 from staging2.stg_process_table_dbstd_test b +where b.block_tag='DBSTD_test_remarks' +and trim(column3)='Prepared by' ) +where dummy_F='dummy'; + +update staging2.DBSTD_test_remarks_footer_block a +set reviewed_by=( select column7 from staging2.stg_process_table_dbstd_test b +where b.block_tag='DBSTD_test_remarks' +and trim(column3)='Reviewed by' ) +where dummy_F='dummy'; + +update staging2.DBSTD_test_remarks_footer_block a +set approved_by=( select column7 from staging2.stg_process_table_dbstd_test b +where b.block_tag='DBSTD_test_remarks' +and trim(column3)='Approved by' ) +where dummy_F='dummy'; + +update staging2.DBSTD_test_remarks_footer_block a +set comments=( select column3 from staging2.stg_process_table_dbstd_test b +where b.block_tag='DBSTD_test_remarks' +and column3 like 'THIS DOCUMENT%' ) +where dummy_F='dummy'; + +update staging2.DBSTD_test_remarks_footer_block a +set rev1=( select column3 from staging2.stg_process_table_dbstd_test b +where b.block_tag='DBSTD_test_remarks' +and block_row_number=(select block_row_number + 1 from staging2.stg_process_table_dbstd_test b +where b.block_tag='DBSTD_test_remarks' +and column3 like 'THIS DOCUMENT%') ) +where dummy_F='dummy'; + + +update staging2.DBSTD_test_remarks_footer_block a +set rev2=( select column9 from staging2.stg_process_table_dbstd_test b +where b.block_tag='DBSTD_test_remarks' +and block_row_number=(select block_row_number + 1 from staging2.stg_process_table_dbstd_test b +where b.block_tag='DBSTD_test_remarks' +and column3 like 'THIS DOCUMENT%') ) +where dummy_F='dummy'; + +update staging2.DBSTD_test_remarks_footer_block a +set rev3=( select column18 from staging2.stg_process_table_dbstd_test b +where b.block_tag='DBSTD_test_remarks' +and block_row_number=(select block_row_number + 1 from staging2.stg_process_table_dbstd_test b +where b.block_tag='DBSTD_test_remarks' +and column3 like 'THIS DOCUMENT%') ) +where dummy_F='dummy'; + +update staging2.DBSTD_test_remarks_footer_block a +set replaces=( select column23 from staging2.stg_process_table_dbstd_test b +where b.block_tag='DBSTD_test_remarks' +and column23 like 'Replaces%') +where dummy_F='dummy'; + +update staging2.DBSTD_test_remarks_footer_block a +set revision_no=( select column23 from staging2.stg_process_table_dbstd_test b +where b.block_tag='DBSTD_test_remarks' +and column23 like 'Revision%') +where dummy_F='dummy'; + +update staging2.DBSTD_test_remarks_footer_block a +set date=( select column19 from staging2.stg_process_table_dbstd_test b +where b.block_tag='DBSTD_test_remarks' +and block_row_number=(select block_row_number+1 from staging2.stg_process_table_dbstd_test b +where b.block_tag='DBSTD_test_remarks' +and column23 like 'Revision%')) +where dummy_F='dummy'; + +update staging2.DBSTD_test_remarks_footer_block a +set date=( select column19 from staging2.stg_process_table_dbstd_test b +where b.block_tag='DBSTD_test_remarks' +and block_row_number=7 and column9 is not null) +where dummy_F='dummy'; + + +execute 'update staging2.DBSTD_test_remarks_footer_block set file_syspk='||p_file_syspk||''; + execute 'update staging2.DBSTD_test_remarks_footer_block set client_id='||p_client_id||''; + execute 'update staging2.DBSTD_test_remarks_footer_block set function_id='||p_function_id||''; + update staging2.DBSTD_test_remarks_footer_block set make=__make; + update staging2.DBSTD_test_remarks_footer_block set model=__model; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'DBSTD_test_remarks_footer_block'); + +execute 'update dbstd_test_transmission_fuel_lubricant_block set file_mnemonic='''||p_file_mnemonic||''' , file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +execute 'update dbstd_test_h1_block set file_mnemonic='''||p_file_mnemonic||''' , file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +execute 'update dbstd_test_engine_rpm_rpm_block set file_mnemonic='''||p_file_mnemonic||''' , file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +execute 'update dbstd_test_engine_rpm_engine_to_pto_block set file_mnemonic='''||p_file_mnemonic||''' , file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +execute 'update dbstd_test_engine_rpm_required_pull_block set file_mnemonic='''||p_file_mnemonic||''' , file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +execute 'update dbstd_test_engine_rpm_weight_block set file_mnemonic='''||p_file_mnemonic||''' , file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +execute 'update dbstd_test_engine_rpm_tyre_details_block set file_mnemonic='''||p_file_mnemonic||''' , file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +execute 'update dbstd_test_test_condition_block set file_mnemonic='''||p_file_mnemonic||''' , file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +execute 'update dbstd_test_drawbar_performance_selected_summary_block set file_mnemonic='''||p_file_mnemonic||''' , file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +execute 'update dbstd_test_drawbar_performance_gear_performance_block set file_mnemonic='''||p_file_mnemonic||''' , file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +execute 'update dbstd_test_test_equipment_used_block set file_mnemonic='''||p_file_mnemonic||''' , file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +execute 'update dbstd_test_measurement_uncertainty_block set file_mnemonic='''||p_file_mnemonic||''' , file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +execute 'update dbstd_test_tractor_specifications_engine_details_block set file_mnemonic='''||p_file_mnemonic||''' , file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +execute 'update dbstd_test_tractor_specifications_cylinders_block set file_mnemonic='''||p_file_mnemonic||''' , file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +execute 'update dbstd_test_tractor_specifications_fuel_and_injection_block set file_mnemonic='''||p_file_mnemonic||''' , file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +execute 'update dbstd_test_tractor_specifications_cleaner_block set file_mnemonic='''||p_file_mnemonic||''' , file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +execute 'update dbstd_test_transmission_clutch_block set file_mnemonic='''||p_file_mnemonic||''' , file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +execute 'update dbstd_test_transmission_drawbar_block set file_mnemonic='''||p_file_mnemonic||''' , file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +execute 'update dbstd_test_transmission_speed_chart_desc_block set file_mnemonic='''||p_file_mnemonic||''' , file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +execute 'update dbstd_test_transmission_speed_chart_block set file_mnemonic='''||p_file_mnemonic||''' , file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +execute 'update dbstd_test_transmission_wheels_block set file_mnemonic='''||p_file_mnemonic||''' , file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +execute 'update dbstd_test_transmission_fuel_lubricant_block set file_mnemonic='''||p_file_mnemonic||''' , file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +execute 'update dbstd_test_remarks_block set file_mnemonic='''||p_file_mnemonic||''' , file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +execute 'update dbstd_test_remarks_footer_block set file_mnemonic='''||p_file_mnemonic||''' , file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +err_context := ''; +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_DBSTD_test_block', err_state, err_msg, err_detail, err_hint, err_context,'success');return err_context; + +EXCEPTION when OTHERS then + +GET STACKED DIAGNOSTICS + err_state = returned_sqlstate, + err_msg = message_text, + err_detail = pg_exception_detail, + err_hint = pg_exception_hint, + err_context = pg_exception_context; + + perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,err_block,'stg2', 'fn_DBSTD_test_block', err_state, err_msg, err_detail, err_hint, err_context,'error'); +return err_context; +end +$$ LANGUAGE plpgsql; + + + + + + + diff --git a/onetime/dataloadfunctions/IHT/IHTBT30_BT30_ODS.sql b/onetime/dataloadfunctions/IHT/IHTBT30_BT30_ODS.sql new file mode 100755 index 0000000..b0d67a9 --- /dev/null +++ b/onetime/dataloadfunctions/IHT/IHTBT30_BT30_ODS.sql @@ -0,0 +1,459 @@ +drop function if exists staging2.fn_IHTBT30_BT30_TRX; +CREATE OR REPLACE FUNCTION staging2.fn_IHTBT30_BT30_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + declare __test_instance_tractor_id int; + begin +__file_syspk := p_file_syspk; + + +/************************************************************ +Function Name:fn_IHTBT30_BT30_TRX +Function Desc: This function populates data into ODS +File Format: IHT +Sheet Format: IHTBT30_BT30 +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_IHTBT30_BT30_TRX() +***************************************************************/ +insert into transactional.test_instance +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +job_order_no, +sample_receipt_date, +test_report_no, +generation, +customer_name, +test_engineer, +test_report_date, +no_of_sample, +test_start_date, +test_end_date, +tractor_sr_no, +test_standard_ref, +test_location_name, +test_operator, +project_group, +objective_of_test, +test_condition, +test_standard_desc, +test_standard_id, +acceptance_criteria, +remarks, +observations +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +Test_Request_no, +sample_receipt_date::date, +Test_report_No, +Generation, +Customer_Name, +Test_Engineer, +Test_Report_Date::date, +No_of_Sample, +Test_Start_Date::date, +Test_End_Date::date, +Tractor_Sr_No, +Test_Standard_Ref, +test_location, +Operator_Name, +Project_Group, +Objective, +condition, +test_standard, +test_standard_id::numeric, +acceptance_criteria, +remarks, +observations +from +staging2.IHTBT30_BT30_H1_block where trx_record =1; + +update transactional.test_instance a +set +report_prepared_date=to_date(b.prepared_date,'DD-MM-YYYY'), +report_reviewed_date=to_date(b.reviewed_date,'DD-MM-YYYY'), +report_approved_date=to_date(b.approved_date,'DD-MM-YYYY'), +report_prepared_by=b.prepared_by, +report_reviewed_by=b.reviewed_by, +report_approved_by=b.approved_by, +report_template_replaces=b.replaces, +report_title=b.comments, +report_template_no=b.rev1, +report_template_rev_date=b.rev2, +report_template_rev_no= b.rev3 +from staging2.IHTBT30_BT30_footer_block b +where a.file_sheet_mnemonic='IHTBT30_BT30' and trx_record =1; + + + +insert into transactional.test_instance_tyre_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +tyre_type, +tyre_make, +tyre_size, +tyre_ply_rating, +tyre_use_type, +tyre_pressure_kg_per_cm2 +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +tyre_details, +tyre_make, +tyre_size, +ply_rating::numeric, +tyre_use_type, +pressure_kg_cm2::numeric +from staging2.IHTBT30_BT30_tyre_details_block where trx_record =1; + + +insert into transactional.test_instance_drawbar_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +weight_front_kg, +weight_rear_kg, +weight_total_kg +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +test_condition, +front::numeric , +rear::numeric , +total::numeric +from staging2.IHTBT30_BT30_weight_block where trx_record =1; + + +/*block */ + +insert into transactional.test_instance_tractor_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +tractor_platform +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +platform +from staging2.IHTBT30_BT30_h1_block where trx_record =1; + +update transactional.test_instance_tractor_info +set mahindra_model_yn = ( +case when tractor_make like 'Mahindra%' then 'Y' else 'N' end +) where file_syspk =__file_syspk; + +update transactional.test_instance_tractor_info a +set test_tractor_yn ='Y' where syspk in +(select min(syspk) from transactional.test_instance_tractor_info b +where b.file_syspk =a.file_syspk) +and a.file_syspk =__file_syspk; + + + +insert into transactional.iht_brake_perf_test_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +srl_no, +trigger_speed_km_per_h, +brake_control_input_force_kg, +required_corrected_stopping_distance_m, +actual_stopping_distance_m, +deceleration_m_s2_v2_2s, +observation, +test_mode +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column2, +column3::numeric, +column4::numeric, +column5::numeric, +column6::numeric, +column7::numeric, +column8::numeric, +column9, +column10 +from staging2.IHTBT30_BT30_test_res_1_block where trx_record =1; + +insert into transactional.iht_brake_perf_test_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +srl_no, +trigger_speed_km_per_h, +brake_control_input_force_kg, +required_corrected_stopping_distance_m, +actual_stopping_distance_m, +deceleration_m_s2_v2_2s, +observation, +test_mode +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column2, +column3::numeric, +column4::numeric, +column5::numeric, +column6::numeric, +column7::numeric, +column8::numeric, +column9, +column10 +from staging2.IHTBT30_BT30_test_res_2_block where trx_record =1; + +insert into transactional.iht_brake_perf_test_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +srl_no, +trigger_speed_km_per_h, +brake_control_input_force_kg, +required_corrected_stopping_distance_m, +actual_stopping_distance_m, +deceleration_m_s2_v2_2s, +observation, +test_mode +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column2, +column3::numeric, +column4::numeric, +column5::numeric, +column6::numeric, +column7::numeric, +column8::numeric, +column9, +column10 +from staging2.IHTBT30_BT30_test_res_3_block where trx_record =1; + +insert into transactional.iht_brake_perf_test_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +srl_no, +trigger_speed_km_per_h, +brake_control_input_force_kg, +required_corrected_stopping_distance_m, +actual_stopping_distance_m, +deceleration_m_s2_v2_2s, +observation, +test_mode +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column2, +column3::numeric, +column4::numeric, +column5::numeric, +column6::numeric, +column7::numeric, +column8::numeric, +column9, +column10 +from staging2.IHTBT30_BT30_test_res_4_block where trx_record =1; + +insert into transactional.iht_brake_perf_test_condition +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +date_of_test, +time_of_test, +location_name, +test_mode, +wind_velocity_kmph, +ambient_temp_c, +humidity_rh_pct +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make, +model, +condition, +date::date, +time, +location, +mode, +wind_velocity_km_hr, +ambient_temperature_c::numeric , +humidity_rh::numeric +from staging2.IHTBT30_BT30_test_condition_block where trx_record =1; + +update transactional.iht_brake_perf_test_results a +set brake_perf_test_condition_id=(select syspk +from transactional.iht_brake_perf_test_condition b +where a.test_mode =b.test_mode and a.test_condition=b.test_condition and a.file_syspk=b.file_syspk) +where a.file_syspk =__file_syspk; + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk; +select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk; +select syspk from transactional.test_master into __test_master_id where test_type ='In House'; +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk; + + +update transactional.test_instance +set test_master_id =__test_master_id, +test_tractor_id =__test_instance_tractor_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_tyre_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.test_instance_drawbar_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.iht_brake_perf_test_condition +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.iht_brake_perf_test_results +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_IHTBT30_BT30_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + diff --git a/onetime/dataloadfunctions/IHT/IHTBT30_BT30_STG2.sql b/onetime/dataloadfunctions/IHT/IHTBT30_BT30_STG2.sql new file mode 100755 index 0000000..2520e2f --- /dev/null +++ b/onetime/dataloadfunctions/IHT/IHTBT30_BT30_STG2.sql @@ -0,0 +1,908 @@ +drop function if exists staging2.fn_IHTBT30_BT30_block; +CREATE OR REPLACE FUNCTION staging2.fn_IHTBT30_BT30_block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + + begin + +/************************************************************ +Function Name:fn_IHTBT30_BT30_block +Function Desc: This function populates data into staging 2 block +File Format: IHT +Sheet Format: IHTBT30_BT30 +Creation Date: March 25 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_IHTBT30_BT30_block(p_client_id,p_function_id, p_file_mnemonic, +p_file_sheet_mnemonic, p_file_syspk) +Function call ex: select staging2.fn_IHTBT30_BT30_block(1,2,'IHT','IHTBT30_BT30',456) +***************************************************************/ + + +SET search_path TO staging2; + +/* to process multiple files - re-runnability*/ + +truncate table staging2.IHTBT30_BT30_H1_INT; +truncate table staging2.IHTBT30_BT30_H1_block; +truncate table staging2.IHTBT30_BT30_Weight_Tyre_Int; +truncate table staging2.IHTBT30_BT30_Weight_Block; +truncate table staging2.IHTBT30_BT30_Tyre_Details_Block; +truncate table staging2.IHTBT30_BT30_Test_Res_1_Block; +truncate table staging2.IHTBT30_BT30_Test_Res_2_Block; +truncate table staging2.IHTBT30_BT30_Test_Res_3_Block; +truncate table staging2.IHTBT30_BT30_Test_Res_4_Block; +truncate table staging2.IHTBT30_BT30_Test_Condition_Block; +truncate table staging2.IHTBT30_BT30_Footer_Block; +truncate table staging2.stg_specific_table_IHTBT30_BT30; +truncate table staging2.stg_process_table_IHTBT30_BT30; + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* transfer data from generic to specific for IHT */ +execute 'insert into staging2.stg_specific_table_IHTBT30_BT30 +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_IHTBT30_BT30; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for IHTBT30', + detail = 'No data in table stg_specific_table_IHTBT30_BT30', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + +/* trimming data */ +update staging2.stg_specific_table_IHTBT30_BT30 +set column10='Objective' where lower(column10) like 'objective%'; + +update staging2.stg_specific_table_IHTBT30_BT30 +set column10='Acceptance criteria' where lower(column10) like 'acceptance criteria%'; + + +update staging2.stg_specific_table_IHTBT30_BT30 +set column10='Condition' where lower(column10) like 'condition%'; + +update transactional.source_config set F1_source=F1_modified ; + +/* keyword match in config table*/ +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_IHTBT30_BT30 b +where upper(F1_modified)=upper(column3) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update in process table for match*/ +execute 'update staging2.stg_specific_table_IHTBT30_BT30 a +set is_rownumber_fetched=1 +from transactional.source_config b +where upper(F1_modified)=upper(column3) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* update config files for row numbers start, end */ +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a +set row_read_end = null ,run_time=current_timestamp +where f1_modified =''Prepared by'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers*/ +execute 'insert into staging2.stg_process_table_IHTBT30_BT30 +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTBT30_BT30 a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Request No'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTBT30_BT30 +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTBT30_BT30 a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Un-Ballast cold'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTBT30_BT30 +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTBT30_BT30 a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Ballast cold'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTBT30_BT30 +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTBT30_BT30 a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Fade Performance'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTBT30_BT30 +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTBT30_BT30 a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Recovery Performance'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'insert into staging2.stg_process_table_IHTBT30_BT30 +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTBT30_BT30 a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Weight (kg)'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'insert into staging2.stg_process_table_IHTBT30_BT30 +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTBT30_BT30 a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Prepared by'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/*selecting tractor model*/ +select column5 into __model from staging2.stg_process_table_IHTBT30_BT30 a +where block_tag='IHTBT30_BT30_H1' and trim(column3)='Tractor Model'; + +/*block starts - IHTBT30_BT30_H1_BLOCK */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBT30_BT30_H1_BLOCK',__file_mnemonic,__file_sheet_mnemonic,1); +err_block:='IHTBT30_BT30_H1_BLOCK'; +insert into staging2.IHTBT30_BT30_H1_INT (c1,c2) +select a.column3,column5 from staging2.stg_process_table_IHTBT30_BT30 a where block_tag='IHTBT30_BT30_H1' +and block_row_number <=9; + +insert into staging2.IHTBT30_BT30_H1_INT (c1,c2) +select a.column7,column9 from staging2.stg_process_table_IHTBT30_BT30 a where block_tag='IHTBT30_BT30_H1' +and block_row_number <=9; + +insert into staging2.IHTBT30_BT30_H1_INT (c1,c2) +select 'Objective',column10 +from staging2.stg_process_table_IHTBT30_BT30 a +where block_tag='IHTBT30_BT30_H1' +and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTBT30_BT30 a +where column10='Objective' +and block_tag='IHTBT30_BT30_H1' +); + +insert into staging2.IHTBT30_BT30_H1_INT (c1,c2) +select 'Acceptance criteria',column8 +from staging2.stg_process_table_IHTBT30_BT30 a +where block_tag='IHTBT30_BT30_H1' and block_row_number=11; + + +insert into staging2.IHTBT30_BT30_H1_INT (c1,c2) +select 'Condition',column10 +from staging2.stg_process_table_IHTBT30_BT30 a +where block_tag='IHTBT30_BT30_H1' +and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTBT30_BT30 a +where column10='Condition' +and block_tag='IHTBT30_BT30_H1' +); + + + +insert into staging2.IHTBT30_BT30_H1_INT (c1,c2) +select 'Test std',column4 +from staging2.stg_process_table_IHTBT30_BT30 b +where block_row_number=11 +and block_tag='IHTBT30_BT30_H1'; + +insert into staging2.IHTBT30_BT30_H1_INT (c1,c2) +select 'Test std Id',column3 +from staging2.stg_process_table_IHTBT30_BT30 b +where block_row_number=11 +and block_tag='IHTBT30_BT30_H1'; + +insert into staging2.IHTBT30_BT30_H1_INT (c1,c2) +select 'Test Standard ref',split_part(column3,':',2) +from staging2.stg_process_table_IHTBT30_BT30 b +where block_row_number=10 +and block_tag='IHTBT30_BT30_H1'; + + +insert into staging2.IHTBT30_BT30_H1_INT (c1,c2) +select 'Observations',column3 +from staging2.stg_process_table_IHTBT30_BT30 +where block_tag='IHTBT30_BT30_Weight_Tyre' +and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTBT30_BT30 a +where column3='Remarks & Observations' +and block_tag='IHTBT30_BT30_Weight_Tyre' +); + + +update staging2.IHTBT30_BT30_H1_Int set model=__model; +execute 'update staging2.IHTBT30_BT30_H1_Int set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +insert into staging2.IHTBT30_BT30_H1_Block +( +dummy_f, +Test_Request_no, +Sample_Receipt_Date, +Test_report_No, +Tractor_Model, +Generation, +Customer_Name, +Test_Engineer, +Test_Report_Date, +Test_Location, +No_of_Sample, +Test_Start_Date, +Test_End_Date, +Tractor_Sr_No, +Test_Standard_Refer, +Domestic_Export, +Operator_Name, +Project_Group, +Platform, +Objective, +Acceptance_Criteria, +condition, +Test_Standard, +Test_Standard_id, +Test_Standard_ref, +Remarks, +Observations +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{c2}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[c2::text]) AS val + FROM staging2.IHTBT30_BT30_H1_INT + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text, + a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text, + a_18 text,a_19 text,a_20 text,a_21 text,a_22 text,a_23 text,a_24 text,a_25 text,a_26 text); + +update staging2.IHTBT30_BT30_H1_Block + set Sample_Receipt_Date=case + when Sample_Receipt_Date like '%-%' then Sample_Receipt_Date::timestamptz + else date '1899-12-30' + Sample_Receipt_Date::int * interval '1' day + end; + + update staging2.IHTBT30_BT30_H1_Block + set Test_Report_Date=case + when Test_Report_Date like '%-%' then Test_Report_Date::timestamptz + else date '1899-12-30' + Test_Report_Date::int * interval '1' day + end; + + update staging2.IHTBT30_BT30_H1_Block + set Test_Start_Date=case + when Test_Report_Date like '%-%' then Test_Report_Date::timestamptz + else date '1899-12-30' + Test_Report_Date::int * interval '1' day + end; + update staging2.IHTBT30_BT30_H1_Block + set Test_End_Date=case + when Test_Report_Date like '%-%' then Test_Report_Date::timestamptz + else date '1899-12-30' + Test_Report_Date::int * interval '1' day + end; + +delete from staging2.IHTBT30_BT30_H1_Block where dummy_f is null ; +update staging2.IHTBT30_BT30_H1_Block set model=__model; +execute 'update staging2.IHTBT30_BT30_H1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBT30_BT30_H1_BLOCK'); + + +insert into staging2.IHTBT30_BT30_Weight_Tyre_Int +( +column3,column4,column5,column6,column7,column8,column9, +column10,column11,column12,block_row_number +) +select +column3,column4,column5,column6,column7,column8, +column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_IHTBT30_BT30 a +where block_tag='IHTBT30_BT30_Weight_Tyre' +order by block_row_number; + + +update staging2.IHTBT30_BT30_Weight_Tyre_Int set model=__model; +execute 'update staging2.IHTBT30_BT30_Weight_Tyre_Int set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/*block starts - IHTBT30_BT30_Weight_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBT30_BT30_Weight_Block',__file_mnemonic,__file_sheet_mnemonic,2); + err_block:='IHTBT30_BT30_Weight_Block'; +insert into staging2.IHTBT30_BT30_Weight_Block +( +dummy_f, +test_condition, +Front, +Rear, +Total +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column5,column7}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column5::text,column7::text]) AS val + FROM staging2.IHTBT30_BT30_Weight_Tyre_Int where column5 is not null and column7 is not null and block_row_number<>1 + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text); + + +delete from staging2.IHTBT30_BT30_Weight_Block where dummy_f is null ; +update staging2.IHTBT30_BT30_Weight_Block set model=__model; +execute 'update staging2.IHTBT30_BT30_Weight_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBT30_BT30_Weight_Block'); + +/*block starts - IHTBT30_BT30_Tyre_Details_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBT30_BT30_Tyre_Details_Block',__file_mnemonic,__file_sheet_mnemonic,3); +err_block:='IHTBT30_BT30_Tyre_Details_Block'; +insert into staging2.IHTBT30_BT30_Tyre_Details_Block +( +dummy_f, +Tyre_Details, +Pressure_kg_cm2, +tyre_use_type, +Tyre_Make, +tyre_size, +ply_rating +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column10,column11}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column10::text,column11::text]) AS val + FROM staging2.IHTBT30_BT30_Weight_Tyre_Int where column11 is not null or column10 is not null + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text); + + + +delete from staging2.IHTBT30_BT30_Tyre_Details_Block where dummy_f is null ; +update staging2.IHTBT30_BT30_Tyre_Details_Block set model=__model; +execute 'update staging2.IHTBT30_BT30_Tyre_Details_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBT30_BT30_Tyre_Details_Block'); + + +/*block starts - IHTBT30_BT30_Test_Res_1_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBT30_BT30_Test_Res_1_Block',__file_mnemonic,__file_sheet_mnemonic,4); +err_block:='IHTBT30_BT30_Test_Res_1_Block'; + +insert into staging2.IHTBT30_BT30_Test_Res_1_Block +( +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +) +select +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_IHTBT30_BT30 a +where block_tag='IHTBT30_BT30_Test_Res_1' +order by block_row_number; + +update staging2.IHTBT30_BT30_Test_Res_1_Block +set column2=column3 where block_row_number=1; + + + update staging2.IHTBT30_BT30_Test_Res_1_Block a + set column2= b.first_value from (SELECT +block_row_number,column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column2, +sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBT30_BT30_Test_Res_1_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + + update staging2.IHTBT30_BT30_Test_Res_1_Block a + set column10= b.first_value from (SELECT +block_row_number,column10, value_partition, first_value(column10) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column10, +sum(case when column10 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBT30_BT30_Test_Res_1_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + +update staging2.IHTBT30_BT30_Test_Res_1_Block set trx_record =0 where block_row_number in (1,2,3,4); + +update staging2.IHTBT30_BT30_Test_Res_1_Block set trx_record =0 +where column4 is null and column5 is null; + +update staging2.IHTBT30_BT30_Test_Res_1_Block set model=__model; +execute 'update staging2.IHTBT30_BT30_Test_Res_1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBT30_BT30_Test_Res_1_Block'); + + +/*block starts - IHTBT30_BT30_Test_Res_2_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBT30_BT30_Test_Res_2_Block',__file_mnemonic,__file_sheet_mnemonic,5); +err_block:='IHTBT30_BT30_Test_Res_2_Block'; + +insert into staging2.IHTBT30_BT30_Test_Res_2_Block +( +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +) +select +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_IHTBT30_BT30 a +where block_tag='IHTBT30_BT30_Test_Res_2' +order by block_row_number; + +update staging2.IHTBT30_BT30_Test_Res_2_Block +set column2=column3 where block_row_number=1; + + + update staging2.IHTBT30_BT30_Test_Res_2_Block a + set column2= b.first_value from (SELECT +block_row_number,column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number) +FROM ( +select +block_row_number, +column2, +sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBT30_BT30_Test_Res_2_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + + update staging2.IHTBT30_BT30_Test_Res_2_Block a + set column10= b.first_value from (SELECT +block_row_number,column10, value_partition, first_value(column10) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column10, +sum(case when column10 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBT30_BT30_Test_Res_2_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + +update staging2.IHTBT30_BT30_Test_Res_2_Block set trx_record =0 where block_row_number in (1,2,3,4); + +update staging2.IHTBT30_BT30_Test_Res_2_Block set trx_record =0 +where column4 is null and column5 is null; + +update staging2.IHTBT30_BT30_Test_Res_2_Block set model=__model; +execute 'update staging2.IHTBT30_BT30_Test_Res_2_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBT30_BT30_Test_Res_2_Block'); + + +/*block starts - IHTBT30_BT30_Test_Res_3_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBT30_BT30_Test_Res_3_Block',__file_mnemonic,__file_sheet_mnemonic,6); +err_block:='IHTBT30_BT30_Test_Res_3_Block'; + +insert into staging2.IHTBT30_BT30_Test_Res_3_Block +( +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +) +select +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_IHTBT30_BT30 a +where block_tag='IHTBT30_BT30_Test_Res_3' +order by block_row_number; + +update staging2.IHTBT30_BT30_Test_Res_3_Block +set column2=column3 where block_row_number=1; + + + update staging2.IHTBT30_BT30_Test_Res_3_Block a + set column2= b.first_value from (SELECT +block_row_number,column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column2, +sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBT30_BT30_Test_Res_3_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + + update staging2.IHTBT30_BT30_Test_Res_3_Block a + set column10= b.first_value from (SELECT +block_row_number,column10, value_partition, first_value(column10) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column10, +sum(case when column10 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBT30_BT30_Test_Res_3_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + +update staging2.IHTBT30_BT30_Test_Res_3_Block set trx_record =0 where block_row_number in (1,2,3,4); + +update staging2.IHTBT30_BT30_Test_Res_3_Block set trx_record =0 +where column4 is null and column5 is null; + +update staging2.IHTBT30_BT30_Test_Res_3_Block set model=__model; +execute 'update staging2.IHTBT30_BT30_Test_Res_3_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBT30_BT30_Test_Res_3_Block'); + + +/*block starts - IHTBT30_BT30_Test_Res_4_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBT30_BT30_Test_Res_4_Block',__file_mnemonic,__file_sheet_mnemonic,7); +err_block:='IHTBT30_BT30_Test_Res_4_Block'; + +insert into staging2.IHTBT30_BT30_Test_Res_4_Block +( +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +) +select +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_IHTBT30_BT30 a +where block_tag='IHTBT30_BT30_Test_Res_4' +order by block_row_number; + +update staging2.IHTBT30_BT30_Test_Res_4_Block +set column2=column3 where block_row_number=1; + + + update staging2.IHTBT30_BT30_Test_Res_4_Block a + set column2= b.first_value from (SELECT +block_row_number,column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column2, +sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBT30_BT30_Test_Res_4_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + + update staging2.IHTBT30_BT30_Test_Res_4_Block a + set column10= b.first_value from (SELECT +block_row_number,column10, value_partition, first_value(column10) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column10, +sum(case when column10 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBT30_BT30_Test_Res_4_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + +update staging2.IHTBT30_BT30_Test_Res_4_Block set trx_record =0 where block_row_number in (1,2,3,4,15); + +update staging2.IHTBT30_BT30_Test_Res_4_Block set trx_record =0 +where column4 is null and column5 is null; + +update staging2.IHTBT30_BT30_Test_Res_4_Block set model=__model; +execute 'update staging2.IHTBT30_BT30_Test_Res_4_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBT30_BT30_Test_Res_4_Block'); + + +/*block starts - IHTBT30_BT30_Test_Condition_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBT30_BT30_Test_Condition_Block',__file_mnemonic,__file_sheet_mnemonic,8); +err_block:='IHTBT30_BT30_Test_Condition_Block'; + + +insert into staging2.IHTBT30_BT30_Test_Condition_Block (condition) +select column2 from staging2.IHTBT30_BT30_Test_Res_1_Block +where block_row_number=2 +union +select column2 from staging2.IHTBT30_BT30_Test_Res_2_Block +where block_row_number=2 +union +select column2 from staging2.IHTBT30_BT30_Test_Res_3_Block +where block_row_number=2 +union +select column2 from staging2.IHTBT30_BT30_Test_Res_4_Block +where block_row_number=2; + + +update staging2.IHTBT30_BT30_Test_Condition_Block +set date=b.column4, +location=b.column7, +--time=b.column9, +mode=b.column10 +from staging2.IHTBT30_BT30_Test_Res_1_Block b +where b.block_row_number =2 and condition=b.column2; + +update staging2.IHTBT30_BT30_Test_Condition_Block +set Wind_Velocity_Km_hr=b.column5, +Ambient_Temperature_C=b.column7, +Humidity_RH=b.column9 +from staging2.IHTBT30_BT30_Test_Res_1_Block b +where b.block_row_number =3 and condition=b.column2; + +update staging2.IHTBT30_BT30_Test_Condition_Block +set date=b.column4, +location=b.column7, +--time=b.column9, +mode=b.column10 +from staging2.IHTBT30_BT30_Test_Res_2_Block b +where b.block_row_number =2 and condition=b.column2; + +update staging2.IHTBT30_BT30_Test_Condition_Block +set Wind_Velocity_Km_hr=b.column5, +Ambient_Temperature_C=b.column7, +Humidity_RH=b.column9 +from staging2.IHTBT30_BT30_Test_Res_2_Block b +where b.block_row_number =3 and condition=b.column2; + +update staging2.IHTBT30_BT30_Test_Condition_Block +set date=b.column4, +location=b.column7, +--time=b.column9, +mode=b.column10 +from staging2.IHTBT30_BT30_Test_Res_3_Block b +where b.block_row_number =2 and condition=b.column2; + +update staging2.IHTBT30_BT30_Test_Condition_Block +set Wind_Velocity_Km_hr=b.column5, +Ambient_Temperature_C=b.column7, +Humidity_RH=b.column9 +from staging2.IHTBT30_BT30_Test_Res_3_Block b +where b.block_row_number =3 and condition=b.column2; + +update staging2.IHTBT30_BT30_Test_Condition_Block +set date=b.column4, +location=b.column7, +--time=b.column9, +mode=b.column10 +from staging2.IHTBT30_BT30_Test_Res_4_Block b +where b.block_row_number =2 and condition=b.column2; + +update staging2.IHTBT30_BT30_Test_Condition_Block +set Wind_Velocity_Km_hr=b.column5, +Ambient_Temperature_C=b.column7, +Humidity_RH=b.column9 +from staging2.IHTBT30_BT30_Test_Res_4_Block b +where b.block_row_number=3 and condition=b.column2; + + +update staging2.IHTBT30_BT30_Test_Condition_Block a +set date= case + when date like '%-%' then date::timestamptz + else date '1899-12-30' + date::int * interval '1' day + end ; + + +update staging2.IHTBT30_BT30_Test_Condition_Block set model=__model; +execute 'update staging2.IHTBT30_BT30_Test_Condition_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBT30_BT30_Test_Condition_Block'); + +/*block starts - IHTBT30_BT30_Footer_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBT30_BT30_Footer_block',__file_mnemonic,__file_sheet_mnemonic,9); +err_block:='IHTBT30_BT30_Footer_block'; + +insert into staging2.IHTBT30_BT30_Footer_block(dummy_f) values ('dummy'); + + +update staging2.IHTBT30_BT30_Footer_block a +set prepared_by=( select column6 from staging2.stg_process_table_IHTBT30_BT30 b +where b.block_tag='IHTBT30_BT30_Footer' +and lower(column3)='prepared by' ) +where dummy_F='dummy'; + +update staging2.IHTBT30_BT30_Footer_block a +set reviewed_by=( select column6 from staging2.stg_process_table_IHTBT30_BT30 b +where b.block_tag='IHTBT30_BT30_Footer' +and lower(column3)='reviewed by' ) +where dummy_F='dummy'; + +update staging2.IHTBT30_BT30_Footer_block a +set approved_by=( select column6 from staging2.stg_process_table_IHTBT30_BT30 b +where b.block_tag='IHTBT30_BT30_Footer' +and lower(column3)='Approved by' ) +where dummy_F='dummy'; + +update staging2.IHTBT30_BT30_Footer_block a +set comments=( select column3 from staging2.stg_process_table_IHTBT30_BT30 b +where b.block_tag='IHTBT30_BT30_Footer' +and block_row_number=5 ) +where dummy_F='dummy'; + +update staging2.IHTBT30_BT30_Footer_block a +set rev1=( select column3 from staging2.stg_process_table_IHTBT30_BT30 b +where b.block_tag='IHTBT30_BT30_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + + +update staging2.IHTBT30_BT30_Footer_block a +set rev2=( select column7 from staging2.stg_process_table_IHTBT30_BT30 b +where b.block_tag='IHTBT30_BT30_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + +update staging2.IHTBT30_BT30_Footer_block a +set rev3=( select column10 from staging2.stg_process_table_IHTBT30_BT30 b +where b.block_tag='IHTBT30_BT30_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + +update staging2.IHTBT30_BT30_Footer_block a +set replaces=( select column11 from staging2.stg_process_table_IHTBT30_BT30 b +where b.block_tag='IHTBT30_BT30_Footer' +and block_row_number=1) +where dummy_F='dummy'; + +update staging2.IHTBT30_BT30_Footer_block a +set revision_no=( select column11 from staging2.stg_process_table_IHTBT30_BT30 b +where b.block_tag='IHTBT30_BT30_Footer' +and block_row_number=3) +where dummy_F='dummy'; + +update staging2.IHTBT30_BT30_Footer_block a +set prepared_date=( select column10 from staging2.stg_process_table_IHTBT30_BT30 b +where b.block_tag='IHTBT30_BT30_Footer' +and block_row_number=1) +where dummy_F='dummy'; + +update staging2.IHTBT30_BT30_Footer_block a +set reviewed_date=( select column10 from staging2.stg_process_table_IHTBT30_BT30 b +where b.block_tag='IHTBT30_BT30_Footer' +and block_row_number=2) +where dummy_F='dummy'; + +update staging2.IHTBT30_BT30_Footer_block a +set approved_date=( select column10 from staging2.stg_process_table_IHTBT30_BT30 b +where b.block_tag='IHTBT30_BT30_Footer' +and block_row_number=3) +where dummy_F='dummy'; + +update staging2.IHTBT30_BT30_Footer_block set model=__model; +execute 'update staging2.IHTBT30_BT30_Footer_block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBT30_BT30_Footer_block'); + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_IHTBT30_BT30_block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + diff --git a/onetime/dataloadfunctions/IHT/IHTBT50_BT50_ODS.sql b/onetime/dataloadfunctions/IHT/IHTBT50_BT50_ODS.sql new file mode 100755 index 0000000..3ff64a6 --- /dev/null +++ b/onetime/dataloadfunctions/IHT/IHTBT50_BT50_ODS.sql @@ -0,0 +1,460 @@ +drop function if exists staging2.fn_IHTBT50_BT50_TRX; +CREATE OR REPLACE FUNCTION staging2.fn_IHTBT50_BT50_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + declare __test_instance_tractor_id int; + begin +__file_syspk := p_file_syspk; + + +/************************************************************ +Function Name:fn_IHTBT50_BT50_TRX +Function Desc: This function populates data into ODS +File Format: IHT +Sheet Format: IHTBT50_BT50 +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_IHTBT50_BT50_TRX() +***************************************************************/ + +insert into transactional.test_instance +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +job_order_no, +sample_receipt_date, +test_report_no, +generation, +customer_name, +test_engineer, +test_report_date, +no_of_sample, +test_start_date, +test_end_date, +tractor_sr_no, +test_standard_ref, +test_location_name, +test_operator, +project_group, +objective_of_test, +test_condition, +test_standard_desc, +test_standard_id, +acceptance_criteria, +remarks, +observations +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +Test_Request_no, +sample_receipt_date::date, +Test_report_No, +Generation, +Customer_Name, +Test_Engineer, +Test_Report_Date::date, +No_of_Sample, +Test_Start_Date::date, +Test_End_Date::date, +Tractor_Sr_No, +Test_Standard_Ref, +test_location, +Operator_Name, +Project_Group, +Objective, +condition, +test_standard, +test_standard_id::numeric, +acceptance_criteria, +remarks, +observations +from +staging2.IHTBT50_BT50_H1_block where trx_record =1; + +update transactional.test_instance a +set +report_prepared_date=to_date(b.prepared_date,'DD-MM-YYYY'), +report_reviewed_date=to_date(b.reviewed_date,'DD-MM-YYYY'), +report_approved_date=to_date(b.approved_date,'DD-MM-YYYY'), +report_prepared_by=b.prepared_by, +report_reviewed_by=b.reviewed_by, +report_approved_by=b.approved_by, +report_template_replaces=b.replaces, +report_title=b.comments, +report_template_no=b.rev1, +report_template_rev_date=b.rev2, +report_template_rev_no= b.rev3 +from staging2.IHTBT50_BT50_footer_block b +where a.file_sheet_mnemonic='IHTBT50_BT50' and trx_record =1; + + + +insert into transactional.test_instance_tyre_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +tyre_type, +tyre_make, +tyre_size, +tyre_ply_rating, +tyre_use_type, +tyre_pressure_kg_per_cm2 +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +tyre_details, +tyre_make, +tyre_size, +ply_rating::numeric, +tyre_use_type, +pressure_kg_cm2::numeric +from staging2.IHTBT50_BT50_tyre_details_block where trx_record =1; + + +insert into transactional.test_instance_drawbar_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +weight_front_kg, +weight_rear_kg, +weight_total_kg +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +test_condition, +front::numeric , +rear::numeric , +total::numeric +from staging2.IHTBT50_BT50_weight_block where trx_record =1; + + +/*block */ + +insert into transactional.test_instance_tractor_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +tractor_platform +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +platform +from staging2.IHTBT50_BT50_h1_block where trx_record =1; + +update transactional.test_instance_tractor_info +set mahindra_model_yn = ( +case when lower(tractor_make) like 'mahindra%' then 'Y' else 'N' end +) where file_syspk =__file_syspk; + +update transactional.test_instance_tractor_info a +set test_tractor_yn ='Y' where syspk in +(select min(syspk) from transactional.test_instance_tractor_info b +where b.file_syspk =a.file_syspk) +and a.file_syspk =__file_syspk; + + + +insert into transactional.iht_brake_perf_test_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +srl_no, +trigger_speed_km_per_h, +brake_control_input_force_kg, +required_corrected_stopping_distance_m, +actual_stopping_distance_m, +deceleration_m_s2_v2_2s, +observation, +test_mode +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column2, +column3::numeric, +column4::numeric, +column5::numeric, +column6::numeric, +column7::numeric, +column8::numeric, +column9, +column10 +from staging2.IHTBT50_BT50_test_res_1_block where trx_record =1; + +insert into transactional.iht_brake_perf_test_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +srl_no, +trigger_speed_km_per_h, +brake_control_input_force_kg, +required_corrected_stopping_distance_m, +actual_stopping_distance_m, +deceleration_m_s2_v2_2s, +observation, +test_mode +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column2, +column3::numeric, +column4::numeric, +column5::numeric, +column6::numeric, +column7::numeric, +column8::numeric, +column9, +column10 +from staging2.IHTBT50_BT50_test_res_2_block where trx_record =1; + +insert into transactional.iht_brake_perf_test_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +srl_no, +trigger_speed_km_per_h, +brake_control_input_force_kg, +required_corrected_stopping_distance_m, +actual_stopping_distance_m, +deceleration_m_s2_v2_2s, +observation, +test_mode +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column2, +column3::numeric, +column4::numeric, +column5::numeric, +column6::numeric, +column7::numeric, +column8::numeric, +column9, +column10 +from staging2.IHTBT50_BT50_test_res_3_block where trx_record =1; + +insert into transactional.iht_brake_perf_test_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +srl_no, +trigger_speed_km_per_h, +brake_control_input_force_kg, +required_corrected_stopping_distance_m, +actual_stopping_distance_m, +deceleration_m_s2_v2_2s, +observation, +test_mode +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column2, +column3::numeric, +column4::numeric, +column5::numeric, +column6::numeric, +column7::numeric, +column8::numeric, +column9, +column10 +from staging2.IHTBT50_BT50_test_res_4_block where trx_record =1; + +insert into transactional.iht_brake_perf_test_condition +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +date_of_test, +time_of_test, +location_name, +test_mode, +wind_velocity_kmph, +ambient_temp_c, +humidity_rh_pct +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make, +model, +condition, +date::date, +time, +location, +mode, +wind_velocity_km_hr, +ambient_temperature_c::numeric , +humidity_rh::numeric +from staging2.IHTBT50_BT50_test_condition_block where trx_record =1; + +update transactional.iht_brake_perf_test_results a +set brake_perf_test_condition_id=(select syspk +from transactional.iht_brake_perf_test_condition b +where a.test_mode =b.test_mode and a.test_condition=b.test_condition and a.file_syspk=b.file_syspk) +where a.file_syspk=__file_syspk; + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk; +select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk; +select syspk from transactional.test_master into __test_master_id where test_type ='In House'; +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk; + + +update transactional.test_instance +set test_master_id =__test_master_id, +test_tractor_id =__test_instance_tractor_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_tyre_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.test_instance_drawbar_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.iht_brake_perf_test_condition +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.iht_brake_perf_test_results +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_IHTBT50_BT50_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + diff --git a/onetime/dataloadfunctions/IHT/IHTBT50_BT50_STG2.sql b/onetime/dataloadfunctions/IHT/IHTBT50_BT50_STG2.sql new file mode 100755 index 0000000..c092b12 --- /dev/null +++ b/onetime/dataloadfunctions/IHT/IHTBT50_BT50_STG2.sql @@ -0,0 +1,908 @@ +drop function if exists staging2.fn_IHTBT50_BT50_block; +CREATE OR REPLACE FUNCTION staging2.fn_IHTBT50_BT50_block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + + begin + +/************************************************************ +Function Name:fn_IHTBT50_BT50_block +Function Desc: This function populates data into staging 2 block +File Format: IHT +Sheet Format: IHTBT50_BT50 +Creation Date: March 25 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_IHTBT50_BT50_block(p_client_id,p_function_id, p_file_mnemonic, +p_file_sheet_mnemonic, p_file_syspk) +Function call ex: select staging2.fn_IHTBT50_BT50_block(1,2,'IHT','IHTBT50_BT50',456) +***************************************************************/ + + +SET search_path TO staging2; + +/* to process multiple files - re-runnability*/ + +truncate table staging2.IHTBT50_BT50_H1_INT; +truncate table staging2.IHTBT50_BT50_H1_block; +truncate table staging2.IHTBT50_BT50_Weight_Tyre_Int; +truncate table staging2.IHTBT50_BT50_Weight_Block; +truncate table staging2.IHTBT50_BT50_Tyre_Details_Block; +truncate table staging2.IHTBT50_BT50_Test_Res_1_Block; +truncate table staging2.IHTBT50_BT50_Test_Res_2_Block; +truncate table staging2.IHTBT50_BT50_Test_Res_3_Block; +truncate table staging2.IHTBT50_BT50_Test_Res_4_Block; +truncate table staging2.IHTBT50_BT50_Test_Condition_Block; +truncate table staging2.IHTBT50_BT50_Footer_Block; +truncate table staging2.stg_specific_table_IHTBT50_BT50; +truncate table staging2.stg_process_table_IHTBT50_BT50; + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* transfer data from generic to specific for IHT */ +execute 'insert into staging2.stg_specific_table_IHTBT50_BT50 +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_IHTBT50_BT50; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for IHTBT50', + detail = 'No data in table stg_specific_table_IHTBT50_BT50', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + +/* trimming data */ +update staging2.stg_specific_table_IHTBT50_BT50 +set column10='Objective' where lower(column10) like 'objective%'; + +update staging2.stg_specific_table_IHTBT50_BT50 +set column10='Acceptance criteria' where lower(column10) like 'acceptance criteria%'; + + +update staging2.stg_specific_table_IHTBT50_BT50 +set column10='Condition' where lower(column10) like 'condition%'; + +update transactional.source_config set F1_source=F1_modified ; + + +/* keyword match in config table*/ +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_IHTBT50_BT50 b +where upper(F1_modified)=upper(column3) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update in process table for match*/ +execute 'update staging2.stg_specific_table_IHTBT50_BT50 a +set is_rownumber_fetched=1 +from transactional.source_config b +where upper(F1_modified)=upper(column3) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* update config files for row numbers start, end */ +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a +set row_read_end = null ,run_time=current_timestamp +where f1_modified =''Prepared by'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers*/ +execute 'insert into staging2.stg_process_table_IHTBT50_BT50 +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTBT50_BT50 a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Request No'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTBT50_BT50 +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTBT50_BT50 a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Un-Ballast cold'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTBT50_BT50 +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTBT50_BT50 a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Ballast cold'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTBT50_BT50 +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTBT50_BT50 a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Fade Performance'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTBT50_BT50 +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTBT50_BT50 a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Recovery Performance'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'insert into staging2.stg_process_table_IHTBT50_BT50 +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTBT50_BT50 a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Weight (kg)'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'insert into staging2.stg_process_table_IHTBT50_BT50 +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTBT50_BT50 a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Prepared by'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/*selecting tractor model*/ +select column5 into __model from staging2.stg_process_table_IHTBT50_BT50 a +where block_tag='IHTBT50_BT50_H1' and trim(column3)='Tractor Model'; + +/*block starts - IHTBT50_BT50_H1_BLOCK */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBT50_BT50_H1_BLOCK',__file_mnemonic,__file_sheet_mnemonic,1); +err_block:='IHTBT50_BT50_H1_BLOCK'; +insert into staging2.IHTBT50_BT50_H1_INT (c1,c2) +select a.column3,column5 from staging2.stg_process_table_IHTBT50_BT50 a where block_tag='IHTBT50_BT50_H1' +and block_row_number <=9; + +insert into staging2.IHTBT50_BT50_H1_INT (c1,c2) +select a.column7,column9 from staging2.stg_process_table_IHTBT50_BT50 a where block_tag='IHTBT50_BT50_H1' +and block_row_number <=9; + +insert into staging2.IHTBT50_BT50_H1_INT (c1,c2) +select 'Objective',column10 +from staging2.stg_process_table_IHTBT50_BT50 a +where block_tag='IHTBT50_BT50_H1' +and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTBT50_BT50 a +where column10='Objective' +and block_tag='IHTBT50_BT50_H1' +); + +insert into staging2.IHTBT50_BT50_H1_INT (c1,c2) +select 'Acceptance criteria',column8 +from staging2.stg_process_table_IHTBT50_BT50 a +where block_tag='IHTBT50_BT50_H1' and block_row_number=11; + + +insert into staging2.IHTBT50_BT50_H1_INT (c1,c2) +select 'Condition',column10 +from staging2.stg_process_table_IHTBT50_BT50 a +where block_tag='IHTBT50_BT50_H1' +and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTBT50_BT50 a +where column10='Condition' +and block_tag='IHTBT50_BT50_H1' +); + + + +insert into staging2.IHTBT50_BT50_H1_INT (c1,c2) +select 'Test std',column4 +from staging2.stg_process_table_IHTBT50_BT50 b +where block_row_number=11 +and block_tag='IHTBT50_BT50_H1'; + +insert into staging2.IHTBT50_BT50_H1_INT (c1,c2) +select 'Test std Id',column3 +from staging2.stg_process_table_IHTBT50_BT50 b +where block_row_number=11 +and block_tag='IHTBT50_BT50_H1'; + +insert into staging2.IHTBT50_BT50_H1_INT (c1,c2) +select 'Test Standard ref',split_part(column3,':',2) +from staging2.stg_process_table_IHTBT50_BT50 b +where block_row_number=10 +and block_tag='IHTBT50_BT50_H1'; + + +insert into staging2.IHTBT50_BT50_H1_INT (c1,c2) +select 'Observations',column3 +from staging2.stg_process_table_IHTBT50_BT50 +where block_tag='IHTBT50_BT50_Weight_Tyre' +and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTBT50_BT50 a +where column3='Remarks & Observations' +and block_tag='IHTBT50_BT50_Weight_Tyre' +); + + +update staging2.IHTBT50_BT50_H1_Int set model=__model; +execute 'update staging2.IHTBT50_BT50_H1_Int set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +insert into staging2.IHTBT50_BT50_H1_Block +( +dummy_f, +Test_Request_no, +Sample_Receipt_Date, +Test_report_No, +Tractor_Model, +Generation, +Customer_Name, +Test_Engineer, +Test_Report_Date, +Test_Location, +No_of_Sample, +Test_Start_Date, +Test_End_Date, +Tractor_Sr_No, +Test_Standard_Refer, +Domestic_Export, +Operator_Name, +Project_Group, +Platform, +Objective, +Acceptance_Criteria, +condition, +Test_Standard, +Test_Standard_id, +Test_Standard_ref, +Remarks, +Observations +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{c2}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[c2::text]) AS val + FROM staging2.IHTBT50_BT50_H1_INT + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text, + a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text, + a_18 text,a_19 text,a_20 text,a_21 text,a_22 text,a_23 text,a_24 text,a_25 text,a_26 text); + +update staging2.IHTBT50_BT50_H1_Block + set Sample_Receipt_Date=case + when Sample_Receipt_Date like '%-%' then Sample_Receipt_Date::timestamptz + else date '1899-12-30' + Sample_Receipt_Date::int * interval '1' day + end; + + update staging2.IHTBT50_BT50_H1_Block + set Test_Report_Date=case + when Test_Report_Date like '%-%' then Test_Report_Date::timestamptz + else date '1899-12-30' + Test_Report_Date::int * interval '1' day + end; + + update staging2.IHTBT50_BT50_H1_Block + set Test_Start_Date=case + when Test_Report_Date like '%-%' then Test_Report_Date::timestamptz + else date '1899-12-30' + Test_Report_Date::int * interval '1' day + end; + update staging2.IHTBT50_BT50_H1_Block + set Test_End_Date=case + when Test_Report_Date like '%-%' then Test_Report_Date::timestamptz + else date '1899-12-30' + Test_Report_Date::int * interval '1' day + end; + +delete from staging2.IHTBT50_BT50_H1_Block where dummy_f is null ; +update staging2.IHTBT50_BT50_H1_Block set model=__model; +execute 'update staging2.IHTBT50_BT50_H1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBT50_BT50_H1_BLOCK'); + + +insert into staging2.IHTBT50_BT50_Weight_Tyre_Int +( +column3,column4,column5,column6,column7,column8,column9, +column10,column11,column12,block_row_number +) +select +column3,column4,column5,column6,column7,column8, +column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_IHTBT50_BT50 a +where block_tag='IHTBT50_BT50_Weight_Tyre' +order by block_row_number; + + +update staging2.IHTBT50_BT50_Weight_Tyre_Int set model=__model; +execute 'update staging2.IHTBT50_BT50_Weight_Tyre_Int set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/*block starts - IHTBT50_BT50_Weight_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBT50_BT50_Weight_Block',__file_mnemonic,__file_sheet_mnemonic,2); + err_block:='IHTBT50_BT50_Weight_Block'; +insert into staging2.IHTBT50_BT50_Weight_Block +( +dummy_f, +test_condition, +Front, +Rear, +Total +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column5,column7}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column5::text,column7::text]) AS val + FROM staging2.IHTBT50_BT50_Weight_Tyre_Int where column5 is not null and column7 is not null and block_row_number<>1 + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text); + + +delete from staging2.IHTBT50_BT50_Weight_Block where dummy_f is null ; +update staging2.IHTBT50_BT50_Weight_Block set model=__model; +execute 'update staging2.IHTBT50_BT50_Weight_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBT50_BT50_Weight_Block'); + +/*block starts - IHTBT50_BT50_Tyre_Details_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBT50_BT50_Tyre_Details_Block',__file_mnemonic,__file_sheet_mnemonic,3); +err_block:='IHTBT50_BT50_Tyre_Details_Block'; +insert into staging2.IHTBT50_BT50_Tyre_Details_Block +( +dummy_f, +Tyre_Details, +Pressure_kg_cm2, +tyre_use_type, +Tyre_Make, +tyre_size, +ply_rating +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column10,column11}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column10::text,column11::text]) AS val + FROM staging2.IHTBT50_BT50_Weight_Tyre_Int where column11 is not null or column10 is not null + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text); + + + +delete from staging2.IHTBT50_BT50_Tyre_Details_Block where dummy_f is null ; +update staging2.IHTBT50_BT50_Tyre_Details_Block set model=__model; +execute 'update staging2.IHTBT50_BT50_Tyre_Details_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBT50_BT50_Tyre_Details_Block'); + + +/*block starts - IHTBT50_BT50_Test_Res_1_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBT50_BT50_Test_Res_1_Block',__file_mnemonic,__file_sheet_mnemonic,4); +err_block:='IHTBT50_BT50_Test_Res_1_Block'; + +insert into staging2.IHTBT50_BT50_Test_Res_1_Block +( +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +) +select +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_IHTBT50_BT50 a +where block_tag='IHTBT50_BT50_Test_Res_1' +order by block_row_number; + +update staging2.IHTBT50_BT50_Test_Res_1_Block +set column2=column3 where block_row_number=1; + + + update staging2.IHTBT50_BT50_Test_Res_1_Block a + set column2= b.first_value from (SELECT +block_row_number,column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column2, +sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBT50_BT50_Test_Res_1_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + + update staging2.IHTBT50_BT50_Test_Res_1_Block a + set column10= b.first_value from (SELECT +block_row_number,column10, value_partition, first_value(column10) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column10, +sum(case when column10 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBT50_BT50_Test_Res_1_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + +update staging2.IHTBT50_BT50_Test_Res_1_Block set trx_record =0 where block_row_number in (1,2,3,4); + +update staging2.IHTBT50_BT50_Test_Res_1_Block set trx_record =0 where +column4 is null and column5 is null; + +update staging2.IHTBT50_BT50_Test_Res_1_Block set model=__model; +execute 'update staging2.IHTBT50_BT50_Test_Res_1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBT50_BT50_Test_Res_1_Block'); + + +/*block starts - IHTBT50_BT50_Test_Res_2_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBT50_BT50_Test_Res_2_Block',__file_mnemonic,__file_sheet_mnemonic,5); +err_block:='IHTBT50_BT50_Test_Res_2_Block'; + +insert into staging2.IHTBT50_BT50_Test_Res_2_Block +( +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +) +select +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_IHTBT50_BT50 a +where block_tag='IHTBT50_BT50_Test_Res_2' +order by block_row_number; + +update staging2.IHTBT50_BT50_Test_Res_2_Block +set column2=column3 where block_row_number=1; + + + update staging2.IHTBT50_BT50_Test_Res_2_Block a + set column2= b.first_value from (SELECT +block_row_number,column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number) +FROM ( +select +block_row_number, +column2, +sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBT50_BT50_Test_Res_2_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + + update staging2.IHTBT50_BT50_Test_Res_2_Block a + set column10= b.first_value from (SELECT +block_row_number,column10, value_partition, first_value(column10) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column10, +sum(case when column10 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBT50_BT50_Test_Res_2_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + +update staging2.IHTBT50_BT50_Test_Res_2_Block set trx_record =0 where block_row_number in (1,2,3,4); + +update staging2.IHTBT50_BT50_Test_Res_2_Block set trx_record =0 where +column4 is null and column5 is null; + +update staging2.IHTBT50_BT50_Test_Res_2_Block set model=__model; +execute 'update staging2.IHTBT50_BT50_Test_Res_2_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBT50_BT50_Test_Res_2_Block'); + + +/*block starts - IHTBT50_BT50_Test_Res_3_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBT50_BT50_Test_Res_3_Block',__file_mnemonic,__file_sheet_mnemonic,6); +err_block:='IHTBT50_BT50_Test_Res_3_Block'; + +insert into staging2.IHTBT50_BT50_Test_Res_3_Block +( +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +) +select +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_IHTBT50_BT50 a +where block_tag='IHTBT50_BT50_Test_Res_3' +order by block_row_number; + +update staging2.IHTBT50_BT50_Test_Res_3_Block +set column2=column3 where block_row_number=1; + + + update staging2.IHTBT50_BT50_Test_Res_3_Block a + set column2= b.first_value from (SELECT +block_row_number,column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column2, +sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBT50_BT50_Test_Res_3_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + + update staging2.IHTBT50_BT50_Test_Res_3_Block a + set column10= b.first_value from (SELECT +block_row_number,column10, value_partition, first_value(column10) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column10, +sum(case when column10 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBT50_BT50_Test_Res_3_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + +update staging2.IHTBT50_BT50_Test_Res_3_Block set trx_record =0 where block_row_number in (1,2,3,4); + +update staging2.IHTBT50_BT50_Test_Res_3_Block set trx_record =0 where +column4 is null and column5 is null; + +update staging2.IHTBT50_BT50_Test_Res_3_Block set model=__model; +execute 'update staging2.IHTBT50_BT50_Test_Res_3_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBT50_BT50_Test_Res_3_Block'); + + +/*block starts - IHTBT50_BT50_Test_Res_4_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBT50_BT50_Test_Res_4_Block',__file_mnemonic,__file_sheet_mnemonic,7); +err_block:='IHTBT50_BT50_Test_Res_4_Block'; + +insert into staging2.IHTBT50_BT50_Test_Res_4_Block +( +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +) +select +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_IHTBT50_BT50 a +where block_tag='IHTBT50_BT50_Test_Res_4' +order by block_row_number; + +update staging2.IHTBT50_BT50_Test_Res_4_Block +set column2=column3 where block_row_number=1; + + + update staging2.IHTBT50_BT50_Test_Res_4_Block a + set column2= b.first_value from (SELECT +block_row_number,column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column2, +sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBT50_BT50_Test_Res_4_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + + update staging2.IHTBT50_BT50_Test_Res_4_Block a + set column10= b.first_value from (SELECT +block_row_number,column10, value_partition, first_value(column10) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column10, +sum(case when column10 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBT50_BT50_Test_Res_4_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + +update staging2.IHTBT50_BT50_Test_Res_4_Block set trx_record =0 where block_row_number in (1,2,3,4,15); + +update staging2.IHTBT50_BT50_Test_Res_4_Block set trx_record =0 where +column4 is null and column5 is null; + +update staging2.IHTBT50_BT50_Test_Res_4_Block set model=__model; +execute 'update staging2.IHTBT50_BT50_Test_Res_4_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBT50_BT50_Test_Res_4_Block'); + + +/*block starts - IHTBT50_BT50_Test_Condition_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBT50_BT50_Test_Condition_Block',__file_mnemonic,__file_sheet_mnemonic,8); +err_block:='IHTBT50_BT50_Test_Condition_Block'; + + +insert into staging2.IHTBT50_BT50_Test_Condition_Block (condition) +select column2 from staging2.IHTBT50_BT50_Test_Res_1_Block +where block_row_number=2 +union +select column2 from staging2.IHTBT50_BT50_Test_Res_2_Block +where block_row_number=2 +union +select column2 from staging2.IHTBT50_BT50_Test_Res_3_Block +where block_row_number=2 +union +select column2 from staging2.IHTBT50_BT50_Test_Res_4_Block +where block_row_number=2; + + +update staging2.IHTBT50_BT50_Test_Condition_Block +set date=b.column4, +location=b.column7, +--time=b.column9, +mode=b.column10 +from staging2.IHTBT50_BT50_Test_Res_1_Block b +where b.block_row_number =2 and condition=b.column2; + +update staging2.IHTBT50_BT50_Test_Condition_Block +set Wind_Velocity_Km_hr=b.column5, +Ambient_Temperature_C=b.column7, +Humidity_RH=b.column9 +from staging2.IHTBT50_BT50_Test_Res_1_Block b +where b.block_row_number =3 and condition=b.column2; + +update staging2.IHTBT50_BT50_Test_Condition_Block +set date=b.column4, +location=b.column7, +--time=b.column9, +mode=b.column10 +from staging2.IHTBT50_BT50_Test_Res_2_Block b +where b.block_row_number =2 and condition=b.column2; + +update staging2.IHTBT50_BT50_Test_Condition_Block +set Wind_Velocity_Km_hr=b.column5, +Ambient_Temperature_C=b.column7, +Humidity_RH=b.column9 +from staging2.IHTBT50_BT50_Test_Res_2_Block b +where b.block_row_number =3 and condition=b.column2; + +update staging2.IHTBT50_BT50_Test_Condition_Block +set date=b.column4, +location=b.column7, +--time=b.column9, +mode=b.column10 +from staging2.IHTBT50_BT50_Test_Res_3_Block b +where b.block_row_number =2 and condition=b.column2; + +update staging2.IHTBT50_BT50_Test_Condition_Block +set Wind_Velocity_Km_hr=b.column5, +Ambient_Temperature_C=b.column7, +Humidity_RH=b.column9 +from staging2.IHTBT50_BT50_Test_Res_3_Block b +where b.block_row_number =3 and condition=b.column2; + +update staging2.IHTBT50_BT50_Test_Condition_Block +set date=b.column4, +location=b.column7, +--time=b.column9, +mode=b.column10 +from staging2.IHTBT50_BT50_Test_Res_4_Block b +where b.block_row_number =2 and condition=b.column2; + +update staging2.IHTBT50_BT50_Test_Condition_Block +set Wind_Velocity_Km_hr=b.column5, +Ambient_Temperature_C=b.column7, +Humidity_RH=b.column9 +from staging2.IHTBT50_BT50_Test_Res_4_Block b +where b.block_row_number=3 and condition=b.column2; + + +update staging2.IHTBT50_BT50_Test_Condition_Block a +set date= case + when date like '%-%' then date::timestamptz + else date '1899-12-30' + date::int * interval '1' day + end ; + + +update staging2.IHTBT50_BT50_Test_Condition_Block set model=__model; +execute 'update staging2.IHTBT50_BT50_Test_Condition_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBT50_BT50_Test_Condition_Block'); + +/*block starts - IHTBT50_BT50_Footer_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBT50_BT50_Footer_block',__file_mnemonic,__file_sheet_mnemonic,9); +err_block:='IHTBT50_BT50_Footer_block'; + +insert into staging2.IHTBT50_BT50_Footer_block(dummy_f) values ('dummy'); + + +update staging2.IHTBT50_BT50_Footer_block a +set prepared_by=( select column6 from staging2.stg_process_table_IHTBT50_BT50 b +where b.block_tag='IHTBT50_BT50_Footer' +and lower(column3)='prepared by' ) +where dummy_F='dummy'; + +update staging2.IHTBT50_BT50_Footer_block a +set reviewed_by=( select column6 from staging2.stg_process_table_IHTBT50_BT50 b +where b.block_tag='IHTBT50_BT50_Footer' +and lower(column3)='reviewed by' ) +where dummy_F='dummy'; + +update staging2.IHTBT50_BT50_Footer_block a +set approved_by=( select column6 from staging2.stg_process_table_IHTBT50_BT50 b +where b.block_tag='IHTBT50_BT50_Footer' +and lower(column3)='approved by' ) +where dummy_F='dummy'; + +update staging2.IHTBT50_BT50_Footer_block a +set comments=( select column3 from staging2.stg_process_table_IHTBT50_BT50 b +where b.block_tag='IHTBT50_BT50_Footer' +and block_row_number=5 ) +where dummy_F='dummy'; + +update staging2.IHTBT50_BT50_Footer_block a +set rev1=( select column3 from staging2.stg_process_table_IHTBT50_BT50 b +where b.block_tag='IHTBT50_BT50_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + + +update staging2.IHTBT50_BT50_Footer_block a +set rev2=( select column7 from staging2.stg_process_table_IHTBT50_BT50 b +where b.block_tag='IHTBT50_BT50_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + +update staging2.IHTBT50_BT50_Footer_block a +set rev3=( select column10 from staging2.stg_process_table_IHTBT50_BT50 b +where b.block_tag='IHTBT50_BT50_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + +update staging2.IHTBT50_BT50_Footer_block a +set replaces=( select column11 from staging2.stg_process_table_IHTBT50_BT50 b +where b.block_tag='IHTBT50_BT50_Footer' +and block_row_number=1) +where dummy_F='dummy'; + +update staging2.IHTBT50_BT50_Footer_block a +set revision_no=( select column11 from staging2.stg_process_table_IHTBT50_BT50 b +where b.block_tag='IHTBT50_BT50_Footer' +and block_row_number=3) +where dummy_F='dummy'; + +update staging2.IHTBT50_BT50_Footer_block a +set prepared_date=( select column10 from staging2.stg_process_table_IHTBT50_BT50 b +where b.block_tag='IHTBT50_BT50_Footer' +and block_row_number=1) +where dummy_F='dummy'; + +update staging2.IHTBT50_BT50_Footer_block a +set reviewed_date=( select column10 from staging2.stg_process_table_IHTBT50_BT50 b +where b.block_tag='IHTBT50_BT50_Footer' +and block_row_number=2) +where dummy_F='dummy'; + +update staging2.IHTBT50_BT50_Footer_block a +set approved_date=( select column10 from staging2.stg_process_table_IHTBT50_BT50 b +where b.block_tag='IHTBT50_BT50_Footer' +and block_row_number=3) +where dummy_F='dummy'; + +update staging2.IHTBT50_BT50_Footer_block set model=__model; +execute 'update staging2.IHTBT50_BT50_Footer_block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBT50_BT50_Footer_block'); + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_IHTBT50_BT50_block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; diff --git a/onetime/dataloadfunctions/IHT/IHTBTD_BTD_ODS.sql b/onetime/dataloadfunctions/IHT/IHTBTD_BTD_ODS.sql new file mode 100755 index 0000000..5d56a81 --- /dev/null +++ b/onetime/dataloadfunctions/IHT/IHTBTD_BTD_ODS.sql @@ -0,0 +1,539 @@ +drop function if exists staging2.fn_IHTBTD_BTD_TRX; +CREATE OR REPLACE FUNCTION staging2.fn_IHTBTD_BTD_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + declare __test_instance_tractor_id int; + begin +__file_syspk := p_file_syspk; + + +/************************************************************ +Function Name:fn_IHTBTD_BTD_TRX +Function Desc: This function populates data into ODS +File Format: IHT +Sheet Format: IHTBTD_BTD +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_IHTBTD_BTD_TRX() +***************************************************************/ +insert into transactional.test_instance +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +job_order_no, +sample_receipt_date, +test_report_no, +generation, +customer_name, +test_engineer, +test_report_date, +no_of_sample, +test_start_date, +test_end_date, +tractor_sr_no, +test_standard_ref, +test_location_name, +test_operator, +project_group, +objective_of_test, +test_condition, +test_standard_desc, +test_standard_id, +acceptance_criteria, +remarks, +observations +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +Test_Request_no, +to_date(sample_receipt_date,'DD-MM-YYYY'), +Test_report_No, +Generation, +Customer_Name, +Test_Engineer, +to_date(Test_Report_Date,'DD-MM-YYYY'), +No_of_Sample, +to_date(Test_Start_Date,'DD-MM-YYYY'), +to_date(Test_End_Date, 'DD-MM-YYYY'), +Tractor_Sr_No, +Test_Standard_Refer, +test_location, +Operator_Name, +Project_Group, +Objective, +condition, +test_standard, +test_standard_id::numeric, +test_standard_ref +acceptance_criteria, +remarks, +observations +from +staging2.IHTBTD_BTD_H1_block where trx_record =1; + +update transactional.test_instance a +set +report_prepared_date=to_date(b.prepared_date,'DD-MM-YYYY'), +report_reviewed_date=to_date(b.reviewed_date,'DD-MM-YYYY'), +report_approved_date=to_date(b.approved_date,'DD-MM-YYYY'), +report_prepared_by=b.prepared_by, +report_reviewed_by=b.reviewed_by, +report_approved_by=b.approved_by, +report_template_replaces=b.replaces, +report_title=b.comments, +report_template_no=b.rev1, +report_template_rev_date=b.rev2, +report_template_rev_no= b.rev3 +from staging2.IHTBTD_BTD_footer_block b +where a.file_sheet_mnemonic='IHTBTD_BTD' and trx_record =1; + + + +insert into transactional.test_instance_tyre_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +tyre_type, +tyre_make, +tyre_size, +tyre_ply_rating, +tyre_use_type, +tyre_pressure_kg_per_cm2 +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +tyre_details, +tyre_make, +tyre_size, +ply_rating::numeric, +tyre_use_type, +pressure_kg_cm2::numeric +from staging2.IHTBTD_BTD_tyre_details_block where trx_record =1; + + + +insert into transactional.test_instance_drawbar_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +weight_front_kg, +weight_rear_kg, +weight_total_kg, +status +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +test_condition, +front::numeric , +rear::numeric , +total::numeric , +status +from staging2.IHTBTD_BTD_weight_block where trx_record =1; + + +/*block */ + +insert into transactional.test_instance_tractor_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +tractor_platform +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +platform +from staging2.IHTBTD_BTD_h1_block where trx_record =1; + +update transactional.test_instance_tractor_info +set mahindra_model_yn = ( +case when tractor_make like 'Mahindra%' then 'Y' else 'N' end +) where file_syspk =__file_syspk; + +update transactional.test_instance_tractor_info a +set test_tractor_yn ='Y' where syspk in +(select min(syspk) from transactional.test_instance_tractor_info b +where b.file_syspk =a.file_syspk) +and a.file_syspk =__file_syspk; + + + +insert into transactional.iht_brake_perf_test_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +srl_no, +trigger_speed_km_per_h, +brake_control_input_force_kg, +required_corrected_stopping_distance_m, +actual_stopping_distance_m, +deceleration_m_s2_v2_2s, +observation, +test_mode +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column2, +column3::numeric, +column4::numeric, +column5::numeric, +column6::numeric, +column7::numeric, +column8::numeric, +column9, +column11 +from staging2.IHTBTD_BTD_test_res_1_block where trx_record =1; + +insert into transactional.iht_brake_perf_test_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +srl_no, +trigger_speed_km_per_h, +brake_control_input_force_kg, +required_corrected_stopping_distance_m, +actual_stopping_distance_m, +deceleration_m_s2_v2_2s, +observation, +test_mode +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column2, +column3::numeric, +column4::numeric, +column5::numeric, +column6::numeric, +column7::numeric, +column8::numeric, +column9, +column11 +from staging2.IHTBTD_BTD_test_res_2_block where trx_record =1; + +insert into transactional.iht_brake_perf_test_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +srl_no, +trigger_speed_km_per_h, +brake_control_input_force_kg, +required_corrected_stopping_distance_m, +actual_stopping_distance_m, +deceleration_m_s2_v2_2s, +observation, +test_mode +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column2, +column3::numeric, +column4::numeric, +column5::numeric, +column6::numeric, +column7::numeric, +column8::numeric, +column9, +column11 +from staging2.IHTBTD_BTD_test_res_3_block where trx_record =1; + +insert into transactional.iht_brake_perf_test_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +srl_no, +trigger_speed_km_per_h, +brake_control_input_force_kg, +required_corrected_stopping_distance_m, +actual_stopping_distance_m, +deceleration_m_s2_v2_2s, +observation, +test_mode +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column2, +column3::numeric, +column4::numeric, +column5::numeric, +column6::numeric, +column7::numeric, +column8::numeric, +column9, +column11 +from staging2.IHTBTD_BTD_test_res_4_block where trx_record =1; + +insert into transactional.iht_brake_perf_test_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +srl_no, +trigger_speed_km_per_h, +brake_control_input_force_kg, +required_corrected_stopping_distance_m, +actual_stopping_distance_m, +deceleration_m_s2_v2_2s, +observation, +test_mode +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column2, +column3::numeric, +column4::numeric, +column5::numeric, +column6::numeric, +column7::numeric, +column8::numeric, +column9, +column11 +from staging2.IHTBTD_BTD_test_res_5_block where trx_record =1; + + +insert into transactional.iht_brake_perf_test_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +srl_no, +trigger_speed_km_per_h, +brake_control_input_force_kg, +required_corrected_stopping_distance_m, +actual_stopping_distance_m, +deceleration_m_s2_v2_2s, +observation, +test_mode +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column2, +column3::numeric, +column4::numeric, +column5::numeric, +column6::numeric, +column7::numeric, +column8::numeric, +column9, +column13 +from staging2.IHTBTD_BTD_test_res_6_block where trx_record =1; + +insert into transactional.iht_brake_perf_test_condition +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +date_of_test, +time_of_test, +location_name, +test_mode, +wind_velocity_kmph, +ambient_temp_c, +humidity_rh_pct +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make, +model, +condition, +date::date, +time, +location, +mode, +wind_velocity_km_hr, +ambient_temperature_c::numeric , +humidity_rh::numeric +from staging2.ihtbtd_btd_test_condition_block where trx_record =1; + +update transactional.iht_brake_perf_test_results a +set brake_perf_test_condition_id=(select syspk +from transactional.iht_brake_perf_test_condition b +where a.test_mode =b.test_mode and a.test_condition=b.test_condition and a.file_syspk=b.file_syspk) +where a.file_syspk=__file_syspk; + + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk; +select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk; +select syspk from transactional.test_master into __test_master_id where test_type ='In House'; +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk; + + +update transactional.test_instance +set test_master_id =__test_master_id, +test_tractor_id =__test_instance_tractor_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_tyre_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.test_instance_drawbar_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.iht_brake_perf_test_condition +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.iht_brake_perf_test_results +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_IHTBTD_BTD_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + diff --git a/onetime/dataloadfunctions/IHT/IHTBTD_BTD_STG2.sql b/onetime/dataloadfunctions/IHT/IHTBTD_BTD_STG2.sql new file mode 100755 index 0000000..05cc953 --- /dev/null +++ b/onetime/dataloadfunctions/IHT/IHTBTD_BTD_STG2.sql @@ -0,0 +1,1098 @@ +drop function if exists staging2.fn_IHTBTD_BTD_block; +CREATE OR REPLACE FUNCTION staging2.fn_IHTBTD_BTD_block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + + begin + +/************************************************************ +Function Name:fn_IHTBTD_BTD_block +Function Desc: This function populates data into staging 2 block +File Format: IHT +Sheet Format: IHTBTD_BTD +Creation Date: March 25 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_IHTBTD_BTD_block(p_client_id,p_function_id, p_file_mnemonic, +p_file_sheet_mnemonic, p_file_syspk) +Function call ex: select staging2.fn_IHTBTD_BTD_block(1,2,'IHT','IHTBTD_BTD',456) +***************************************************************/ + + +SET search_path TO staging2; + +/* to process multiple files - re-runnability*/ + +truncate table staging2.IHTBTD_BTD_H1_Int; +truncate table staging2.IHTBTD_BTD_H1_block; +truncate table staging2.IHTBTD_BTD_Weight_Tyre_Int; +truncate table staging2.IHTBTD_BTD_Weight_Block; +truncate table staging2.IHTBTD_BTD_Tyre_Details_Block; +truncate table staging2.IHTBTD_BTD_Test_Res_1_Block; +truncate table staging2.IHTBTD_BTD_Test_Res_2_Block; +truncate table staging2.IHTBTD_BTD_Test_Res_3_Block; +truncate table staging2.IHTBTD_BTD_Test_Res_4_Block; +truncate table staging2.IHTBTD_BTD_Test_Res_5_Block; +truncate table staging2.IHTBTD_BTD_Test_Res_6_Block; +truncate table staging2.IHTBTD_BTD_Test_Condition_Block; +truncate table staging2.IHTBTD_BTD_Footer_Block; +truncate table staging2.stg_specific_table_IHTBTD_BTD; +truncate table staging2.stg_process_table_IHTBTD_BTD; + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* transfer data from generic to specific for IHT */ +execute 'insert into staging2.stg_specific_table_IHTBTD_BTD +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_IHTBTD_BTD; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for IHT BTD', + detail = 'No data in table stg_specific_table_IHTBTD_BTD', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + +/* trimming data */ +update staging2.stg_specific_table_IHTBTD_BTD +set column11='Objective' where lower(column11) like 'objective%'; + +update staging2.stg_specific_table_IHTBTD_BTD +set column10='Acceptance criteria' where lower(column10) like 'acceptance criteria%'; + + +update staging2.stg_specific_table_IHTBTD_BTD +set column11='Condition' where lower(column11) like 'condition%'; + +update transactional.source_config set F1_source=F1_modified ; + + +/* keyword match in config table*/ +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_IHTBTD_BTD b +where upper(F1_modified)=upper(column3) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update in process table for match*/ +execute 'update staging2.stg_specific_table_IHTBTD_BTD a +set is_rownumber_fetched=1 +from transactional.source_config b +where upper(F1_modified)=upper(column3) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* update config files for row numbers start, end */ +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a +set row_read_end = null ,run_time=current_timestamp +where f1_modified =''Prepared by'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers*/ +execute 'insert into staging2.stg_process_table_IHTBTD_BTD +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTBTD_BTD a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Request No'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTBTD_BTD +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTBTD_BTD a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Un-Ballast cold'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTBTD_BTD +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTBTD_BTD a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Road Ballast cold'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTBTD_BTD +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTBTD_BTD a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Road Ballast Hot'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTBTD_BTD +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTBTD_BTD a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Max Ballast cold'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTBTD_BTD +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTBTD_BTD a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Max Ballast Hot'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTBTD_BTD +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTBTD_BTD a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Date- 04-July-2019'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTBTD_BTD +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTBTD_BTD a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Weight (kg)'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'insert into staging2.stg_process_table_IHTBTD_BTD +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTBTD_BTD a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Prepared by'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/*selecting tractor model*/ +select column5 into __model from staging2.stg_process_table_IHTBTD_BTD a +where block_tag='IHTBTD_BTD_H1' and trim(column3)='Tractor Model'; + +/*block starts - IHTBTD_BTD_H1_BLOCK */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBTD_BTD_H1_BLOCK',__file_mnemonic,__file_sheet_mnemonic,1); +err_block:='IHTBTD_BTD_H1_BLOCK'; +insert into staging2.IHTBTD_BTD_H1_INT (c1,c2) +select a.column3,column5 from staging2.stg_process_table_IHTBTD_BTD a where block_tag='IHTBTD_BTD_H1' +and block_row_number <=9; + +insert into staging2.IHTBTD_BTD_H1_INT (c1,c2) +select a.column7,column9 from staging2.stg_process_table_IHTBTD_BTD a where block_tag='IHTBTD_BTD_H1' +and block_row_number <=9; + +insert into staging2.IHTBTD_BTD_H1_INT (c1,c2) +select 'Objective',column11 +from staging2.stg_process_table_IHTBTD_BTD a +where block_tag='IHTBTD_BTD_H1' +and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTBTD_BTD a +where column11='Objective' +and block_tag='IHTBTD_BTD_H1' +); + +insert into staging2.IHTBTD_BTD_H1_INT (c1,c2) +select 'Acceptance criteria',column8 +from staging2.stg_process_table_IHTBTD_BTD a +where block_tag='IHTBTD_BTD_H1' and block_row_number=11; + + +insert into staging2.IHTBTD_BTD_H1_INT (c1,c2) +select 'Condition',column11 +from staging2.stg_process_table_IHTBTD_BTD a +where block_tag='IHTBTD_BTD_H1' +and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTBTD_BTD a +where column11='Condition' +and block_tag='IHTBTD_BTD_H1' +); + + + +insert into staging2.IHTBTD_BTD_H1_INT (c1,c2) +select 'Test std',column4 +from staging2.stg_process_table_IHTBTD_BTD b +where block_row_number=11 +and block_tag='IHTBTD_BTD_H1'; + +insert into staging2.IHTBTD_BTD_H1_INT (c1,c2) +select 'Test std Id',column3 +from staging2.stg_process_table_IHTBTD_BTD b +where block_row_number=11 +and block_tag='IHTBTD_BTD_H1'; + +insert into staging2.IHTBTD_BTD_H1_INT (c1,c2) +select 'Test Standard ref',split_part(column3,':',2) +from staging2.stg_process_table_IHTBTD_BTD b +where block_row_number=10 +and block_tag='IHTBTD_BTD_H1'; + + +insert into staging2.IHTBTD_BTD_H1_INT (c1,c2) +select 'Observations',column3 +from staging2.stg_process_table_IHTBTD_BTD +where block_tag='IHTBTD_BTD_Weight_Tyre' +and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTBTD_BTD a +where column3='Remarks & Observations' +and block_tag='IHTBTD_BTD_Weight_Tyre' +); + + + +insert into staging2.IHTBTD_BTD_H1_INT (c1,c2) +select 'Test Purpose',column8 +from staging2.stg_process_table_IHTBTD_BTD b +where block_row_number=12 +and block_tag='IHTBTD_BTD_H1'; + +update staging2.IHTBTD_BTD_H1_Int set model=__model; +execute 'update staging2.IHTBTD_BTD_H1_Int set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +insert into staging2.IHTBTD_BTD_H1_Block +( +dummy_f, +Test_Request_no, +Sample_Receipt_Date, +Test_report_No, +Tractor_Model, +Generation, +Customer_Name, +Test_Engineer, +Test_Report_Date, +Test_Location, +No_of_Sample, +Test_Start_Date, +Test_End_Date, +Tractor_Sr_No, +Test_Standard_Refer, +Domestic_Export, +Operator_Name, +Project_Group, +Platform, +Objective, +Acceptance_Criteria, +condition, +Test_Standard, +Test_Standard_id, +Test_Standard_ref, +Remarks, +Observations, +Test_Purpose +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{c2}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[c2::text]) AS val + FROM staging2.IHTBTD_BTD_H1_INT + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text, + a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text, + a_18 text,a_19 text,a_20 text,a_21 text,a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text); + + +delete from staging2.IHTBTD_BTD_H1_Block where dummy_f is null ; +update staging2.IHTBTD_BTD_H1_Block set model=__model; +execute 'update staging2.IHTBTD_BTD_H1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBTD_BTD_H1_BLOCK'); + + +insert into staging2.IHTBTD_BTD_Weight_Tyre_Int +( +column3,column4,column5,column6,column7,column8,column9, +column10,column11,column12,block_row_number +) +select +column3,column4,column5,column6,column7,column8, +column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_IHTBTD_BTD a +where block_tag='IHTBTD_BTD_Weight_Tyre' +order by block_row_number; + + +update staging2.IHTBTD_BTD_Weight_Tyre_Int set model=__model; +execute 'update staging2.IHTBTD_BTD_Weight_Tyre_Int set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/*block starts - IHTBTD_BTD_Weight_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBTD_BTD_Weight_Block',__file_mnemonic,__file_sheet_mnemonic,2); + err_block:='IHTBTD_BTD_Weight_Block'; +insert into staging2.IHTBTD_BTD_Weight_Block +( +dummy_f, +test_condition, +Front, +Rear, +Total +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column5,column7,column9}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column5::text,column7::text,column9::text]) AS val + FROM staging2.IHTBTD_BTD_Weight_Tyre_Int where block_row_number <>1 + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text); + + +delete from staging2.IHTBTD_BTD_Weight_Block where dummy_f is null ; +update staging2.IHTBTD_BTD_Weight_Block set model=__model; +execute 'update staging2.IHTBTD_BTD_Weight_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBTD_BTD_Weight_Block'); + +/*block starts - IHTBTD_BTD_Tyre_Details_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBTD_BTD_Tyre_Details_Block',__file_mnemonic,__file_sheet_mnemonic,3); +err_block:='IHTBTD_BTD_Tyre_Details_Block'; +insert into staging2.IHTBTD_BTD_Tyre_Details_Block +( +dummy_f, +Tyre_Details, +Pressure_kg_cm2, +tyre_use_type, +Tyre_Make, +tyre_size, +ply_rating +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column11,column12}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column11::text,column12::text]) AS val + FROM staging2.IHTBTD_BTD_Weight_Tyre_Int where column11 is not null and column12 is not null + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text); + + + +delete from staging2.IHTBTD_BTD_Tyre_Details_Block where dummy_f is null ; +update staging2.IHTBTD_BTD_Tyre_Details_Block set model=__model; +execute 'update staging2.IHTBTD_BTD_Tyre_Details_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBTD_BTD_Tyre_Details_Block'); + + +/*block starts - IHTBTD_BTD_Test_Res_1_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBTD_BTD_Test_Res_1_Block',__file_mnemonic,__file_sheet_mnemonic,4); +err_block:='IHTBTD_BTD_Test_Res_1_Block'; + +insert into staging2.IHTBTD_BTD_Test_Res_1_Block +( +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +) +select +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_IHTBTD_BTD a +where block_tag='IHTBTD_BTD_Test_Res_1' +order by block_row_number; + +update staging2.IHTBTD_BTD_Test_Res_1_Block +set column2=column3 where block_row_number=1; + + + update staging2.IHTBTD_BTD_Test_Res_1_Block a + set column2= b.first_value from (SELECT +block_row_number,column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column2, +sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBTD_BTD_Test_Res_1_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + + update staging2.IHTBTD_BTD_Test_Res_1_Block a + set column11= b.first_value from (SELECT +block_row_number,column11, value_partition, first_value(column11) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column11, +sum(case when column11 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBTD_BTD_Test_Res_1_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + +update staging2.IHTBTD_BTD_Test_Res_1_Block set trx_record =0 where block_row_number in (1,2,3,4); + +update staging2.IHTBTD_BTD_Test_Res_1_Block set trx_record =0 +where column4 is null and column5 is null; + +update staging2.IHTBTD_BTD_Test_Res_1_Block set model=__model; +execute 'update staging2.IHTBTD_BTD_Test_Res_1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBTD_BTD_Test_Res_1_Block'); + + +/*block starts - IHTBTD_BTD_Test_Res_2_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBTD_BTD_Test_Res_2_Block',__file_mnemonic,__file_sheet_mnemonic,5); +err_block:='IHTBTD_BTD_Test_Res_2_Block'; + +insert into staging2.IHTBTD_BTD_Test_Res_2_Block +( +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +) +select +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_IHTBTD_BTD a +where block_tag='IHTBTD_BTD_Test_Res_2' +order by block_row_number; + +update staging2.IHTBTD_BTD_Test_Res_2_Block +set column2=column3 where block_row_number=1; + + + update staging2.IHTBTD_BTD_Test_Res_2_Block a + set column2= b.first_value from (SELECT +block_row_number,column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number) +FROM ( +select +block_row_number, +column2, +sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBTD_BTD_Test_Res_2_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + + update staging2.IHTBTD_BTD_Test_Res_2_Block a + set column11= b.first_value from (SELECT +block_row_number,column11, value_partition, first_value(column11) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column11, +sum(case when column11 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBTD_BTD_Test_Res_2_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + +update staging2.IHTBTD_BTD_Test_Res_2_Block set trx_record =0 where block_row_number in (1,2,3,4); + +update staging2.IHTBTD_BTD_Test_Res_2_Block set trx_record =0 +where column4 is null and column5 is null; + +update staging2.IHTBTD_BTD_Test_Res_2_Block set model=__model; +execute 'update staging2.IHTBTD_BTD_Test_Res_2_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBTD_BTD_Test_Res_2_Block'); + + +/*block starts - IHTBTD_BTD_Test_Res_3_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBTD_BTD_Test_Res_3_Block',__file_mnemonic,__file_sheet_mnemonic,6); +err_block:='IHTBTD_BTD_Test_Res_3_Block'; + +insert into staging2.IHTBTD_BTD_Test_Res_3_Block +( +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +) +select +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_IHTBTD_BTD a +where block_tag='IHTBTD_BTD_Test_Res_3' +order by block_row_number; + +update staging2.IHTBTD_BTD_Test_Res_3_Block +set column2=column3 where block_row_number=1; + + + update staging2.IHTBTD_BTD_Test_Res_3_Block a + set column2= b.first_value from (SELECT +block_row_number,column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column2, +sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBTD_BTD_Test_Res_3_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + + update staging2.IHTBTD_BTD_Test_Res_3_Block a + set column11= b.first_value from (SELECT +block_row_number,column11, value_partition, first_value(column11) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column11, +sum(case when column11 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBTD_BTD_Test_Res_3_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + +update staging2.IHTBTD_BTD_Test_Res_3_Block set trx_record =0 where block_row_number in (1,2,3,4); + +update staging2.IHTBTD_BTD_Test_Res_3_Block set trx_record =0 +where column4 is null and column5 is null; + +update staging2.IHTBTD_BTD_Test_Res_3_Block set model=__model; +execute 'update staging2.IHTBTD_BTD_Test_Res_3_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBTD_BTD_Test_Res_3_Block'); + + +/*block starts - IHTBTD_BTD_Test_Res_4_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBTD_BTD_Test_Res_4_Block',__file_mnemonic,__file_sheet_mnemonic,7); +err_block:='IHTBTD_BTD_Test_Res_4_Block'; + +insert into staging2.IHTBTD_BTD_Test_Res_4_Block +( +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +) +select +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_IHTBTD_BTD a +where block_tag='IHTBTD_BTD_Test_Res_4' +order by block_row_number; + +update staging2.IHTBTD_BTD_Test_Res_4_Block +set column2=column3 where block_row_number=1; + + + update staging2.IHTBTD_BTD_Test_Res_4_Block a + set column2= b.first_value from (SELECT +block_row_number,column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column2, +sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBTD_BTD_Test_Res_4_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + + update staging2.IHTBTD_BTD_Test_Res_4_Block a + set column11= b.first_value from (SELECT +block_row_number,column11, value_partition, first_value(column11) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column11, +sum(case when column11 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBTD_BTD_Test_Res_4_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + +update staging2.IHTBTD_BTD_Test_Res_4_Block set trx_record =0 where block_row_number in (1,2,3,4); + +update staging2.IHTBTD_BTD_Test_Res_4_Block set trx_record =0 +where column4 is null and column5 is null; + +update staging2.IHTBTD_BTD_Test_Res_4_Block set model=__model; +execute 'update staging2.IHTBTD_BTD_Test_Res_4_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBTD_BTD_Test_Res_4_Block'); + + +/*block starts - IHTBTD_BTD_Test_Res_1_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBTD_BTD_Test_Res_5_Block',__file_mnemonic,__file_sheet_mnemonic,8); +err_block:='IHTBTD_BTD_Test_Res_5_Block'; + +insert into staging2.IHTBTD_BTD_Test_Res_5_Block +( +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +) +select +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_IHTBTD_BTD a +where block_tag='IHTBTD_BTD_Test_Res_5' +order by block_row_number; + +update staging2.IHTBTD_BTD_Test_Res_5_Block +set column2=column3 where block_row_number=1; + + + update staging2.IHTBTD_BTD_Test_Res_5_Block a + set column2= b.first_value from (SELECT +block_row_number,column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column2, +sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBTD_BTD_Test_Res_5_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + + update staging2.IHTBTD_BTD_Test_Res_5_Block a + set column11= b.first_value from (SELECT +block_row_number,column11, value_partition, first_value(column11) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column11, +sum(case when column11 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBTD_BTD_Test_Res_5_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + + +update staging2.IHTBTD_BTD_Test_Res_5_Block set trx_record =0 where block_row_number in (1,2,3,4); + +update staging2.IHTBTD_BTD_Test_Res_5_Block set trx_record =0 +where column4 is null and column5 is null; + +update staging2.IHTBTD_BTD_Test_Res_5_Block set model=__model; +execute 'update staging2.IHTBTD_BTD_Test_Res_5_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBTD_BTD_Test_Res_5_Block'); + +/*block starts - IHTBTD_BTD_Test_Res_6_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBTD_BTD_Test_Res_6_Block',__file_mnemonic,__file_sheet_mnemonic,9); +err_block:='IHTBTD_BTD_Test_Res_6_Block'; +insert into staging2.IHTBTD_BTD_Test_Res_6_Block +( +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,column13, +block_row_number +) +select +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,column13, +block_row_number +from staging2.stg_process_table_IHTBTD_BTD a +where block_tag='IHTBTD_BTD_Test_Res_6' +order by block_row_number; + +update staging2.IHTBTD_BTD_Test_Res_6_Block +set column3 =(select split_part(column3,'- ',2) +from staging2.IHTBTD_BTD_Test_Res_6_Block where block_row_number=1) +where block_row_number=1; + +update staging2.IHTBTD_BTD_Test_Res_6_Block +set column6 =(select split_part(column6,'-',2) +from staging2.IHTBTD_BTD_Test_Res_6_Block where block_row_number=1) +where block_row_number=1; + +update staging2.IHTBTD_BTD_Test_Res_6_Block +set column8 =(select split_part(column8,'-',2) +from staging2.IHTBTD_BTD_Test_Res_6_Block where block_row_number=1) +where block_row_number=1; + + +update staging2.IHTBTD_BTD_Test_Res_6_Block a +set column2=(select split_part(column10,'-',3) +from staging2.IHTBTD_BTD_Test_Res_6_Block where block_row_number=1) where a.block_row_number=1; + +update staging2.IHTBTD_BTD_Test_Res_6_Block a +set column13=(select split_part(column10,'-',2) +from staging2.IHTBTD_BTD_Test_Res_6_Block where block_row_number=1) where a.block_row_number=1; + +update staging2.IHTBTD_BTD_Test_Res_6_Block set trx_record =0 where block_row_number in (1,2,3,13); + + update staging2.IHTBTD_BTD_Test_Res_6_Block a + set column2= b.first_value from (SELECT +block_row_number,column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column2, +sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBTD_BTD_Test_Res_6_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + +update staging2.IHTBTD_BTD_Test_Res_6_Block a + set column13= b.first_value from (SELECT +block_row_number,column13, value_partition, first_value(column13) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column13, +sum(case when column13 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTBTD_BTD_Test_Res_6_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number=b.block_row_number; + +update staging2.IHTBTD_BTD_Test_Res_6_Block set trx_record =0 +where column4 is null and column5 is null; + +update staging2.IHTBTD_BTD_Test_Res_6_Block set model=__model; +execute 'update staging2.IHTBTD_BTD_Test_Res_6_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBTD_BTD_Test_Res_6_Block'); + +/*block starts - IHTBTD_BTD_Test_Condition_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBTD_BTD_Test_Condition_Block',__file_mnemonic,__file_sheet_mnemonic,10); +err_block:='IHTBTD_BTD_Test_Condition_Block'; + + +insert into staging2.IHTBTD_BTD_Test_Condition_Block (condition) +select column2 from staging2.IHTBTD_BTD_Test_Res_1_Block +where block_row_number=2 +union +select column2 from staging2.IHTBTD_BTD_Test_Res_2_Block +where block_row_number=2 +union +select column2 from staging2.IHTBTD_BTD_Test_Res_3_Block +where block_row_number=2 +union +select column2 from staging2.IHTBTD_BTD_Test_Res_4_Block +where block_row_number=2 +union +select column2 from staging2.IHTBTD_BTD_Test_Res_5_Block +where block_row_number=2 +union +select column2 from staging2.IHTBTD_BTD_Test_Res_6_Block +where block_row_number=2; + + +update staging2.IHTBTD_BTD_Test_Condition_Block +set date=b.column4, +location=b.column7, +time=b.column9, +mode=b.column11 +from staging2.IHTBTD_BTD_Test_Res_1_Block b +where b.block_row_number =2 and condition=b.column2; + +update staging2.IHTBTD_BTD_Test_Condition_Block +set Wind_Velocity_Km_hr=b.column5, +Ambient_Temperature_C=b.column7, +Humidity_RH=b.column10 +from staging2.IHTBTD_BTD_Test_Res_1_Block b +where b.block_row_number =3 and condition=b.column2; + +update staging2.IHTBTD_BTD_Test_Condition_Block +set date=b.column4, +location=b.column7, +time=b.column9, +mode=b.column11 +from staging2.IHTBTD_BTD_Test_Res_2_Block b +where b.block_row_number =2 and condition=b.column2; + +update staging2.IHTBTD_BTD_Test_Condition_Block +set Wind_Velocity_Km_hr=b.column5, +Ambient_Temperature_C=b.column7, +Humidity_RH=b.column10 +from staging2.IHTBTD_BTD_Test_Res_2_Block b +where b.block_row_number =3 and condition=b.column2; + +update staging2.IHTBTD_BTD_Test_Condition_Block +set date=b.column4, +location=b.column7, +time=b.column9, +mode=b.column11 +from staging2.IHTBTD_BTD_Test_Res_3_Block b +where b.block_row_number =2 and condition=b.column2; + +update staging2.IHTBTD_BTD_Test_Condition_Block +set Wind_Velocity_Km_hr=b.column5, +Ambient_Temperature_C=b.column7, +Humidity_RH=b.column10 +from staging2.IHTBTD_BTD_Test_Res_3_Block b +where b.block_row_number =3 and condition=b.column2; + +update staging2.IHTBTD_BTD_Test_Condition_Block +set date=b.column4, +location=b.column7, +time=b.column9, +mode=b.column11 +from staging2.IHTBTD_BTD_Test_Res_4_Block b +where b.block_row_number =2 and condition=b.column2; + +update staging2.IHTBTD_BTD_Test_Condition_Block +set Wind_Velocity_Km_hr=b.column5, +Ambient_Temperature_C=b.column7, +Humidity_RH=b.column10 +from staging2.IHTBTD_BTD_Test_Res_4_Block b +where b.block_row_number=3 and condition=b.column2; + +update staging2.IHTBTD_BTD_Test_Condition_Block +set date=b.column4, +location=b.column7, +time=b.column9, +mode=b.column11 +from staging2.IHTBTD_BTD_Test_Res_5_Block b +where b.block_row_number =2 and condition=b.column2; + +update staging2.IHTBTD_BTD_Test_Condition_Block +set Wind_Velocity_Km_hr=b.column5, +Ambient_Temperature_C=b.column7, +Humidity_RH=b.column10 +from staging2.IHTBTD_BTD_Test_Res_5_Block b +where b.block_row_number =3 and condition=b.column2; + + +update staging2.IHTBTD_BTD_Test_Condition_Block +set date=b.column3, +location=b.column6, +time=b.column8, +mode=b.column13 +from staging2.IHTBTD_BTD_Test_Res_6_Block b +where b.block_row_number =1 and condition=b.column2; + +update staging2.IHTBTD_BTD_Test_Condition_Block +set Wind_Velocity_Km_hr=b.column9, +Ambient_Temperature_C=b.column10, +Humidity_RH=b.column11 +from staging2.IHTBTD_BTD_Test_Res_6_Block b +where b.block_row_number =3 and condition=b.column2; + +update staging2.IHTBTD_BTD_Test_Condition_Block a +set date= case + when date like '%-%' then date::timestamptz + else date '1899-12-30' + date::int * interval '1' day + end ; + + +update staging2.IHTBTD_BTD_Test_Condition_Block set model=__model; +execute 'update staging2.IHTBTD_BTD_Test_Condition_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBTD_BTD_Test_Condition_Block'); + +/*block starts - IHTBTD_BTD_Footer_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTBTD_BTD_Footer_block',__file_mnemonic,__file_sheet_mnemonic,11); +err_block:='IHTBTD_BTD_Footer_block'; + +insert into staging2.IHTBTD_BTD_Footer_block(dummy_f) values ('dummy'); + + +update staging2.IHTBTD_BTD_Footer_block a +set prepared_by=( select column6 from staging2.stg_process_table_IHTBTD_BTD b +where b.block_tag='IHTBTD_BTD_Footer' +and lower(column3)='prepared by' ) +where dummy_F='dummy'; + +update staging2.IHTBTD_BTD_Footer_block a +set reviewed_by=( select column6 from staging2.stg_process_table_IHTBTD_BTD b +where b.block_tag='IHTBTD_BTD_Footer' +and lower(column3)='reviewed by' ) +where dummy_F='dummy'; + +update staging2.IHTBTD_BTD_Footer_block a +set approved_by=( select column6 from staging2.stg_process_table_IHTBTD_BTD b +where b.block_tag='IHTBTD_BTD_Footer' +and lower(column3)='approved by' ) +where dummy_F='dummy'; + +update staging2.IHTBTD_BTD_Footer_block a +set comments=( select column3 from staging2.stg_process_table_IHTBTD_BTD b +where b.block_tag='IHTBTD_BTD_Footer' +and block_row_number=5 ) +where dummy_F='dummy'; + +update staging2.IHTBTD_BTD_Footer_block a +set rev1=( select column3 from staging2.stg_process_table_IHTBTD_BTD b +where b.block_tag='IHTBTD_BTD_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + + +update staging2.IHTBTD_BTD_Footer_block a +set rev2=( select column7 from staging2.stg_process_table_IHTBTD_BTD b +where b.block_tag='IHTBTD_BTD_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + +update staging2.IHTBTD_BTD_Footer_block a +set rev3=( select column11 from staging2.stg_process_table_IHTBTD_BTD b +where b.block_tag='IHTBTD_BTD_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + +update staging2.IHTBTD_BTD_Footer_block a +set replaces=( select column12 from staging2.stg_process_table_IHTBTD_BTD b +where b.block_tag='IHTBTD_BTD_Footer' +and block_row_number=1) +where dummy_F='dummy'; + +update staging2.IHTBTD_BTD_Footer_block a +set revision_no=( select column12 from staging2.stg_process_table_IHTBTD_BTD b +where b.block_tag='IHTBTD_BTD_Footer' +and block_row_number=3) +where dummy_F='dummy'; + +update staging2.IHTBTD_BTD_Footer_block a +set prepared_date=( select column11 from staging2.stg_process_table_IHTBTD_BTD b +where b.block_tag='IHTBTD_BTD_Footer' +and block_row_number=1) +where dummy_F='dummy'; + +update staging2.IHTBTD_BTD_Footer_block a +set reviewed_date=( select column11 from staging2.stg_process_table_IHTBTD_BTD b +where b.block_tag='IHTBTD_BTD_Footer' +and block_row_number=2) +where dummy_F='dummy'; + +update staging2.IHTBTD_BTD_Footer_block a +set approved_date=( select column11 from staging2.stg_process_table_IHTBTD_BTD b +where b.block_tag='IHTBTD_BTD_Footer' +and block_row_number=3) +where dummy_F='dummy'; + +update staging2.IHTBTD_BTD_Footer_block set model=__model; +execute 'update staging2.IHTBTD_BTD_Footer_block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTBTD_BTD_Footer_block'); + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_IHTBTD_BTD_block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + diff --git a/onetime/dataloadfunctions/IHT/IHT_CGM_ODS.sql b/onetime/dataloadfunctions/IHT/IHT_CGM_ODS.sql new file mode 100755 index 0000000..ada55bf --- /dev/null +++ b/onetime/dataloadfunctions/IHT/IHT_CGM_ODS.sql @@ -0,0 +1,336 @@ +drop function if exists staging2.fn_IHTCGM_CGM_TRX; +CREATE OR REPLACE FUNCTION staging2.fn_IHTCGM_CGM_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + declare __test_instance_tractor_id int; + begin +__file_syspk := p_file_syspk; + +/************************************************************ +Function Name:fn_IHTCGM_CGM_TRX +Function Desc: This function populates data into ODS +File Format: IHTCGM +Sheet Format: IHTCGM_CGM +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_IHTCGM_CGM_TRX() +***************************************************************/ +insert into transactional.test_instance +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +job_order_no, +sample_receipt_date, +test_report_no, +generation, +customer_name, +test_engineer, +test_report_date, +no_of_sample, +test_start_date, +test_end_date, +tractor_sr_no, +test_standard_ref, +test_location_name, +test_operator, +project_group, +objective_of_test, +acceptance_criteria, +remarks +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +Test_Request_no, +date '1899-12-30' + sample_receipt_date::int * interval '1' day as Sample_Receipt_Date, +Test_report_No, +Generation, +Customer_Name, +Test_Engineer, +date '1899-12-30' + Test_Report_Date::int * interval '1' day as Test_Report_Date, +No_of_Sample, +date '1899-12-30' + Test_Start_Date::int * interval '1' day as Test_Start_Date, +date '1899-12-30' + Test_End_Date::int * interval '1' day as Test_End_Date, +Tractor_Sr_No, +Test_Standard_Refer, +Test_Location, +Operator_Name, +Project_Group, +Objective, +Acceptance_Criteria, +Remarks +from staging2.IHTCGM_CGM_H1_block where trx_record=1; + +update transactional.test_instance a +set +report_prepared_date=to_date(b.prepared_date,'DD-MM-YYYY'), +report_reviewed_date=to_date(b.reviewed_date,'DD-MM-YYYY'), +report_approved_date=to_date(b.approved_date,'DD-MM-YYYY'), +report_prepared_by=b.prepared_by, +report_reviewed_by=b.reviewed_by, +report_approved_by=b.approved_by, +report_template_replaces=b.replaces, +report_title=b.comments, +report_template_no=b.rev1, +report_template_rev_date=b.rev2, +report_template_rev_no= b.rev3 +from staging2.IHTCGM_CGM_footer_block b +where a.file_sheet_mnemonic ='IHTCGM_CGM' and trx_record=1; + +insert into transactional.test_instance_tyre_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +tyre_type, +tyre_make, +tyre_size, +tyre_ply_rating, +tyre_load_carrying_capacity, +tyre_pressure_kg_per_cm2, +tyre_static_rolling_radius_mm, +tyre_dynamic_rolling_radius_mm, +tyre_wheel_rim_make_and_size +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +tyre_details, +tyre_make, +tyre_size, +ply_rating::numeric, +load_carrying_capacity, +Pressure_kg_cm2::numeric , +Dynamic_rolling_radius::numeric , +Static_rolling_radius::numeric , +wheel_rim_make_size +from staging2.IHTCGM_CGM_tyre_details_block where trx_record=1; + + insert into transactional.test_instance_tractor_info + ( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +wheel_base_mm, +rear_track_width_mm +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +wheel_base::numeric , +rear_track_width::numeric +from staging2.IHTCGM_CGM_wheel_block where trx_record=1; + +update transactional.test_instance_tractor_info +set mahindra_model_yn = ( +case when tractor_make like 'Mahindra%' then 'Y' else 'N' end +) where file_syspk =__file_syspk; + +update transactional.test_instance_tractor_info a +set test_tractor_yn ='Y' where syspk in +(select min(syspk) from transactional.test_instance_tractor_info b +where b.file_syspk =a.file_syspk) +and a.file_syspk =__file_syspk; + +/*block */ + +insert into transactional.test_instance_weight_reaction +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +total_weight_kg, +front_reaction_kg, +rear_reaction_kg, +left_reaction_fl_rl_kg, +right_reaction_fr_rr_kg, +front_left_reaction_kg, +front_right_reactionkg, +rear_left_reaction_kg, +rear_right_reactionkg, +distance_of_lifting_point_from_rear_axle_mm_d1 +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +Weight_Reaction, +Total_Weight_kg::numeric, +Front_Reaction_kg::numeric , +Rear_Reaction_kg::numeric , +Left_Reaction_FL_RL_kg::numeric , +Right_reaction_FR_RR_kg::numeric , +Front_Left_Reaction_kg::numeric , +Front_Right_Reaction_kg::numeric , +Rear_Left_Reaction_kg::numeric , +Rear_Right_Reaction_kg::numeric , +Distance_of_lifting_point_from_rear_axle_mm_d1::numeric +from staging2.IHTCGM_CGM_weight_block where trx_record=1; + + +insert into transactional.IHT_cgm_lifting_angle_load_details +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +angle, +value_in_tan, +diff_of_tan_value, +load_kn, +load_kg, +diff_in_load_kg, +vertical_co_ordinate_z_mm +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column3::numeric, +column4::numeric , +column5::numeric, +column7::numeric, +column8::numeric, +column9::numeric, +column10::numeric +from staging2.IHTCGM_cgm_lifting_block where trx_record=1; + +insert into transactional.IHT_cgm_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +horizontal_distance_from_rac_x_mm, +lateral_co_ordinate_in_horizontal_plane_y_mm, +vertical_co_ordinate_z_mm +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +determination_of_horizontal_distance_from_rac_x::numeric , +determination_of_lateral_coordinate_in_horizontal_plane_y::numeric , +determination_of_vertical_coordinate_z::numeric +from staging2.IHTCGM_cgm_results_block where trx_record=1; + + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk; +select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk; +select syspk from transactional.test_master into __test_master_id where test_type ='In House'; +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk; + + +update transactional.test_instance +set test_master_id =__test_master_id, +test_tractor_id =__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.test_instance_tyre_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.test_instance_weight_reaction +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.IHT_cgm_lifting_angle_load_details +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.IHT_cgm_results +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_IHTCGM_CGM_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + diff --git a/onetime/dataloadfunctions/IHT/IHT_CGM_STG2.sql b/onetime/dataloadfunctions/IHT/IHT_CGM_STG2.sql new file mode 100755 index 0000000..6826a60 --- /dev/null +++ b/onetime/dataloadfunctions/IHT/IHT_CGM_STG2.sql @@ -0,0 +1,565 @@ +drop function if exists staging2.fn_IHTCGM_CGM_block; +CREATE OR REPLACE FUNCTION staging2.fn_IHTCGM_CGM_block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + + begin + +/************************************************************ +Function Name:fn_IHTCGM_CGM_block +Function Desc: This function populates data into staging 2 block +File Format: IHTCGM +Sheet Format: IHTCGM_CGM +Creation Date: March 25 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_IHTCGM_CGM_block(p_client_id,p_function_id, p_file_mnemonic, +p_file_sheet_mnemonic, p_file_syspk) +Function call ex: select staging2.fn_IHTCGM_CGM_block(1,2,'IHTCGM','IHTCGM_CGM',456) +***************************************************************/ + + +SET search_path TO staging2; + +/* to process multiple files - re-runnability*/ + +truncate table staging2.IHTCGM_CGM_H1_Int; +truncate table staging2.IHTCGM_CGM_H1_block; +truncate table staging2.IHTCGM_CGM_Weight_Tyre_Int; +truncate table staging2.IHTCGM_CGM_Weight_Block; +truncate table staging2.IHTCGM_CGM_Wheel_Block; +truncate table staging2.IHTCGM_CGM_Tyre_Details_Block; +truncate table staging2.IHTCGM_CGM_Lifting_Block; +truncate table staging2.IHTCGM_CGM_Results_Block; +truncate table staging2.IHTCGM_CGM_Footer_Block; +truncate table staging2.stg_specific_table_IHTCGM_CGM; +truncate table staging2.stg_process_table_IHTCGM_CGM; + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* transfer data from generic to specific for IHTCGM */ +execute 'insert into staging2.stg_specific_table_IHTCGM_CGM +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_IHTCGM_CGM; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for IHT CGM', + detail = 'No data in table stg_specific_table_IHTCGM_CGM', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + +/* trimming data */ +update staging2.stg_specific_table_IHTCGM_CGM +set column15='Objective' where lower(column15) like 'objective%'; + +update staging2.stg_specific_table_IHTCGM_CGM +set column15='Acceptance criteria' where lower(column15) like 'acceptance criteria%'; + +update transactional.source_config set F1_source=F1_modified ; + + +/* keyword match in config table*/ +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_IHTCGM_CGM b +where upper(F1_modified)=upper(column3) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update in process table for match*/ +execute 'update staging2.stg_specific_table_IHTCGM_CGM a +set is_rownumber_fetched=1 +from transactional.source_config b +where upper(F1_modified)=upper(column3) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* update config files for row numbers start, end */ +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a +set row_read_end = null ,run_time=current_timestamp +where f1_modified =''Prepared by'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers*/ +execute 'insert into staging2.stg_process_table_IHTCGM_CGM +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTCGM_CGM a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Request no.'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTCGM_CGM +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTCGM_CGM a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Weight Reaction'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTCGM_CGM +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTCGM_CGM a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Lifting Angle & Load'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'insert into staging2.stg_process_table_IHTCGM_CGM +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTCGM_CGM a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Prepared by'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/*selecting tractor model*/ +select column6 into __model from staging2.stg_process_table_IHTCGM_CGM a +where block_tag='IHTCGM_CGM_H1' and trim(column3)='Tractor Model'; + +/*block starts - IHTCGM_CGM_H1_BLOCK */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTCGM_CGM_H1_BLOCK',__file_mnemonic,__file_sheet_mnemonic,1); +err_block:='IHTCGM_CGM_H1_BLOCK'; + +insert into staging2.IHTCGM_CGM_H1_INT (c1,c2) +select a.column3,column6 from staging2.stg_process_table_IHTCGM_CGM a where block_tag='IHTCGM_CGM_H1'; + +insert into staging2.IHTCGM_CGM_H1_INT (c1,c2) +select a.column9,column12 from staging2.stg_process_table_IHTCGM_CGM a where block_tag='IHTCGM_CGM_H1'; + +insert into staging2.IHTCGM_CGM_H1_INT (c1,c2) +select 'Objective',column15 +from staging2.stg_process_table_IHTCGM_CGM a +where block_tag='IHTCGM_CGM_H1' +and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTCGM_CGM a +where column15='Objective' +and block_tag='IHTCGM_CGM_H1' +); + +insert into staging2.IHTCGM_CGM_H1_INT (c1,c2) +select 'Acceptance criteria',column15 +from staging2.stg_process_table_IHTCGM_CGM a +where block_tag='IHTCGM_CGM_H1' +and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTCGM_CGM a +where column15='Acceptance criteria' +and block_tag='IHTCGM_CGM_H1' +); + +insert into staging2.IHTCGM_CGM_H1_INT (c1,c2) +select split_part(column3,':',1),split_part(column3,':',2) +from staging2.stg_process_table_IHTCGM_CGM +where block_tag='IHTCGM_CGM_Lifting' and block_row_number=15; + +insert into staging2.IHTCGM_CGM_H1_INT (c1,c2) +select 'Test Purpose',column10 +from staging2.stg_process_table_IHTCGM_CGM a +where block_tag='IHTCGM_CGM_H1' and column3='Test Purpose'; + +update staging2.IHTCGM_CGM_H1_Int set model=__model; +execute 'update staging2.IHTCGM_CGM_H1_Int set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +insert into staging2.IHTCGM_CGM_H1_Block +( +dummy_f, +Test_Request_no, +Sample_Receipt_Date, +Test_report_No, +Tractor_Model, +Generation, +Customer_Name, +Test_Engineer, +Test_Report_Date, +No_of_Sample, +Test_Start_Date, +Test_End_Date, +Tractor_Sr_No, +Test_Standard_Refer, +Test_Location, +Operator_Name, +Project_Group, +Objective, +Acceptance_Criteria, +Remarks, +Test_Purpose +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{c2}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[c2::text]) AS val + FROM staging2.IHTCGM_CGM_H1_INT + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text, + a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text, + a_18 text,a_19 text,a_20 text); + + +delete from staging2.IHTCGM_CGM_H1_Block where dummy_f is null ; +update staging2.IHTCGM_CGM_H1_Block set model=__model; +execute 'update staging2.IHTCGM_CGM_H1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTCGM_CGM_H1_BLOCK'); + + +insert into staging2.IHTCGM_CGM_Weight_Tyre_Int +( +column3,column6,column10,column11,column13,column15,column17,column19, +column20,block_row_number +) +select +column3,column6,column10,column11,column13,column15,column17,column19, +column20,block_row_number +from staging2.stg_process_table_IHTCGM_CGM a +where block_tag='IHTCGM_CGM_Weight_Tyre' +order by block_row_number; + +update staging2.IHTCGM_CGM_Weight_Tyre_Int set model=__model; +execute 'update staging2.IHTCGM_CGM_Weight_Tyre_Int set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +update staging2.IHTCGM_CGM_Weight_Tyre_Int set trx_record = 0 where block_row_number=3; + +/*block starts - IHTCGM_CGM_Weight_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTCGM_CGM_Weight_Block',__file_mnemonic,__file_sheet_mnemonic,2); +err_block:='IHTCGM_CGM_Weight_Block'; + +insert into staging2.IHTCGM_CGM_Weight_Block +( +dummy_f, +Weight_Reaction, +Total_Weight_kg, +Front_Reaction_kg, +Rear_Reaction_kg, +Left_Reaction_FL_RL_kg, +Right_reaction_FR_RR_kg, +Front_Left_Reaction_kg, +Front_Right_Reaction_kg, +Rear_Left_Reaction_kg, +Rear_Right_Reaction_kg, +Distance_of_lifting_point_from_rear_axle_mm_d1 +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column6}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column6::text]) AS val + FROM staging2.IHTCGM_CGM_Weight_Tyre_Int where trx_record=1 + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text, + a_10 text,a_11 text); + +delete from staging2.IHTCGM_CGM_Weight_Block where dummy_f is null ; +update staging2.IHTCGM_CGM_Weight_Block set model=__model; +execute 'update staging2.IHTCGM_CGM_Weight_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTCGM_CGM_Weight_Block'); + +/*block starts - IHTCGM_CGM_Tyre_Details_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTCGM_CGM_Tyre_Details_Block',__file_mnemonic,__file_sheet_mnemonic,3); +err_block:='IHTCGM_CGM_Tyre_Details_Block'; +insert into staging2.IHTCGM_CGM_Tyre_Details_Block +( +dummy_f, +Tyre_Details, +Tyre_Make, +Tyre_size, +Ply_Rating, +Load_Carrying_Capacity, +Pressure_kg_cm2, +Dynamic_rolling_radius, +Static_rolling_radius, +Wheel_rim_Make_size +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column15,column19}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column15::text,column19::text]) AS val + FROM staging2.IHTCGM_CGM_Weight_Tyre_Int where block_row_number between 3 and 11 + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text); + +delete from staging2.IHTCGM_CGM_Tyre_Details_Block where dummy_f is null ; +update staging2.IHTCGM_CGM_Tyre_Details_Block set model=__model; +execute 'update staging2.IHTCGM_CGM_Tyre_Details_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTCGM_CGM_Tyre_Details_Block'); + + +/*block starts - IHTCGM_CGM_Wheel_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTCGM_CGM_Wheel_Block',__file_mnemonic,__file_sheet_mnemonic,4); +err_block:='IHTCGM_CGM_Wheel_Block'; +insert into staging2.IHTCGM_CGM_Wheel_Block(dummy_f) values ('dummy'); + +update staging2.IHTCGM_CGM_Wheel_Block +set Wheel_Base=(select column13 from +staging2.IHTCGM_CGM_Weight_Tyre_Int +where block_row_number=1 and column10='Wheel Base in mm') +where dummy_f='dummy'; + +update staging2.IHTCGM_CGM_Wheel_Block +set Rear_Track_Width=(select column20 from +staging2.IHTCGM_CGM_Weight_Tyre_Int +where block_row_number=1 and column17='Rear Track Width in mm') +where dummy_f='dummy'; + + +update staging2.IHTCGM_CGM_Wheel_Block set model=__model; +execute 'update staging2.IHTCGM_CGM_Wheel_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTCGM_CGM_Wheel_Block'); + +/*block starts - IHTCGM_CGM_Lifting_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTCGM_CGM_Lifting_Block',__file_mnemonic,__file_sheet_mnemonic,5); +err_block:='IHTCGM_CGM_Lifting_Block'; + +insert into staging2.IHTCGM_CGM_Lifting_Block +( +column3,column4,column5,column6,column7, +column8,column9,column10,block_row_number +) +select +column3,column4,column5,column6,column7, +column8,column9,column10,block_row_number +from staging2.stg_process_table_IHTCGM_CGM a +where block_tag='IHTCGM_CGM_Lifting' +order by block_row_number; + + + +update staging2.IHTCGM_CGM_Lifting_Block set model=__model; +execute 'update staging2.IHTCGM_CGM_Lifting_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +update staging2.IHTCGM_CGM_Lifting_Block set trx_record =0 where block_row_number not in (3,4,5,6,7,8,9); + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTCGM_CGM_Lifting_Block'); + + +/*block starts - IHTCGM_CGM_Results_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTCGM_CGM_Results_Block',__file_mnemonic,__file_sheet_mnemonic,6); +err_block:='IHTCGM_CGM_Results_Block'; +insert into staging2.IHTCGM_CGM_Results_Block (dummy_f) values('dummy'); + +update staging2.IHTCGM_CGM_Results_Block +set Determination_of_Horizontal_Distance_from_RAC_X= +(select column10 from staging2.IHTCGM_CGM_Lifting_Block +where block_row_number=12) where dummy_f='dummy'; + +update staging2.IHTCGM_CGM_Results_Block +set Determination_of_Lateral_CoOrdinate_in_Horizontal_Plane_Y= +(select column10 from staging2.IHTCGM_CGM_Lifting_Block +where block_row_number=13) where dummy_f='dummy'; + +update staging2.IHTCGM_CGM_Results_Block +set Determination_of_Vertical_CoOrdinate_Z= +(select column10 from staging2.IHTCGM_CGM_Lifting_Block +where block_row_number=14) where dummy_f='dummy'; + + +update staging2.IHTCGM_CGM_Results_Block set model=__model; +execute 'update staging2.IHTCGM_CGM_Results_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTCGM_CGM_Results_Block'); + + +/*block starts - IHTCGM_CGM_Footer_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTCGM_CGM_Footer_block',__file_mnemonic,__file_sheet_mnemonic,8); +err_block='IHTCGM_CGM_Footer_block'; +insert into staging2.IHTCGM_CGM_Footer_block(dummy_f) values ('dummy'); + +update staging2.IHTCGM_CGM_Footer_block a +set prepared_by=( select column7 from staging2.stg_process_table_IHTCGM_CGM b +where b.block_tag='IHTCGM_CGM_Footer' +and lower(column3)='prepared by' ) +where dummy_F='dummy'; + +update staging2.IHTCGM_CGM_Footer_block a +set reviewed_by=( select column7 from staging2.stg_process_table_IHTCGM_CGM b +where b.block_tag='IHTCGM_CGM_Footer' +and lower(column3)='reviewed by' ) +where dummy_F='dummy'; + +update staging2.IHTCGM_CGM_Footer_block a +set approved_by=( select column7 from staging2.stg_process_table_IHTCGM_CGM b +where b.block_tag='IHTCGM_CGM_Footer' +and lower(column3)='approved by' ) +where dummy_F='dummy'; + +update staging2.IHTCGM_CGM_Footer_block a +set comments=( select column3 from staging2.stg_process_table_IHTCGM_CGM b +where b.block_tag='IHTCGM_CGM_Footer' +and block_row_number=5 ) +where dummy_F='dummy'; + +update staging2.IHTCGM_CGM_Footer_block a +set rev1=( select column3 from staging2.stg_process_table_IHTCGM_CGM b +where b.block_tag='IHTCGM_CGM_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + + +update staging2.IHTCGM_CGM_Footer_block a +set rev2=( select column9 from staging2.stg_process_table_IHTCGM_CGM b +where b.block_tag='IHTCGM_CGM_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + +update staging2.IHTCGM_CGM_Footer_block a +set rev3=( select column18 from staging2.stg_process_table_IHTCGM_CGM b +where b.block_tag='IHTCGM_CGM_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + +update staging2.IHTCGM_CGM_Footer_block a +set replaces=( select column19 from staging2.stg_process_table_IHTCGM_CGM b +where b.block_tag='IHTCGM_CGM_Footer' +and block_row_number=1) +where dummy_F='dummy'; + +update staging2.IHTCGM_CGM_Footer_block a +set revision_no=( select column19 from staging2.stg_process_table_IHTCGM_CGM b +where b.block_tag='IHTCGM_CGM_Footer' +and block_row_number=1) +where dummy_F='dummy'; + +update staging2.IHTCGM_CGM_Footer_block a +set prepared_date=( select column16 from staging2.stg_process_table_IHTCGM_CGM b +where b.block_tag='IHTCGM_CGM_Footer' +and block_row_number=1) +where dummy_F='dummy'; + +update staging2.IHTCGM_CGM_Footer_block a +set reviewed_date=( select column16 from staging2.stg_process_table_IHTCGM_CGM b +where b.block_tag='IHTCGM_CGM_Footer' +and block_row_number=2) +where dummy_F='dummy'; + +update staging2.IHTCGM_CGM_Footer_block a +set approved_date=( select column16 from staging2.stg_process_table_IHTCGM_CGM b +where b.block_tag='IHTCGM_CGM_Footer' +and block_row_number=3) +where dummy_F='dummy'; + +update staging2.IHTCGM_CGM_Footer_block set model=__model; +execute 'update staging2.IHTCGM_CGM_Footer_block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTCGM_CGM_Footer_block'); +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_IHTCGM_CGM_block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + diff --git a/onetime/dataloadfunctions/IHT/IHT_EMT_ODS.sql b/onetime/dataloadfunctions/IHT/IHT_EMT_ODS.sql new file mode 100755 index 0000000..e134c51 --- /dev/null +++ b/onetime/dataloadfunctions/IHT/IHT_EMT_ODS.sql @@ -0,0 +1,434 @@ +drop function if exists staging2.fn_IHTEMT_EMT_TRX; +CREATE OR REPLACE FUNCTION staging2.fn_IHTEMT_EMT_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + declare __test_instance_tractor_id int; + begin +__file_syspk := p_file_syspk; + +/************************************************************ +Function Name:fn_IHTEMT_EMT_TRX +Function Desc: This function populates data into ODS +File Format: IHTEMT +Sheet Format: IHTEMT_EMT +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_IHTEMT_EMT_TRX() +***************************************************************/ +insert into transactional.test_instance +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +job_order_no, +sample_receipt_date, +test_report_no, +generation, +customer_name, +test_engineer, +test_report_date, +no_of_sample, +test_start_date, +test_end_date, +tractor_sr_no, +test_standard_ref, +test_location_name, +test_operator, +project_group, +objective_of_test, +acceptance_criteria, +remarks, +test_purpose +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +Test_Request_no, +date '1899-12-30' + sample_receipt_date::int * interval '1' day as Sample_Receipt_Date, +Test_report_No, +Generation, +Customer_Name, +Test_Engineer, +date '1899-12-30' + Test_Report_Date::int * interval '1' day as Test_Report_Date, +No_of_Sample, +date '1899-12-30' + Test_Start_Date ::int * interval '1' day as Test_Start_Date, +date '1899-12-30' + Test_End_Date ::int * interval '1' day as Test_End_Date, +Tractor_Sr_No, +Test_Standard_Refer, +Test_Location, +Operator_Name, +Project_Group, +Objective, +Acceptance_Criteria, +Remarks, +Test_Purpose +from staging2.IHTEMT_EMT_H1_block where trx_record =1; + +update transactional.test_instance a +set +report_prepared_date=to_date(b.prepared_date,'DD-MM-YYYY'), +report_reviewed_date=to_date(b.reviewed_date,'DD-MM-YYYY'), +report_approved_date=to_date(b.approved_date,'DD-MM-YYYY'), +report_prepared_by=b.prepared_by, +report_reviewed_by=b.reviewed_by, +report_approved_by=b.approved_by, +report_template_replaces=b.replaces, +report_title=b.comments, +report_template_no=b.rev1, +report_template_rev_date=b.rev2, +report_template_rev_no= b.rev3 +from staging2.IHTEMT_EMT_footer_block b +where a.file_sheet_mnemonic ='IHTEMT_EMT' and trx_record =1; + +insert into transactional.test_instance_tyre_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +tyre_type, +tyre_make, +tyre_size, +tyre_ply_rating, +tyre_load_carrying_capacity, +tyre_pressure_kg_per_cm2, +tyre_static_rolling_radius_mm, +tyre_dynamic_rolling_radius_mm, +tyre_wheel_rim_make_and_size +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +tyre_details, +tyre_make, +tyre_size, +ply_rating::numeric, +load_carrying_capacity, +Pressure_kg_cm2::numeric , +Dynamic_rolling_radius::numeric , +Static_rolling_radius::numeric , +wheel_rim_make_size +from staging2.IHTEMT_EMT_tyre_details_block where trx_record =1; + + insert into transactional.test_instance_tractor_info + ( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +wheel_base_mm, +turning_circle_diameter_mm +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +wheel_base::numeric , +tcd::numeric +from staging2.IHTEMT_EMT_wheel_block where trx_record =1; + +update transactional.test_instance_tractor_info +set mahindra_model_yn = ( +case when tractor_make like 'Mahindra%' then 'Y' else 'N' end +) where file_syspk =__file_syspk; + +update transactional.test_instance_tractor_info a +set test_tractor_yn ='Y' where syspk in +(select min(syspk) from transactional.test_instance_tractor_info b +where b.file_syspk =a.file_syspk) +and a.file_syspk =__file_syspk; + + +/*block */ + +insert into transactional.test_instance_weight_reaction +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +total_weight_kg, +front_reaction_kg, +rear_reaction_kg, +left_reaction_fl_rl_kg, +right_reaction_fr_rr_kg, +front_left_reaction_kg, +front_right_reactionkg, +rear_left_reaction_kg, +rear_right_reactionkg, +distance_of_lifting_point_from_rear_axle_mm_d1 +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +Weight_Reaction, +Total_Weight_kg::numeric, +Front_Reaction_kg::numeric , +Rear_Reaction_kg::numeric , +Left_Reaction_FL_RL_kg::numeric , +Right_reaction_FR_RR_kg::numeric , +Front_Left_Reaction_kg::numeric , +Front_Right_Reaction_kg::numeric , +Rear_Left_Reaction_kg::numeric , +Rear_Right_Reaction_kg::numeric , +Distance_of_lifting_point_from_rear_axle_mm_d1::numeric +from staging2.IHTEMT_EMT_weight_block where trx_record =1; + + +insert into transactional.IHT_steering_effort +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +test_speed_kmph, +max_angle_lh, +max_angle_rh, +max_effort_lh, +max_effort_rh +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column2, +column3, +column4::numeric, +column5::numeric, +column6::numeric, +column8::numeric +from staging2.IHTEMT_emt_steering_block where trx_record=1; + +insert into transactional.IHT_pedal_effort +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +parameters, +efforts_kg, +travel_mm +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column2, +column3::numeric , +column4::numeric +from staging2.IHTEMT_emt_pedal_block where trx_record=1; + +insert into transactional.IHT_gear_effort +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +parameters, +efforts_kg +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column5, +column8::numeric +from staging2.IHTEMT_emt_pedal_block where trx_record=1; + +insert into transactional.IHT_brake_pedal_effort +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +srl_no, +pedal_effort_kg, +pedal_travel_lh_mm, +pedal_travel_rh_mm, +pedal_travel_latched_mm +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column2::numeric, +column3::numeric, +column4::numeric , +column5::numeric, +column6::numeric +from staging2.IHTEMT_emt_brake_pedal_block where trx_record=1; + +insert into transactional.IHT_clutch_pedal_effort +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +srl_no, +pedal_effort_kg, +pedal_travel_mm +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column7::numeric, +column8::numeric, +column9::numeric +from staging2.IHTEMT_emt_brake_pedal_block where trx_record=1; + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk; +select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk; +select syspk from transactional.test_master into __test_master_id where test_type ='In House'; +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk; + + +update transactional.test_instance +set test_master_id =__test_master_id, +test_tractor_id =__test_instance_tractor_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.test_instance_tyre_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.test_instance_weight_reaction +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.IHT_brake_pedal_effort +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.IHT_pedal_effort +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.IHT_steering_effort +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.IHT_gear_effort +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.IHT_clutch_pedal_effort +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_IHTEMT_EMT_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + diff --git a/onetime/dataloadfunctions/IHT/IHT_EMT_STD_ODS.sql b/onetime/dataloadfunctions/IHT/IHT_EMT_STD_ODS.sql new file mode 100755 index 0000000..2e15fd4 --- /dev/null +++ b/onetime/dataloadfunctions/IHT/IHT_EMT_STD_ODS.sql @@ -0,0 +1,91 @@ + +drop function if exists staging2.fn_IHTEMT_STD_TRX; +CREATE OR REPLACE FUNCTION staging2.fn_IHTEMT_STD_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + declare __test_instance_tractor_id int; + begin +__file_syspk := p_file_syspk; + +/************************************************************ +Function Name:fn_IHTEMT_STD_TRX +Function Desc: This function populates data into ODS +File Format: IHTEMT +Sheet Format: IHTEMT_STD +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_IHTEMT_STD_TRX() +***************************************************************/ + +insert into transactional.iht_steering_effort_raw_data +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +time_sec, +steering_anglel, +effort_kg +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +time_s::numeric, +steering_angle ::numeric, +effort ::numeric +from staging2.IHTEMT_STD_RAW_Data_Block where trx_record=1; + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk; +select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk; +select syspk from transactional.test_master into __test_master_id where test_type ='In House'; +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk; + + +update transactional.test_instance +set test_master_id =__test_master_id, +test_tractor_id =__test_instance_tractor_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_IHTEMT_STD_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + diff --git a/onetime/dataloadfunctions/IHT/IHT_EMT_STD_STG2.sql b/onetime/dataloadfunctions/IHT/IHT_EMT_STD_STG2.sql new file mode 100755 index 0000000..205276b --- /dev/null +++ b/onetime/dataloadfunctions/IHT/IHT_EMT_STD_STG2.sql @@ -0,0 +1,149 @@ +drop function if exists staging2.fn_IHTEMT_STD_block; +CREATE OR REPLACE FUNCTION staging2.fn_IHTEMT_STD_block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + + begin + +/************************************************************ +Function Name:fn_IHTEMT_STD_block +Function Desc: This function populates data into staging 2 block +File Format: IHTEMT +Sheet Format: IHTEMT_STD +Creation Date: March 25 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_IHTEMT_STD_block(p_client_id,p_function_id, p_file_mnemonic, +p_file_sheet_mnemonic, p_file_syspk) +Function call ex: select staging2.fn_IHTEMT_STD_block(1,2,'IHTEMT','IHTEMT_STD',456) +***************************************************************/ + + +SET search_path TO staging2; + +/* to process multiple files - re-runnability*/ + +truncate table staging2.IHTEMT_STD_RAW_Data_Block; +truncate table staging2.stg_specific_table_IHTEMT_STD; +truncate table staging2.stg_process_table_IHTEMT_STD; + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* transfer data from generic to specific for IHTEMT */ +execute 'insert into staging2.stg_specific_table_IHTEMT_STD +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_IHTEMT_STD; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for IHTEMT STD', + detail = 'No data in table stg_specific_table_IHTEMT_STD', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + +update transactional.source_config set F1_source=F1_modified ; + + +/* keyword match in config table*/ +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_IHTEMT_STD b +where upper(F1_modified)=upper(column1) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update in process table for match*/ +execute 'update staging2.stg_specific_table_IHTEMT_STD a +set is_rownumber_fetched=1 +from transactional.source_config b +where upper(F1_modified)=upper(column1) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* update config files for row numbers start, end */ +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a +set row_read_end = null ,run_time=current_timestamp +where f1_modified =''Steering effort RAW data'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers*/ +execute 'insert into staging2.stg_process_table_IHTEMT_STD +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTEMT_STD a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Steering effort RAW data'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/*block starts - IHTEMT_STD_H1_BLOCK */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTEMT_STD_RAW_Data_Block',__file_mnemonic,__file_sheet_mnemonic,1); + +err_block:='IHTEMT_STD_RAW_Data_Block'; +insert into staging2.IHTEMT_STD_RAW_Data_Block (Time_s,Steering_Angle,Effort,block_row_number) +select a.column1,column2,column3,block_row_number from staging2.stg_process_table_IHTEMT_STD a +where block_tag='IHTEMT_STD_RAW_Data'; + + +execute 'update staging2.IHTEMT_STD_RAW_Data_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +update staging2.IHTEMT_STD_RAW_Data_Block set trx_record =0 where block_row_number in (1,2,3); + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTEMT_STD_RAW_Data_Block'); +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_IHTEMT_STD_block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + diff --git a/onetime/dataloadfunctions/IHT/IHT_EMT_STG2.sql b/onetime/dataloadfunctions/IHT/IHT_EMT_STG2.sql new file mode 100755 index 0000000..ac9f135 --- /dev/null +++ b/onetime/dataloadfunctions/IHT/IHT_EMT_STG2.sql @@ -0,0 +1,615 @@ +drop function if exists staging2.fn_IHTEMT_EMT_block; +CREATE OR REPLACE FUNCTION staging2.fn_IHTEMT_EMT_block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + + begin + +/************************************************************ +Function Name:fn_IHTEMT_EMT_block +Function Desc: This function populates data into staging 2 block +File Format: IHTEMT +Sheet Format: IHTEMT_EMT +Creation Date: March 25 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_IHTEMT_EMT_block(p_client_id,p_function_id, p_file_mnemonic, +p_file_sheet_mnemonic, p_file_syspk) +Function call ex: select staging2.fn_IHTEMT_EMT_block(1,2,'IHTEMT','IHTEMT_EMT',456) +***************************************************************/ + + +SET search_path TO staging2; + +/* to process multiple files - re-runnability*/ + +truncate table staging2.IHTEMT_EMT_H1_INT; +truncate table staging2.IHTEMT_EMT_H1_block; +truncate table staging2.IHTEMT_EMT_Weight_Tyre_Int; +truncate table staging2.IHTEMT_EMT_Weight_Block; +truncate table staging2.IHTEMT_EMT_Wheel_Block; +truncate table staging2.IHTEMT_EMT_Tyre_Details_Block; +truncate table staging2.IHTEMT_EMT_Steering_Block; +truncate table staging2.IHTEMT_EMT_Pedal_Block; +truncate table staging2.IHTEMT_EMT_Brake_Pedal_Block; +truncate table staging2.IHTEMT_EMT_Footer_Block; +truncate table staging2.stg_specific_table_IHTEMT_EMT; +truncate table staging2.stg_process_table_IHTEMT_EMT; + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* transfer data from generic to specific for IHTEMT */ +execute 'insert into staging2.stg_specific_table_IHTEMT_EMT +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_IHTEMT_EMT; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for IHTEMT EMT', + detail = 'No data in table stg_specific_table_IHTEMT_EMT', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + +/* trimming data */ +update staging2.stg_specific_table_IHTEMT_EMT +set column14='Objective' where lower(column14) like 'objective%'; + +update staging2.stg_specific_table_IHTEMT_EMT +set column14='Acceptance criteria' where lower(column14) like 'acceptance criteria%'; + + +update transactional.source_config set F1_source=F1_modified ; + +/* keyword match in config table*/ +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_IHTEMT_EMT b +where upper(F1_modified)=upper(column2) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update in process table for match*/ +execute 'update staging2.stg_specific_table_IHTEMT_EMT a +set is_rownumber_fetched=1 +from transactional.source_config b +where upper(F1_modified)=upper(column2) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* update config files for row numbers start, end */ +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a +set row_read_end = null ,run_time=current_timestamp +where f1_modified =''Prepared by'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers*/ +execute 'insert into staging2.stg_process_table_IHTEMT_EMT +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTEMT_EMT a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Request no.'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTEMT_EMT +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTEMT_EMT a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Weight Reaction'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTEMT_EMT +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTEMT_EMT a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Steering effort'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTEMT_EMT +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTEMT_EMT a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Pedal Effort'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTEMT_EMT +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTEMT_EMT a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Brake Pedal Effort'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'insert into staging2.stg_process_table_IHTEMT_EMT +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTEMT_EMT a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Prepared by'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/*selecting tractor model and make*/ +select column5 into __make from staging2.stg_process_table_IHTEMT_EMT a +where block_tag='IHTEMT_EMT_H1' and trim(column2)='Tractor Model'; + + +select column5 into __model from staging2.stg_process_table_IHTEMT_EMT a +where block_tag='IHTEMT_EMT_H1' and trim(column2)='Tractor Model'; + +/*block starts - IHTEMT_EMT_H1_BLOCK */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTEMT_EMT_H1_BLOCK',__file_mnemonic,__file_sheet_mnemonic,1); +err_block:='IHTEMT_EMT_H1_BLOCK'; +insert into staging2.IHTEMT_EMT_H1_INT (c1,c2) +select a.column2,column5 from staging2.stg_process_table_IHTEMT_EMT a where block_tag='IHTEMT_EMT_H1'; + +insert into staging2.IHTEMT_EMT_H1_INT (c1,c2) +select a.column8,column11 from staging2.stg_process_table_IHTEMT_EMT a where block_tag='IHTEMT_EMT_H1'; + +insert into staging2.IHTEMT_EMT_H1_INT (c1,c2) +select 'Objective',column14 +from staging2.stg_process_table_IHTEMT_EMT a +where block_tag='IHTEMT_EMT_H1' +and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTEMT_EMT a +where column14='Objective' +and block_tag='IHTEMT_EMT_H1' +); + +insert into staging2.IHTEMT_EMT_H1_INT (c1,c2) +select 'Acceptance criteria',column14 +from staging2.stg_process_table_IHTEMT_EMT a +where block_tag='IHTEMT_EMT_H1' +and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTEMT_EMT a +where column14='Acceptance criteria' +and block_tag='IHTEMT_EMT_H1' +); + +insert into staging2.IHTEMT_EMT_H1_INT (c1,c2) +select split_part(column2,':',1),split_part(column2,':',2) +from staging2.stg_process_table_IHTEMT_EMT +where block_tag='IHTEMT_EMT_Footer' and block_row_number=1; + +insert into staging2.IHTEMT_EMT_H1_INT (c1,c2) +select 'Test Purpose',column9 +from staging2.stg_process_table_IHTEMT_EMT +where block_tag='IHTEMT_EMT_Weight_Tyre' and column2='Test Purpose'; + + +update staging2.IHTEMT_EMT_H1_Int set model=__model; +execute 'update staging2.IHTEMT_EMT_H1_Int set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +insert into staging2.IHTEMT_EMT_H1_Block +( +dummy_f, +Test_Request_no, +Sample_Receipt_Date, +Test_report_No, +Tractor_Model, +Generation, +Customer_Name, +Test_Engineer, +Test_Report_Date, +No_of_Sample, +Test_Start_Date, +Test_End_Date, +Tractor_Sr_No, +Test_Standard_Refer, +Test_Location, +Operator_Name, +Project_Group, +Objective, +Acceptance_Criteria, +Remarks, +Test_Purpose +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{c2}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[c2::text]) AS val + FROM staging2.IHTEMT_EMT_H1_INT + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text, + a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text, + a_18 text,a_19 text,a_20 text); + + +delete from staging2.IHTEMT_EMT_H1_Block where dummy_f is null ; +update staging2.IHTEMT_EMT_H1_Block set model=__model; +execute 'update staging2.IHTEMT_EMT_H1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTEMT_EMT_H1_BLOCK'); + + +insert into staging2.IHTEMT_EMT_Weight_Tyre_Int +( +column2,column5,column9,column10,column12,column14,column16,column18, +column19,block_row_number +) +select +column2,column5,column9,column10,column12,column14,column16,column18, +column19,block_row_number +from staging2.stg_process_table_IHTEMT_EMT a +where block_tag='IHTEMT_EMT_Weight_Tyre' +order by block_row_number; + +update staging2.IHTEMT_EMT_Weight_Tyre_Int set model=__model; +execute 'update staging2.IHTEMT_EMT_Weight_Tyre_Int set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/*block starts - IHTEMT_EMT_Weight_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTEMT_EMT_Weight_Block',__file_mnemonic,__file_sheet_mnemonic,2); + err_block:='IHTEMT_EMT_Weight_Block'; + +insert into staging2.IHTEMT_EMT_Weight_Block +( +dummy_f, +Weight_Reaction, +Total_Weight_kg, +Front_Reaction_kg, +Rear_Reaction_kg, +Left_Reaction_FL_RL_kg, +Right_reaction_FR_RR_kg, +Front_Left_Reaction_kg, +Front_Right_Reaction_kg, +Rear_Left_Reaction_kg, +Rear_Right_Reaction_kg, +Distance_of_lifting_point_from_rear_axle_mm_d1 +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column5}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column5::text]) AS val + FROM staging2.IHTEMT_EMT_Weight_Tyre_Int + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text, + a_10 text,a_11 text); + + +delete from staging2.IHTEMT_EMT_Weight_Block where dummy_f is null ; +update staging2.IHTEMT_EMT_Weight_Block set model=__model; +execute 'update staging2.IHTEMT_EMT_Weight_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTEMT_EMT_Weight_Block'); + +/*block starts - IHTEMT_EMT_Tyre_Details_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTEMT_EMT_Tyre_Details_Block',__file_mnemonic,__file_sheet_mnemonic,3); +err_block:='IHTEMT_EMT_Tyre_Details_Block'; + +insert into staging2.IHTEMT_EMT_Tyre_Details_Block +( +dummy_f, +Tyre_Details, +Tyre_Make, +Tyre_size, +Ply_Rating, +Load_Carrying_Capacity, +Pressure_kg_cm2, +Dynamic_rolling_radius, +Static_rolling_radius, +Wheel_rim_Make_size +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column14,column18}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column14::text,column18::text]) AS val + FROM staging2.IHTEMT_EMT_Weight_Tyre_Int where block_row_number between 3 and 11 + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text); + +delete from staging2.IHTEMT_EMT_Tyre_Details_Block where dummy_f is null ; +update staging2.IHTEMT_EMT_Tyre_Details_Block set model=__model; +execute 'update staging2.IHTEMT_EMT_Tyre_Details_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTEMT_EMT_Tyre_Details_Block'); + + +/*block starts - IHTEMT_EMT_Wheel_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTEMT_EMT_Wheel_Block',__file_mnemonic,__file_sheet_mnemonic,4); +err_block:='IHTEMT_EMT_Wheel_Block'; +insert into staging2.IHTEMT_EMT_Wheel_Block(dummy_f) values ('dummy'); + +update staging2.IHTEMT_EMT_Wheel_Block +set Wheel_Base=(select column12 from +staging2.IHTEMT_EMT_Weight_Tyre_Int +where block_row_number=1 and column9='Wheel Base in mm') +where dummy_f='dummy'; + +update staging2.IHTEMT_EMT_Wheel_Block +set TCD=(select replace(column19,'mm','') from +staging2.IHTEMT_EMT_Weight_Tyre_Int +where block_row_number=1 and column16='TCD in mm') +where dummy_f='dummy'; + + +update staging2.IHTEMT_EMT_Wheel_Block set model=__model; +execute 'update staging2.IHTEMT_EMT_Wheel_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTEMT_EMT_Wheel_Block'); + +/*block starts - IHTEMT_EMT_Steering_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTEMT_EMT_Steering_Block',__file_mnemonic,__file_sheet_mnemonic,5); +err_block:='IHTEMT_EMT_Steering_Block'; + +insert into staging2.IHTEMT_EMT_Steering_Block +( +column2,column3,column4,column5,column6, +column8,block_row_number +) +select +column2,column3,column4,column5,column6, +column8,block_row_number +from staging2.stg_process_table_IHTEMT_EMT a +where block_tag='IHTEMT_EMT_Steering' +order by block_row_number; + + +update staging2.IHTEMT_EMT_Steering_Block set model=__model; +execute 'update staging2.IHTEMT_EMT_Steering_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +update staging2.IHTEMT_EMT_Steering_Block set trx_record =0 where block_row_number in (1,2,3); +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTEMT_EMT_Steering_Block'); + + +/*block starts - IHTEMT_EMT_Pedal_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTEMT_EMT_Pedal_Block',__file_mnemonic,__file_sheet_mnemonic,6); +err_block:='IHTEMT_EMT_Pedal_Block'; +insert into staging2.IHTEMT_EMT_Pedal_Block +( +column2,column3,column4,column5,column6, +column8,block_row_number +) +select +column2,column3,column4,column5,column6, +column8,block_row_number +from staging2.stg_process_table_IHTEMT_EMT a +where block_tag='IHTEMT_EMT_Pedal' +order by block_row_number; + + +update staging2.IHTEMT_EMT_Pedal_Block set model=__model; +execute 'update staging2.IHTEMT_EMT_Pedal_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +update staging2.IHTEMT_EMT_Pedal_Block set trx_record =0 where block_row_number in (1,2); + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTEMT_EMT_Pedal_Block'); + +/*block starts - IHTEMT_EMT_Brake_Pedal_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTEMT_EMT_Brake_Pedal_Block',__file_mnemonic,__file_sheet_mnemonic,7); +err_block:='IHTEMT_EMT_Brake_Pedal_Block'; +insert into staging2.IHTEMT_EMT_Brake_Pedal_Block +( +column2,column3,column4,column5,column6,column7, +column8,column9,block_row_number +) +select +column2,column3,column4,column5,column6,column7, +column8,column9,block_row_number +from staging2.stg_process_table_IHTEMT_EMT a +where block_tag='IHTEMT_EMT_Brake_Pedal' +order by block_row_number; + + + +update staging2.IHTEMT_EMT_Brake_Pedal_Block set model=__model; +execute 'update staging2.IHTEMT_EMT_Brake_Pedal_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +update staging2.IHTEMT_EMT_Brake_Pedal_Block set trx_record =0 where block_row_number in (1,2,3,14); + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTEMT_EMT_Brake_Pedal_Block'); + +/*block starts - IHTEMT_EMT_Footer_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTEMT_EMT_Footer_block',__file_mnemonic,__file_sheet_mnemonic,8); +err_block:='IHTEMT_EMT_Footer_block'; +insert into staging2.IHTEMT_EMT_Footer_block(dummy_f) values ('dummy'); + +update staging2.IHTEMT_EMT_Footer_block a +set prepared_by=( select column6 from staging2.stg_process_table_IHTEMT_EMT b +where b.block_tag='IHTEMT_EMT_Footer' +and lower(column2)='prepared by' ) +where dummy_F='dummy'; + +update staging2.IHTEMT_EMT_Footer_block a +set reviewed_by=( select column6 from staging2.stg_process_table_IHTEMT_EMT b +where b.block_tag='IHTEMT_EMT_Footer' +and lower(column2)='reviewed by' ) +where dummy_F='dummy'; + +update staging2.IHTEMT_EMT_Footer_block a +set approved_by=( select column6 from staging2.stg_process_table_IHTEMT_EMT b +where b.block_tag='IHTEMT_EMT_Footer' +and lower(column2)='approved by' ) +where dummy_F='dummy'; + +update staging2.IHTEMT_EMT_Footer_block a +set comments=( select column2 from staging2.stg_process_table_IHTEMT_EMT b +where b.block_tag='IHTEMT_EMT_Footer' +and block_row_number=5 ) +where dummy_F='dummy'; + +update staging2.IHTEMT_EMT_Footer_block a +set rev1=( select column2 from staging2.stg_process_table_IHTEMT_EMT b +where b.block_tag='IHTEMT_EMT_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + + +update staging2.IHTEMT_EMT_Footer_block a +set rev2=( select column8 from staging2.stg_process_table_IHTEMT_EMT b +where b.block_tag='IHTEMT_EMT_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + +update staging2.IHTEMT_EMT_Footer_block a +set rev3=( select column17 from staging2.stg_process_table_IHTEMT_EMT b +where b.block_tag='IHTEMT_EMT_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + +update staging2.IHTEMT_EMT_Footer_block a +set replaces=( select column18 from staging2.stg_process_table_IHTEMT_EMT b +where b.block_tag='IHTEMT_EMT_Footer' +and block_row_number=1) +where dummy_F='dummy'; + +update staging2.IHTEMT_EMT_Footer_block a +set revision_no=( select column18 from staging2.stg_process_table_IHTEMT_EMT b +where b.block_tag='IHTEMT_EMT_Footer' +and block_row_number=3) +where dummy_F='dummy'; + +update staging2.IHTEMT_EMT_Footer_block a +set prepared_date=( select column15 from staging2.stg_process_table_IHTEMT_EMT b +where b.block_tag='IHTEMT_EMT_Footer' +and block_row_number=1) +where dummy_F='dummy'; + +update staging2.IHTEMT_EMT_Footer_block a +set reviewed_date=( select column15 from staging2.stg_process_table_IHTEMT_EMT b +where b.block_tag='IHTEMT_EMT_Footer' +and block_row_number=2) +where dummy_F='dummy'; + +update staging2.IHTEMT_EMT_Footer_block a +set approved_date=( select column15 from staging2.stg_process_table_IHTEMT_EMT b +where b.block_tag='IHTEMT_EMT_Footer' +and block_row_number=3) +where dummy_F='dummy'; + +update staging2.IHTEMT_EMT_Footer_block set model=__model; +execute 'update staging2.IHTEMT_EMT_Footer_block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTEMT_EMT_Footer_block'); +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_IHTEMT_EMT_block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + diff --git a/onetime/dataloadfunctions/IHT/IHT_HAM_ODS.sql b/onetime/dataloadfunctions/IHT/IHT_HAM_ODS.sql new file mode 100755 index 0000000..602b39b --- /dev/null +++ b/onetime/dataloadfunctions/IHT/IHT_HAM_ODS.sql @@ -0,0 +1,433 @@ +drop function if exists staging2.fn_IHTHAM_HAM_TRX; +CREATE OR REPLACE FUNCTION staging2.fn_IHTHAM_HAM_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + declare __test_instance_tractor_id int; + begin +__file_syspk := p_file_syspk; + +/************************************************************ +Function Name:fn_IHTHAM_HAM_TRX +Function Desc: This function populates data into ODS +File Format: IHTHAM +Sheet Format: IHTHAM_HAM +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_IHTHAM_HAM_TRX() +***************************************************************/ +insert into transactional.test_instance +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +job_order_no, +sample_receipt_date, +test_report_no, +generation, +customer_name, +test_engineer, +test_report_date, +no_of_sample, +test_start_date, +test_end_date, +tractor_sr_no, +test_standard_ref, +test_location_name, +test_operator, +project_group, +objective_of_test, +acceptance_criteria, +test_condition, +remarks +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +Test_Request_no, +Sample_Receipt_Date::date, +Test_report_No, +Generation, +Customer_Name, +Test_Engineer, +Test_Report_Date::date, +No_of_Sample, +Test_Start_Date::date, +Test_End_Date::date, +Tractor_Sr_No, +Test_Standard_Refer, +Test_location, +Operator_Name, +Project_Group, +Acceptance_criteria, +Objective, +condition, +Remarks +from + staging2.IHTHAM_HAM_H1_block where trx_record=1; + +update transactional.test_instance a +set report_prepared_by=b.prepared_by, +report_reviewed_by=b.reviewed_by, +report_approved_by=b.approved_by, +report_template_replaces=b.replaces, +report_title=b.comments, +report_template_no=b.rev1, +report_template_rev_date=b.rev2, +report_template_rev_no= b.rev3 +from staging2.IHTHAM_HAM_footer_block b +where a.file_sheet_mnemonic='IHTHAM_HAM' and trx_record=1; + +insert into transactional.test_instance_tyre_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +tyre_type, +tyre_make, +tyre_size, +tyre_ply_rating, +tyre_load_carrying_capacity, +tyre_pressure_kg_per_cm2, +tyre_number_of_lug, +tyre_number_of_no_load_lug_30m, +tyre_lug_height, +tyre_dynamic_rolling_radius_mm, +tyre_wheel_rim_make_and_size +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +tyre_details, +Tyre_Make, +Tyre_size, +Ply_Rating::numeric , +Load_Carrying_Capacity, +pressure_kg_cm2::numeric , +No_of_lug::numeric, +Number_of_no_load_lug_30m::numeric, +Lug_Height::numeric, +Dynamic_rolling_radius::numeric , +Wheel_rim_Make_size +from staging2.IHTHAM_HAM_tyre_details_block where trx_record=1; + +insert into transactional.test_instance_tractor_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model +from + staging2.IHTHAM_HAM_H1_block where trx_record=1; + +update transactional.test_instance_tractor_info +set mahindra_model_yn = ( +case when lower(tractor_make) like 'mahindra%' then 'Y' else 'N' end +) where file_syspk =__file_syspk; + +update transactional.test_instance_tractor_info a +set test_tractor_yn ='Y' where syspk in +(select min(syspk) from transactional.test_instance_tractor_info b +where b.file_syspk =a.file_syspk) +and a.file_syspk =__file_syspk; + + insert into transactional.test_instance_engine_info + ( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +low_idle_declared, +low_idle_observed, +high_idle_declared, +high_idle_observed, +rated_rpm, +rated_rpm_observed, +engine_to_pto_ratio_540_pto +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +low_idle_declared, +low_idle_observed::numeric, +high_idle_declared, +high_idle_observed::numeric, +rated_rpm_declared::numeric, +rated_rpm_observed::numeric, +engine_to_pto_ratio +from staging2.IHTHAM_HAM_engine_rpm_block where trx_record=1; + + insert into transactional.test_instance_weight_reaction + ( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +front_reaction_kg, +rear_reaction_kg, +total_weight_kg +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +test_condition, +Front_weight::numeric, +Rear_weight::numeric, +Total_weight::numeric +from staging2.IHTHAM_HAM_weight_block where trx_record=1; + + +/*block */ + +insert into transactional.test_instance_atmospheric_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +ambient_temp_c, +humidity_pct, +wind_velocity_kmph, +date_of_test, +start_time, +end_time +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +Ambient_temp_C::numeric , +humidity::numeric , +wind_velocity, +date::date, +start_time::time, +end_time::time +from staging2.IHTHAM_HAM_atmos_cond_block where trx_record=1; + +insert into transactional.test_instance_drawbar_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +required_pull_in_kg, +required_power_in_hp, +actual_pull_in_kg, +actual_power_in_hp, +calculated_hitch_height_mm, +actual_hitch_height_mm +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +test_condition, +Required_pull_in_kg::numeric , +Required_Power_in_hp::numeric , +Actual_pull_in_kg::numeric , +actual_power_in_hp::numeric , +Calculated_hitch_heigh_mm::numeric , +Actual_hitch_height_mm::numeric +from staging2.IHTHAM_ham_drawbar_block where trx_record=1; + +insert into transactional.IHT_hot_air_mapping_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +gear, +load_kg, +speed_kmph, +speed_rpm, +ambient_measured_temp_c, +head_measured_temp_c, +head_roa_c, +chest_measured_temp_c, +chest_roa_c, +rh_leg_measured_temp_c, +rh_leg_roa_c, +lh_leg_measured_temp_c, +lh_leg_roa_c, +rh_hand_measured_temp_c, +rh_hand_roa_c, +lh_hand_measured_temp_c, +lh_hand_roa_c, +time_of_test, +towards_main_security_gate_yn, +time_diff_h_min +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column3, +column4::numeric, +column5::numeric, +column6::numeric, +column7::numeric, +column10::numeric , +column11::numeric , +column12::numeric , +column13::numeric , +column14::numeric , +column15::numeric , +column16::numeric , +column17::numeric , +column18::numeric , +column19::numeric , +column20::numeric , +column21::numeric , +column22::time ,column23 ,column24::time +from staging2.IHTHAM_ham_results_block ihrb where trx_record=1 order by block_row_number; + + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk; +select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk; +select syspk from transactional.test_master into __test_master_id where test_type ='In House'; +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk; + + +update transactional.test_instance +set test_master_id =__test_master_id, +test_tractor_id =__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.test_instance_engine_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.test_instance_tyre_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.test_instance_weight_reaction +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.test_instance_atmospheric_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.test_instance_drawbar_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.IHT_hot_air_mapping_results +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_IHTHAM_HAM_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + diff --git a/onetime/dataloadfunctions/IHT/IHT_HAM_STG2.sql b/onetime/dataloadfunctions/IHT/IHT_HAM_STG2.sql new file mode 100755 index 0000000..8da8659 --- /dev/null +++ b/onetime/dataloadfunctions/IHT/IHT_HAM_STG2.sql @@ -0,0 +1,855 @@ +drop function if exists staging2.fn_IHTHAM_HAM_block; +CREATE OR REPLACE FUNCTION staging2.fn_IHTHAM_HAM_block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + + begin + +/************************************************************ +Function Name:fn_IHTHAM_HAM_block +Function Desc: This function populates data into staging 2 block +File Format: IHT +Sheet Format: IHTHAM_HAM +Creation Date: March 25 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_IHTHAM_HAM_block(p_client_id,p_function_id, p_file_mnemonic, +p_file_sheet_mnemonic, p_file_syspk) +Function call ex: select staging2.fn_IHTHAM_HAM_block(1,2,'IHT','IHTHAM_HAM',456) +***************************************************************/ + + +SET search_path TO staging2; + +/* to process multiple files - re-runnability*/ + +truncate table staging2.IHTHAM_HAM_H1_Int; +truncate table staging2.IHTHAM_HAM_H1_block; +truncate table staging2.IHTHAM_HAM_Tyre_Details_Block; +truncate table staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int; +truncate table staging2.IHTHAM_HAM_Engine_RPM_Block; +truncate table staging2.IHTHAM_HAM_Tractor_Block; +truncate table staging2.IHTHAM_HAM_Weight_Block; +truncate table staging2.IHTHAM_HAM_Drawbar_Block; +truncate table staging2.IHTHAM_HAM_Atmos_Cond_Block; +truncate table staging2.IHTHAM_HAM_Results_Block; +truncate table staging2.IHTHAM_HAM_Footer_Block; +truncate table staging2.stg_specific_table_IHTHAM_HAM; +truncate table staging2.stg_process_table_IHTHAM_HAM; + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* transfer data from generic to specific for IHT */ +execute 'insert into staging2.stg_specific_table_IHTHAM_HAM +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_IHTHAM_HAM; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for IHT HAM', + detail = 'No data in table stg_specific_table_IHTHAM_HAM', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + +/* trimming data */ +update staging2.stg_specific_table_IHTHAM_HAM set column15='Objective' +where lower(column15) like 'objective%'; + +update staging2.stg_specific_table_IHTHAM_HAM set column15='Acceptance criteria' +where lower(column15) like 'acceptance criteria%'; + + + +update transactional.source_config set F1_source=F1_modified ; + + +/* keyword match in config table*/ +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_IHTHAM_HAM b +where upper(F1_modified)=upper(column3) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update in process table for match*/ +execute 'update staging2.stg_specific_table_IHTHAM_HAM a +set is_rownumber_fetched=1 +from transactional.source_config b +where upper(F1_modified)=upper(column3) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* update config files for row numbers start, end */ +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a +set row_read_end = null ,run_time=current_timestamp +where f1_modified =''Prepared by'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers*/ +execute 'insert into staging2.stg_process_table_IHTHAM_HAM +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTHAM_HAM a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Request no.'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTHAM_HAM +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTHAM_HAM a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Engine (RPM)'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTHAM_HAM +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTHAM_HAM a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Atmospheric condition'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTHAM_HAM +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTHAM_HAM a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Gear'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTHAM_HAM +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTHAM_HAM a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Prepared By'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/*selecting tractor model*/ +select column6 into __model from staging2.stg_process_table_IHTHAM_HAM a +where block_tag='IHTHAM_HAM_H1' and trim(column3)='Tractor Model'; + +/*block starts - IHTHAM_HAM_H1_BLOCK */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTHAM_HAM_H1_BLOCK',__file_mnemonic,__file_sheet_mnemonic,1); +err_block:='IHTHAM_HAM_H1_BLOCK'; + +insert into staging2.IHTHAM_HAM_H1_INT (c1,c2) +select a.column3,column6 from staging2.stg_process_table_IHTHAM_HAM a where block_tag='IHTHAM_HAM_H1'; + +insert into staging2.IHTHAM_HAM_H1_INT (c1,c2) +select a.column9,column12 from staging2.stg_process_table_IHTHAM_HAM a where block_tag='IHTHAM_HAM_H1'; + +insert into staging2.IHTHAM_HAM_H1_INT (c1,c2) +select 'Objective',column15 +from staging2.stg_process_table_IHTHAM_HAM a +where block_tag='IHTHAM_HAM_H1' +and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTHAM_HAM a +where column15='Objective' +and block_tag='IHTHAM_HAM_H1' +); + +insert into staging2.IHTHAM_HAM_H1_INT (c1,c2) +select 'Acceptance criteria',column15 +from staging2.stg_process_table_IHTHAM_HAM a +where block_tag='IHTHAM_HAM_H1' +and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTHAM_HAM a +where column15='Acceptance criteria' +and block_tag='IHTHAM_HAM_H1' +); + +insert into staging2.IHTHAM_HAM_H1_INT (c1,c2) +select split_part(column3,':',1),split_part(column3,':',2) +from staging2.stg_process_table_IHTHAM_HAM +where block_tag='IHTHAM_HAM_Results' and block_row_number=49; + +insert into staging2.IHTHAM_HAM_H1_INT (c1,c2) +select column3,column4 +from staging2.stg_process_table_IHTHAM_HAM +where block_tag='IHTHAM_HAM_Atmos_Cond' and block_row_number=4; + +update staging2.IHTHAM_HAM_H1_Int set model=__model; +execute 'update staging2.IHTHAM_HAM_H1_Int set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +insert into staging2.IHTHAM_HAM_H1_Block +( +dummy_f, +Test_Request_no, +Sample_Receipt_Date, +Test_report_No, +Tractor_Model, +Generation, +Customer_Name, +Test_Engineer, +Test_Report_Date, +No_of_Sample, +Test_Start_Date, +Test_End_Date, +Tractor_Sr_No, +Test_Location, +Operator_Name, +Project_Group, +Test_standard_refer, +Objective, +Acceptance_Criteria, +Remarks, +condition +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{c2}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[c2::text]) AS val + FROM staging2.IHTHAM_HAM_H1_INT + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text, + a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text, + a_19 text,a_20 text); + + update staging2.IHTHAM_HAM_H1_Block + set Sample_Receipt_Date=case + when Sample_Receipt_Date like '%-%' then Sample_Receipt_Date::timestamptz + else date '1899-12-30' + Sample_Receipt_Date::int * interval '1' day + end; + + update staging2.IHTHAM_HAM_H1_Block + set Test_Report_Date=case + when Test_Report_Date like '%-%' then Test_Report_Date::timestamptz + else date '1899-12-30' + Test_Report_Date::int * interval '1' day + end; + + update staging2.IHTHAM_HAM_H1_Block + set Test_Start_Date=case + when Test_Report_Date like '%-%' then Test_Report_Date::timestamptz + else date '1899-12-30' + Test_Report_Date::int * interval '1' day + end; + update staging2.IHTHAM_HAM_H1_Block + set Test_End_Date=case + when Test_Report_Date like '%-%' then Test_Report_Date::timestamptz + else date '1899-12-30' + Test_Report_Date::int * interval '1' day + end; + + +delete from staging2.IHTHAM_HAM_H1_Block where dummy_f is null ; +update staging2.IHTHAM_HAM_H1_Block set model=__model; +execute 'update staging2.IHTHAM_HAM_H1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTHAM_HAM_H1_BLOCK'); + +insert into staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +( +column3,column4,column5,column6,column8,column9 , +column10,column11,column12,column13, +column14,column15,column16,column17, +column18,column19,column20,column21 , +column22,block_row_number +) +select +column3,column4,column5,column6,column8,column9, +column10,column11,column12,column13, +column14,column15,column16,column17, +column18,column19,column20,column21 , +column22,block_row_number +from staging2.stg_process_table_IHTHAM_HAM a +where block_tag='IHTHAM_HAM_Engine_Tyre_Weight' +order by block_row_number; + + +update staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int set model=__model; +execute 'update staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/*block starts - IHTHAM_HAM_Tyre_Details_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTHAM_HAM_Tyre_Details_Block',__file_mnemonic,__file_sheet_mnemonic,2); +err_block:='IHTHAM_HAM_Tyre_Details_Block'; +insert into staging2.IHTHAM_HAM_Tyre_Details_Block +( +dummy_f, +Tyre_Details, +Tyre_Make, +Tyre_size, +Ply_Rating, +Load_Carrying_Capacity, +pressure_kg_cm2, +No_of_lug, +Number_of_no_load_lug_30m, +Lug_Height, +Dynamic_rolling_radius, +Wheel_rim_Make_size +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column15,column20}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column15::text,column20::text]) AS val + FROM staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int where block_row_number between 4 and 14 + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text, + a_8 text,a_9 text,a_10 text,a_11 text); + + + +delete from staging2.IHTHAM_HAM_Tyre_Details_Block where dummy_f is null ; +update staging2.IHTHAM_HAM_Tyre_Details_Block set model=__model; +execute 'update staging2.IHTHAM_HAM_Tyre_Details_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTHAM_HAM_Tyre_Details_Block'); + + +/*block starts - IHTHAM_HAM_Engine_RPM_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTHAM_HAM_Engine_RPM_Block',__file_mnemonic,__file_sheet_mnemonic,3); +err_block:='IHTHAM_HAM_Engine_RPM_Block'; +insert into staging2.IHTHAM_HAM_Engine_RPM_Block(dummy_f) values ('dummy'); + +update staging2.IHTHAM_HAM_Engine_RPM_Block +set low_idle_declared=(select column6 from +staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where block_row_number=2 and column3='Low Idle RPM') +where dummy_f='dummy'; + +update staging2.IHTHAM_HAM_Engine_RPM_Block +set low_idle_observed=(select column8 from +staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where block_row_number=2 and column3='Low Idle RPM') +where dummy_f='dummy'; + +update staging2.IHTHAM_HAM_Engine_RPM_Block +set high_idle_declared=(select column6 from +staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where block_row_number=3 and column10='High Idle RPM') +where dummy_f='dummy'; + +update staging2.IHTHAM_HAM_Engine_RPM_Block +set high_idle_observed=(select column8 from +staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where block_row_number=3 and column3='High Idle RPM') +where dummy_f='dummy'; + +update staging2.IHTHAM_HAM_Engine_RPM_Block +set rated_rpm_declared=(select column6 from +staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where block_row_number=4 and column3='Rated RPM') +where dummy_f='dummy'; + +update staging2.IHTHAM_HAM_Engine_RPM_Block +set rated_rpm_observed=(select column8 from +staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where block_row_number=4 and column3='Rated RPM') +where dummy_f='dummy'; + +update staging2.IHTHAM_HAM_Engine_RPM_Block +set Engine_to_PTO_Ratio=(select column6 from +staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where block_row_number=5 and column3='Engine to PTO Ratio') +where dummy_f='dummy'; + + +update staging2.IHTHAM_HAM_Engine_RPM_Block set model=__model; +execute 'update staging2.IHTHAM_HAM_Engine_RPM_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTHAM_HAM_Engine_RPM_Block'); + + +/*block starts -IHTHAM_HAM_Drawbar_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTHAM_HAM_Drawbar_Block',__file_mnemonic,__file_sheet_mnemonic,4); +err_block:='IHTHAM_HAM_Drawbar_Block'; + + +insert into staging2.IHTHAM_HAM_Drawbar_Block(test_condition) +select distinct column6 from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where block_row_number between 9 and 14; + +insert into staging2.IHTHAM_HAM_Drawbar_Block(test_condition) +select distinct column8 from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where block_row_number between 9 and 14; + +update staging2.IHTHAM_HAM_Drawbar_Block +set Required_pull_in_kg = (select column7 +from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where test_condition='UB' and block_row_number =9); + + +update staging2.IHTHAM_HAM_Drawbar_Block +set Required_Power_in_hp = (select column7 +from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where test_condition='UB' and block_row_number =10); + +update staging2.IHTHAM_HAM_Drawbar_Block +set Actual_pull_in_kg = (select column7 +from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where test_condition='UB' and block_row_number =11); + + +update staging2.IHTHAM_HAM_Drawbar_Block +set actual_power_in_hp = (select column7 +from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where test_condition='UB' and block_row_number =12); + + +update staging2.IHTHAM_HAM_Drawbar_Block +set Calculated_hitch_heigh_mm = (select column7 +from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where test_condition='UB' and block_row_number =13); + +update staging2.IHTHAM_HAM_Drawbar_Block +set Actual_hitch_height_mm = (select column7 +from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where test_condition='UB' and block_row_number =14); + +update staging2.IHTHAM_HAM_Drawbar_Block +set Required_pull_in_kg = (select column9 +from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where test_condition='B' and block_row_number =9); + + +update staging2.IHTHAM_HAM_Drawbar_Block +set Required_Power_in_hp = (select column9 +from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where test_condition='B' and block_row_number =10); + +update staging2.IHTHAM_HAM_Drawbar_Block +set Actual_pull_in_kg = (select column9 +from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where test_condition='B' and block_row_number =11); + + +update staging2.IHTHAM_HAM_Drawbar_Block +set actual_power_in_hp = (select column9 +from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where test_condition='B' and block_row_number =12); + + +update staging2.IHTHAM_HAM_Drawbar_Block +set Calculated_hitch_heigh_mm = (select column9 +from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where test_condition='B' and block_row_number =13); + +update staging2.IHTHAM_HAM_Drawbar_Block +set Actual_hitch_height_mm = (select column9 +from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where test_condition='B' and block_row_number =14); + +update staging2.IHTHAM_HAM_Drawbar_Block set model=__model; +execute 'update staging2.IHTHAM_HAM_Drawbar_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTHAM_HAM_Drawbar_Block'); + + + +/*block starts - IHTHAM_HAM_Tractor_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTHAM_HAM_Tractor_Block',__file_mnemonic,__file_sheet_mnemonic,5); +err_block:='IHTHAM_HAM_Tractor_Block'; + +insert into staging2.IHTHAM_HAM_Tractor_Block(dummy_f) values ('dummy'); + +update staging2.IHTHAM_HAM_Tractor_Block +set Wheel_Base_mm=(select column6 from +staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where block_row_number=5 and column3='Wheel Base (mm)') +where dummy_f='dummy'; + + +update staging2.IHTHAM_HAM_Tractor_Block +set Engine_Power_hp=(select column6 from +staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where block_row_number=6 and column3='Engine Power hp') +where dummy_f='dummy'; + +update staging2.IHTHAM_HAM_Tractor_Block +set PTO_Power_hp=(select column6 from +staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where block_row_number=7 and column3='PTO Power hp') +where dummy_f='dummy'; + + +update staging2.IHTHAM_HAM_Tractor_Block set model=__model; +execute 'update staging2.IHTHAM_HAM_Tractor_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTHAM_HAM_Tractor_Block'); + +/*block starts -IHTHAM_HAM_Weight_Block*/ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTHAM_HAM_Weight_Block',__file_mnemonic,__file_sheet_mnemonic,6); +err_block:='IHTHAM_HAM_Weight_Block'; + +insert into staging2.IHTHAM_HAM_Weight_Block(dummy_f) values ('dummy'); + +update staging2.IHTHAM_HAM_Weight_Block +set test_condition=(select column10 from +staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where block_row_number=2 ) +where dummy_f='dummy'; + +update staging2.IHTHAM_HAM_Weight_Block +set test_condition=(select column10 from +staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where block_row_number=3) +where dummy_f='dummy'; + +update staging2.IHTHAM_HAM_Weight_Block +set Front_weight=(select column13 from +staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where block_row_number=2 and column14='Unballast') +where dummy_f='dummy'; + +update staging2.IHTHAM_HAM_Weight_Block +set Front_weight=(select column13 from +staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where block_row_number=3 and column14='Ballast') +where dummy_f='dummy'; + +update staging2.IHTHAM_HAM_Weight_Block +set Rear_weight=(select column17 from +staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where block_row_number=2 and column14='Unballast') +where dummy_f='dummy'; + +update staging2.IHTHAM_HAM_Weight_Block +set Rear_weight=(select column17 from +staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where block_row_number=3 and column14='Ballast') +where dummy_f='dummy'; + +update staging2.IHTHAM_HAM_Weight_Block +set Total_weight=(select column21 from +staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where block_row_number=2 and column14='Unballast') +where dummy_f='dummy'; + +update staging2.IHTHAM_HAM_Weight_Block +set Total_weight=(select column21 from +staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int +where block_row_number=3 and column14='Ballast') +where dummy_f='dummy'; + + +update staging2.IHTHAM_HAM_Weight_Block set model=__model; +execute 'update staging2.IHTHAM_HAM_Weight_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTHAM_HAM_Weight_Block'); + + +/*block starts - IHTHAM_HAM_Atmos_Cond_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTHAM_HAM_Atmos_Cond_Block',__file_mnemonic,__file_sheet_mnemonic,7); + err_block:='IHTHAM_HAM_Atmos_Cond_Block'; +insert into staging2.IHTHAM_HAM_Atmos_Cond_Block +( +dummy_f, +Ambient_temp_C, +humidity, +wind_velocity +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column5}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column5::text]) AS val + FROM staging2.stg_process_table_ihtham_ham + where block_tag=''IHTHAM_HAM_Atmos_Cond'' and block_row_number in (1,2,3) + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text); + +update staging2.IHTHAM_HAM_Atmos_Cond_Block +set date= +(select date '1899-12-30' + column8::int * interval '1' day +FROM staging2.stg_process_table_ihtham_ham +where column7='Date' and block_tag='IHTHAM_HAM_Atmos_Cond' and block_row_number =1); + +update staging2.IHTHAM_HAM_Atmos_Cond_Block +set start_time= +(select to_char(to_timestamp((column8::numeric)* 60),'HH12:MI') +FROM staging2.stg_process_table_ihtham_ham +where column7='Start Time' and block_tag='IHTHAM_HAM_Atmos_Cond' and block_row_number=2); + +update staging2.IHTHAM_HAM_Atmos_Cond_Block +set end_time= +(select to_char(to_timestamp((column8::numeric)* 60),'HH12:MI') +FROM staging2.stg_process_table_ihtham_ham +where column7='End time' and block_tag='IHTHAM_HAM_Atmos_Cond' and block_row_number=3); + + + +delete from staging2.IHTHAM_HAM_Atmos_Cond_Block where dummy_f is null ; +update staging2.IHTHAM_HAM_Atmos_Cond_Block set model=__model; +execute 'update staging2.IHTHAM_HAM_Atmos_Cond_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTHAM_HAM_Atmos_Cond_Block'); + + +/*block starts - IHTHAM_HAM_Results_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTHAM_HAM_Results_Block',__file_mnemonic,__file_sheet_mnemonic,8); +err_block:='IHTHAM_HAM_Results_Block'; +insert into staging2.IHTHAM_HAM_Results_Block +( +column3,column4,column5,column6, +column7,column8,column9, +column10,column11,column12, +column13,column14,column15, +column16,column17,column18, +column19,column20,column21, +column22,column23,column24,block_row_number +) +select +column3,column4,column5,column6, +column7,column8,column9, +column10,column11,column12, +column13,column14,column15, +column16,column17,column18, +column19,column20,column21, +column22,column23,column24,block_row_number +from staging2.stg_process_table_IHTHAM_HAM a +where block_tag='IHTHAM_HAM_Results' +order by block_row_number; + + + +update staging2.IHTHAM_HAM_Results_Block +set trx_record =0 where block_row_number in (1,2,49,50,51); + +update staging2.ihtham_ham_results_block a +set column3= b.first_value from (SELECT + block_row_number, column3, value_partition, first_value(column3) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + column3, + sum(case when column3 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.ihtham_ham_results_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + +update staging2.IHTHAM_HAM_Results_Block +set column22= to_char((column22::numeric) * '24 hours'::interval,'HH12:MIPM') +where trx_record=1; + +--select to_char((3.4722222222222654E-3) * '24 hours'::interval,'HH12:MI') + +--select to_timestamp(cast('3.4722222222222654E-3' as real)); + +update staging2.IHTHAM_HAM_Results_Block +set column24= to_char((cast(column24 as real)) * '24 hours'::interval,'HH24:MI') +where trx_record=1; + + +update staging2.IHTHAM_HAM_Results_Block set model=__model; +execute 'update staging2.IHTHAM_HAM_Results_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTHAM_HAM_Results_Block'); + +/*block starts - IHTHAM_HAM_Footer_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTHAM_HAM_Footer_block',__file_mnemonic,__file_sheet_mnemonic,9); +err_block:='IHTHAM_HAM_Footer_block'; + +insert into staging2.IHTHAM_HAM_Footer_block(dummy_f) values ('dummy'); + +update staging2.IHTHAM_HAM_Footer_block a +set prepared_by=( select column7 from staging2.stg_process_table_IHTHAM_HAM b +where b.block_tag='IHTHAM_HAM_Footer' +and lower(column3)='prepared by' ) +where dummy_F='dummy'; + +update staging2.IHTHAM_HAM_Footer_block a +set reviewed_by=( select column7 from staging2.stg_process_table_IHTHAM_HAM b +where b.block_tag='IHTHAM_HAM_Footer' +and lower(column3)='reviewed by' ) +where dummy_F='dummy'; + +update staging2.IHTHAM_HAM_Footer_block a +set approved_by=( select column7 from staging2.stg_process_table_IHTHAM_HAM b +where b.block_tag='IHTHAM_HAM_Footer' +and lower(column3)='approved by' ) +where dummy_F='dummy'; + +update staging2.IHTHAM_HAM_Footer_block a +set comments=( select column3 from staging2.stg_process_table_IHTHAM_HAM b +where b.block_tag='IHTHAM_HAM_Footer' +and block_row_number=5 ) +where dummy_F='dummy'; + +update staging2.IHTHAM_HAM_Footer_block a +set rev1=( select column3 from staging2.stg_process_table_IHTHAM_HAM b +where b.block_tag='IHTHAM_HAM_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + + +update staging2.IHTHAM_HAM_Footer_block a +set rev2=( select column9 from staging2.stg_process_table_IHTHAM_HAM b +where b.block_tag='IHTHAM_HAM_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + +update staging2.IHTHAM_HAM_Footer_block a +set rev3=( select column18 from staging2.stg_process_table_IHTHAM_HAM b +where b.block_tag='IHTHAM_HAM_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + + + +update staging2.IHTHAM_HAM_Footer_block a +set replaces=( select column23 from staging2.stg_process_table_IHTHAM_HAM b +where b.block_tag='IHTHAM_HAM_Footer' +and block_row_number=1) +where dummy_F='dummy'; + +update staging2.IHTHAM_HAM_Footer_block a +set revision_no=( select column23 from staging2.stg_process_table_IHTHAM_HAM b +where b.block_tag='IHTHAM_HAM_Footer' +and block_row_number=2) +where dummy_F='dummy'; + +update staging2.IHTHAM_HAM_Footer_block a +set prepared_date=( select column19 from staging2.stg_process_table_IHTHAM_HAM b +where b.block_tag='IHTHAM_HAM_Footer' +and block_row_number=1) +where dummy_F='dummy'; + +update staging2.IHTHAM_HAM_Footer_block a +set reviewed_date=( select column19 from staging2.stg_process_table_IHTHAM_HAM b +where b.block_tag='IHTHAM_HAM_Footer' +and block_row_number=2) +where dummy_F='dummy'; + +update staging2.IHTHAM_HAM_Footer_block a +set approved_date=( select column19 from staging2.stg_process_table_IHTHAM_HAM b +where b.block_tag='IHTHAM_HAM_Footer' +and block_row_number=3) +where dummy_F='dummy'; + +update staging2.IHTHAM_HAM_Footer_block set model=__model; +execute 'update staging2.IHTHAM_HAM_Footer_block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTHAM_HAM_Footer_block'); + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_IHTHAM_HAM_block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ + diff --git a/onetime/dataloadfunctions/IHT/IHT_HLS_ODS.sql b/onetime/dataloadfunctions/IHT/IHT_HLS_ODS.sql new file mode 100755 index 0000000..97c1ea5 --- /dev/null +++ b/onetime/dataloadfunctions/IHT/IHT_HLS_ODS.sql @@ -0,0 +1,306 @@ +drop function if exists staging2.fn_IHTHLS_HLS_TRX; +CREATE OR REPLACE FUNCTION staging2.fn_IHTHLS_HLS_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + declare __test_instance_tractor_id int; + begin + +__file_syspk := p_file_syspk; + + +/************************************************************ +Function Name:fn_IHTHLS_HLS_TRX +Function Desc: This function populates data into ODS +File Format: IHTHLS +Sheet Format: IHTHLS_HLS +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_IHTHLS_HLS_TRX() +***************************************************************/ +insert into transactional.test_instance +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +job_order_no, +sample_receipt_date, +test_report_no, +generation, +customer_name, +test_engineer, +test_report_date, +no_of_sample, +test_start_date, +test_end_date, +tractor_sr_no, +test_standard_ref, +test_location_name, +test_operator, +project_group, +objective_of_test, +acceptance_criteria, +remarks, +test_purpose +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +Test_Request_no, +date '1899-12-30' + sample_receipt_date::int * interval '1' day as Sample_Receipt_Date, +Test_report_No, +Generation, +Customer_Name, +Test_Engineer, +date '1899-12-30' + Test_Report_Date::int * interval '1' day as Test_Report_Date, +No_of_Sample, +to_date(Test_Start_Date,'DD-MM-YYYY'), +to_date(Test_End_Date, 'DD-MM-YYYY'), +Tractor_Sr_No, +Test_Standard_Refer, +Test_Location, +Operator_Name, +Project_Group, +Objective, +Acceptance_Criteria, +Remarks, +Test_Purpose +from staging2.IHTHLS_HLS_H1_block where trx_record=1; + +update transactional.test_instance a +set +report_prepared_date=to_date(b.prepared_date,'DD-MM-YYYY'), +report_reviewed_date=to_date(b.reviewed_date,'DD-MM-YYYY'), +report_approved_date=to_date(b.approved_date,'DD-MM-YYYY'), +report_prepared_by=b.prepared_by, +report_reviewed_by=b.reviewed_by, +report_approved_by=b.approved_by, +report_template_replaces=b.replaces, +report_title=b.comments, +report_template_no=b.rev1, +report_template_rev_date=b.rev2, +report_template_rev_no= b.rev3 +from staging2.IHTHLS_HLS_footer_block b +where a.file_sheet_mnemonic ='IHTHLS_HLS' and trx_record=1; + +insert into transactional.test_instance_tyre_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +tyre_type, +tyre_make, +tyre_size, +tyre_ply_rating, +tyre_load_carrying_capacity, +tyre_pressure_kg_per_cm2, +tyre_static_rolling_radius_mm, +tyre_dynamic_rolling_radius_mm, +tyre_wheel_rim_make_and_size +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +tyre_details, +tyre_make, +tyre_size, +ply_rating::numeric, +load_carrying_capacity, +Pressure_kg_cm2::numeric , +Dynamic_rolling_radius::numeric , +Static_rolling_radius::numeric , +wheel_rim_make_size +from staging2.IHTHLS_HLS_tyre_details_block where trx_record=1; + + insert into transactional.test_instance_tractor_info + ( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +wheel_base_mm, +rear_track_width_mm +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +wheel_base::numeric , +rear_track_width::numeric +from staging2.IHTHLS_hls_wheel_block where trx_record=1; + +update transactional.test_instance_tractor_info +set mahindra_model_yn = ( +case when tractor_make like 'Mahindra%' then 'Y' else 'N' end +) where file_syspk =__file_syspk; + +update transactional.test_instance_tractor_info a +set test_tractor_yn ='Y' where syspk in +(select min(syspk) from transactional.test_instance_tractor_info b +where b.file_syspk =a.file_syspk) +and a.file_syspk =__file_syspk; + + + +/*block */ + +insert into transactional.test_instance_weight_reaction +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +total_weight_kg, +front_reaction_kg, +rear_reaction_kg, +left_reaction_fl_rl_kg, +right_reaction_fr_rr_kg, +front_left_reaction_kg, +front_right_reactionkg, +rear_left_reaction_kg, +rear_right_reactionkg, +distance_of_lifting_point_from_rear_axle_mm_d1 +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +Weight_Reaction, +Total_Weight_kg::numeric, +Front_Reaction_kg::numeric , +Rear_Reaction_kg::numeric , +Left_Reaction_FL_RL_kg::numeric , +Right_reaction_FR_RR_kg::numeric , +Front_Left_Reaction_kg::numeric , +Front_Right_Reaction_kg::numeric , +Rear_Left_Reaction_kg::numeric , +Rear_Right_Reaction_kg::numeric , +Distance_of_lifting_point_from_rear_axle_mm_d1::numeric +from staging2.IHTHLS_hls_weight_block where trx_record=1; + + +insert into transactional.IHT_hyd_lift_sensitivity +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +tpl_load, +engine_rpm_type, +lifting_time_sec, +lowering_time_sec +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +TPL_load, +Engine_RPM, +Lifting_time_Sec::numeric , +Lowering_time_Sec::numeric +from staging2.IHTHLS_hls_numeric_block where trx_record=1; + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk; +select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk; +select syspk from transactional.test_master into __test_master_id where test_type ='In House'; +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk; + + +update transactional.test_instance +set test_master_id =__test_master_id, +test_tractor_id =__test_instance_tractor_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.test_instance_tyre_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.test_instance_weight_reaction +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.IHT_hyd_lift_sensitivity +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_IHTHLS_HLS_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + diff --git a/onetime/dataloadfunctions/IHT/IHT_HLS_STG2.sql b/onetime/dataloadfunctions/IHT/IHT_HLS_STG2.sql new file mode 100755 index 0000000..88bc1ed --- /dev/null +++ b/onetime/dataloadfunctions/IHT/IHT_HLS_STG2.sql @@ -0,0 +1,571 @@ +drop function if exists staging2.fn_IHTHLS_HLS_block; +CREATE OR REPLACE FUNCTION staging2.fn_IHTHLS_HLS_block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + + begin + +/************************************************************ +Function Name:fn_IHTHLS_HLS_block +Function Desc: This function populates data into staging 2 block +File Format: IHTHLS +Sheet Format: IHTHLS_HLS +Creation Date: March 25 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_IHTHLS_HLS_block(p_client_id,p_function_id, p_file_mnemonic, +p_file_sheet_mnemonic, p_file_syspk) +Function call ex: select staging2.fn_IHTHLS_HLS_block(1,2,'IHTHLS','IHTHLS_HLS',456) +***************************************************************/ + + +SET search_path TO staging2; + +/* to process multiple files - re-runnability*/ + +truncate table staging2.IHTHLS_HLS_H1_Int; +truncate table staging2.IHTHLS_HLS_H1_block; +truncate table staging2.IHTHLS_HLS_Weight_Tyre_Int; +truncate table staging2.IHTHLS_HLS_Weight_Block; +truncate table staging2.IHTHLS_HLS_Wheel_Block; +truncate table staging2.IHTHLS_HLS_Numeric_Int; +truncate table staging2.IHTHLS_HLS_Numeric_Block; +truncate table staging2.IHTHLS_HLS_Tyre_Details_Block; +truncate table staging2.IHTHLS_HLS_Footer_Block; +truncate table staging2.stg_specific_table_IHTHLS_HLS; +truncate table staging2.stg_process_table_IHTHLS_HLS; + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* transfer data from generic to specific for IHTHLS */ +execute 'insert into staging2.stg_specific_table_IHTHLS_HLS +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_IHTHLS_HLS; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for IHTHLS ', + detail = 'No data in table stg_specific_table_IHTHLS_HLS', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + +/* trimming data */ +update staging2.stg_specific_table_IHTHLS_HLS +set column15='Objective' where lower(column15) like 'objective%'; + +update staging2.stg_specific_table_IHTHLS_HLS +set column15='Acceptance criteria' where lower(column15) like 'acceptance criteria%'; + + +update transactional.source_config set F1_source=F1_modified ; + + +/* keyword match in config table*/ +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_IHTHLS_HLS b +where upper(F1_modified)=upper(column3) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update in process table for match*/ +execute 'update staging2.stg_specific_table_IHTHLS_HLS a +set is_rownumber_fetched=1 +from transactional.source_config b +where upper(F1_modified)=upper(column3) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* update config files for row numbers start, end */ +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a +set row_read_end = null ,run_time=current_timestamp +where f1_modified =''Prepared by'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers*/ +execute 'insert into staging2.stg_process_table_IHTHLS_HLS +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTHLS_HLS a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Request no.'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTHLS_HLS +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTHLS_HLS a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Weight Reaction'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTHLS_HLS +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTHLS_HLS a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Numerical data'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'insert into staging2.stg_process_table_IHTHLS_HLS +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTHLS_HLS a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Prepared By'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/*selecting tractor model*/ +select column6 into __model from staging2.stg_process_table_IHTHLS_HLS a +where block_tag='IHTHLS_HLS_H1' and trim(column3)='Tractor Model'; + +/*block starts - IHTHLS_HLS_H1_BLOCK */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTHLS_HLS_H1_BLOCK',__file_mnemonic,__file_sheet_mnemonic,1); +err_block:='IHTHLS_HLS_H1_BLOCK'; + +insert into staging2.IHTHLS_HLS_H1_INT (c1,c2) +select a.column3,column6 from staging2.stg_process_table_IHTHLS_HLS a where block_tag='IHTHLS_HLS_H1'; + +insert into staging2.IHTHLS_HLS_H1_INT (c1,c2) +select a.column9,column12 from staging2.stg_process_table_IHTHLS_HLS a where block_tag='IHTHLS_HLS_H1'; + +insert into staging2.IHTHLS_HLS_H1_INT (c1,c2) +select 'Objective',column15 +from staging2.stg_process_table_IHTHLS_HLS a +where block_tag='IHTHLS_HLS_H1' +and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTHLS_HLS a +where column15='Objective' +and block_tag='IHTHLS_HLS_H1' +); + +insert into staging2.IHTHLS_HLS_H1_INT (c1,c2) +select 'Acceptance criteria',column15 +from staging2.stg_process_table_IHTHLS_HLS a +where block_tag='IHTHLS_HLS_H1' +and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTHLS_HLS a +where column15='Acceptance criteria' +and block_tag='IHTHLS_HLS_H1' +); + + + +insert into staging2.IHTHLS_HLS_H1_INT (c1,c2) +select split_part(column3,':',1),split_part(column3,':',2) +from staging2.stg_process_table_IHTHLS_HLS +where block_tag='IHTHLS_HLS_Numeric' and block_row_number=6; + +insert into staging2.IHTHLS_HLS_H1_INT (c1,c2) +select 'Test Purpose',column10 +from staging2.stg_process_table_IHTHLS_HLS a +where block_tag='IHTHLS_HLS_Weight_Tyre' and column3='Test Purpose'; + + +update staging2.IHTHLS_HLS_H1_Int set model=__model; +execute 'update staging2.IHTHLS_HLS_H1_Int set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +insert into staging2.IHTHLS_HLS_H1_Block +( +dummy_f, +Test_Request_no, +Sample_Receipt_Date, +Test_report_No, +Tractor_Model, +Generation, +Customer_Name, +Test_Engineer, +Test_Report_Date, +No_of_Sample, +Test_Start_Date, +Test_End_Date, +Tractor_Sr_No, +Test_Standard_Refer, +Test_Location, +Operator_Name, +Project_Group, +Objective, +Acceptance_Criteria, +Remarks, +Test_Purpose +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{c2}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[c2::text]) AS val + FROM staging2.IHTHLS_HLS_H1_INT + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text, + a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text, + a_18 text,a_19 text,a_20 text); + + +delete from staging2.IHTHLS_HLS_H1_Block where dummy_f is null ; +update staging2.IHTHLS_HLS_H1_Block set model=__model; +execute 'update staging2.IHTHLS_HLS_H1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTHLS_HLS_H1_Block'); + + +insert into staging2.IHTHLS_HLS_Weight_Tyre_Int +( +column3,column6,column10,column13,column15,column17,column19, +column20,block_row_number +) +select +column3,column6,column10,column13,column15,column17,column19, +column20,block_row_number +from staging2.stg_process_table_IHTHLS_HLS a +where block_tag='IHTHLS_HLS_Weight_Tyre' +order by block_row_number; + +update staging2.IHTHLS_HLS_Weight_Tyre_Int set model=__model; +execute 'update staging2.IHTHLS_HLS_Weight_Tyre_Int set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/*block starts - IHTHLS_HLS_Weight_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTHLS_HLS_Weight_Block',__file_mnemonic,__file_sheet_mnemonic,2); + err_block:='IHTHLS_HLS_Weight_Block'; +insert into staging2.IHTHLS_HLS_Weight_Block +( +dummy_f, +Weight_Reaction, +Total_Weight_kg, +Front_Reaction_kg, +Rear_Reaction_kg, +Left_Reaction_FL_RL_kg, +Right_reaction_FR_RR_kg, +Front_Left_Reaction_kg, +Front_Right_Reaction_kg, +Rear_Left_Reaction_kg, +Rear_Right_Reaction_kg, +Distance_of_lifting_point_from_rear_axle_mm_d1 +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column6}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column6::text]) AS val + FROM staging2.IHTHLS_HLS_Weight_Tyre_Int + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text, + a_10 text,a_11 text); + +delete from staging2.IHTHLS_HLS_Weight_Block where dummy_f is null ; +update staging2.IHTHLS_HLS_Weight_Block set model=__model; +execute 'update staging2.IHTHLS_HLS_Weight_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTHLS_HLS_Weight_Block'); + +/*block starts - IHTHLS_HLS_Tyre_Details_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTHLS_HLS_Tyre_Details_Block',__file_mnemonic,__file_sheet_mnemonic,3); +err_block:='IHTHLS_HLS_Tyre_Details_Block'; +insert into staging2.IHTHLS_HLS_Tyre_Details_Block +( +dummy_f, +Tyre_Details, +Tyre_Make, +Tyre_size, +Ply_Rating, +Load_Carrying_Capacity, +Pressure_kg_cm2, +Dynamic_rolling_radius, +Static_rolling_radius, +Wheel_rim_Make_size +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column15,column19}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column15::text,column19::text]) AS val + FROM staging2.IHTHLS_HLS_Weight_Tyre_Int where block_row_number between 3 and 11 + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text); + +delete from staging2.IHTHLS_HLS_Tyre_Details_Block where dummy_f is null ; +update staging2.IHTHLS_HLS_Tyre_Details_Block set model=__model; +execute 'update staging2.IHTHLS_HLS_Tyre_Details_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTHLS_HLS_Tyre_Details_Block'); + + +/*block starts - IHTHLS_HLS_Wheel_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTHLS_HLS_Wheel_Block',__file_mnemonic,__file_sheet_mnemonic,4); +err_block:='IHTHLS_HLS_Wheel_Block'; +insert into staging2.IHTHLS_HLS_Wheel_Block(dummy_f) values ('dummy'); + +update staging2.IHTHLS_HLS_Wheel_Block +set Wheel_Base=(select column13 from +staging2.IHTHLS_HLS_Weight_Tyre_Int +where block_row_number=1 and column10='Wheel Base in mm') +where dummy_f='dummy'; + +update staging2.IHTHLS_HLS_Wheel_Block +set Rear_Track_Width=(select column20 from +staging2.IHTHLS_HLS_Weight_Tyre_Int +where block_row_number=1 and column17='Rear Track Width in mm') +where dummy_f='dummy'; + + +update staging2.IHTHLS_HLS_Wheel_Block set model=__model; +execute 'update staging2.IHTHLS_HLS_Wheel_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTHLS_HLS_Wheel_Block'); + + +/* insert IHTHLS_HLS_Numeric_Int*/ + +insert into staging2.IHTHLS_HLS_Numeric_Int +( +column3,column4,column5,column6,column7, +column8,block_row_number +) +select +column3,column4,column5,column6,column7, +column8,block_row_number +from staging2.stg_process_table_IHTHLS_HLS a +where block_tag='IHTHLS_HLS_Numeric' +order by block_row_number; + + +update staging2.IHTHLS_HLS_Numeric_Int set model=__model; +execute 'update staging2.IHTHLS_HLS_Numeric_Int set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +update staging2.IHTHLS_HLS_Numeric_Int set trx_record =0 where block_row_number in (1,6); + + +/*block starts - IHTHLS_HLS_Numeric_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTHLS_HLS_Numeric_Block',__file_mnemonic,__file_sheet_mnemonic,5); +err_block:='IHTHLS_HLS_Numeric_Block'; +insert into staging2.IHTHLS_HLS_Numeric_Block +( +dummy_f, +TPL_load, +Engine_RPM, +Lifting_time_Sec, +Lowering_time_Sec +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column5,column6,column8}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column5::text,column6::text,column8::text]) AS val + FROM staging2.IHTHLS_HLS_Numeric_Int + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text); + + update staging2.IHTHLS_hls_numeric_block a + set TPL_load= b.first_value from (SELECT +block_row_number,TPL_load, value_partition, first_value(TPL_load) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +TPL_load, +sum(case when TPL_load is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTHLS_hls_numeric_block +ORDER BY block_row_number ASC +) as q) b; + +delete from staging2.IHTHLS_HLS_Numeric_Block where dummy_f is null; +update staging2.IHTHLS_HLS_Numeric_Block set model=__model; +execute 'update staging2.IHTHLS_HLS_Numeric_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTHLS_HLS_Numeric_Block'); + +/*block starts - IHTHLS_HLS_Footer_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTHLS_HLS_Footer_block',__file_mnemonic,__file_sheet_mnemonic,6); +err_block:='IHTHLS_HLS_Footer_block'; +insert into staging2.IHTHLS_HLS_Footer_block(dummy_f) values ('dummy'); + +update staging2.IHTHLS_HLS_Footer_block a +set prepared_by=( select column7 from staging2.stg_process_table_IHTHLS_HLS b +where b.block_tag='IHTHLS_HLS_Footer' +and lower(column3)='prepared by' ) +where dummy_F='dummy'; + +update staging2.IHTHLS_HLS_Footer_block a +set reviewed_by=( select column7 from staging2.stg_process_table_IHTHLS_HLS b +where b.block_tag='IHTHLS_HLS_Footer' +and lower(column3)='reviewed by' ) +where dummy_F='dummy'; + +update staging2.IHTHLS_HLS_Footer_block a +set approved_by=( select column7 from staging2.stg_process_table_IHTHLS_HLS b +where b.block_tag='IHTHLS_HLS_Footer' +and lower(column3)='approved by' ) +where dummy_F='dummy'; + +update staging2.IHTHLS_HLS_Footer_block a +set comments=( select column3 from staging2.stg_process_table_IHTHLS_HLS b +where b.block_tag='IHTHLS_HLS_Footer' +and block_row_number=5 ) +where dummy_F='dummy'; + +update staging2.IHTHLS_HLS_Footer_block a +set rev1=( select column3 from staging2.stg_process_table_IHTHLS_HLS b +where b.block_tag='IHTHLS_HLS_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + + +update staging2.IHTHLS_HLS_Footer_block a +set rev2=( select column9 from staging2.stg_process_table_IHTHLS_HLS b +where b.block_tag='IHTHLS_HLS_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + +update staging2.IHTHLS_HLS_Footer_block a +set rev3=( select column18 from staging2.stg_process_table_IHTHLS_HLS b +where b.block_tag='IHTHLS_HLS_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + +update staging2.IHTHLS_HLS_Footer_block a +set replaces=( select column19 from staging2.stg_process_table_IHTHLS_HLS b +where b.block_tag='IHTHLS_HLS_Footer' +and block_row_number=1) +where dummy_F='dummy'; + +update staging2.IHTHLS_HLS_Footer_block a +set revision_no=( select column19 from staging2.stg_process_table_IHTHLS_HLS b +where b.block_tag='IHTHLS_HLS_Footer' +and block_row_number=3) +where dummy_F='dummy'; + +update staging2.IHTHLS_HLS_Footer_block a +set prepared_date=( select column16 from staging2.stg_process_table_IHTHLS_HLS b +where b.block_tag='IHTHLS_HLS_Footer' +and block_row_number=1) +where dummy_F='dummy'; + +update staging2.IHTHLS_HLS_Footer_block a +set reviewed_date=( select column16 from staging2.stg_process_table_IHTHLS_HLS b +where b.block_tag='IHTHLS_HLS_Footer' +and block_row_number=2) +where dummy_F='dummy'; + +update staging2.IHTHLS_HLS_Footer_block a +set approved_date=( select column16 from staging2.stg_process_table_IHTHLS_HLS b +where b.block_tag='IHTHLS_HLS_Footer' +and block_row_number=3) +where dummy_F='dummy'; + +update staging2.IHTHLS_HLS_Footer_block set model=__model; +execute 'update staging2.IHTHLS_HLS_Footer_block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTHLS_HLS_Footer_block'); +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_IHTHLS_HLS_block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + diff --git a/onetime/dataloadfunctions/IHT/IHT_NST_ODS.sql b/onetime/dataloadfunctions/IHT/IHT_NST_ODS.sql new file mode 100755 index 0000000..d9ef157 --- /dev/null +++ b/onetime/dataloadfunctions/IHT/IHT_NST_ODS.sql @@ -0,0 +1,603 @@ +drop function if exists staging2.fn_IHTNST_NST_TRX; +CREATE OR REPLACE FUNCTION staging2.fn_IHTNST_NST_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + declare __test_instance_tractor_id int; + begin +__file_syspk := p_file_syspk; + +/************************************************************ +Function Name:fn_IHTNST_NST_TRX +Function Desc: This function populates data into ODS +File Format: IHTNST +Sheet Format: IHTNST_NST +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_IHTNST_NST_TRX() +***************************************************************/ +insert into transactional.test_instance +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +job_order_no, +sample_receipt_date, +test_report_no, +generation, +customer_name, +test_engineer, +test_report_date, +no_of_sample, +test_start_date, +test_end_date, +tractor_sr_no, +test_standard_ref, +test_location_name, +test_operator, +project_group, +objective_of_test, +test_condition, +test_purpose +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +Test_Request_no, +date '1899-12-30' + sample_receipt_date::int * interval '1' day as Sample_Receipt_Date, +Test_report_No, +Generation, +Customer_Name, +Test_Engineer, +date '1899-12-30' + Test_Report_Date::int * interval '1' day as Test_Report_Date, +No_of_Sample, +date '1899-12-30' + Test_Start_Date::int * interval '1' day as Test_Start_Date, +date '1899-12-30' + Test_End_Date::int * interval '1' day as Test_End_Date, +Tractor_Sr_No, +Test_Standard_Refer, +Test_facility, +Operator_Name, +Project_Group, +Objective, +condition, +Test_Purpose +from + staging2.IHTNST_NST_H1_block where trx_record=1; + +update transactional.test_instance a +set report_prepared_by=b.prepared_by, +report_reviewed_by=b.reviewed_by, +report_approved_by=b.approved_by, +report_template_replaces=b.replaces, +report_title=b.comments, +report_template_no=b.rev1, +report_template_rev_date=b.rev2, +report_template_rev_no= b.rev3 +from staging2.IHTNST_nst_footer_block b +where a.file_sheet_mnemonic='IHTNST_NST' and trx_record=1; + +insert into transactional.test_instance_tyre_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +tyre_type, +tyre_make, +tyre_size, +tyre_ply_rating, +tyre_load_carrying_capacity, +tyre_wheel_rim_make_and_size +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +tyre_details, +tyre_make, +tyre_size, +ply_rating::numeric , +load_carrying_capacity, +wheel_rim_make_size +from staging2.IHTNST_nst_tyre_details_block where trx_record=1; + + + insert into transactional.test_instance_engine_info + ( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +low_idle_declared, +low_idle_observed, +high_idle_declared, +high_idle_observed, +rated_rpm, +rated_rpm_observed, +engine_to_pto_ratio_540_pto +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +low_idle_declared, +low_idle_observed::numeric, +high_idle_declared, +high_idle_observed::numeric, +rated_rpm_declared::numeric, +rated_rpm_observed::numeric, +engine_to_pto_ratio +from staging2.IHTNST_nst_engine_rpm_block where trx_record=1; + + insert into transactional.test_instance_tractor_info + ( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +weight_reactions_front_kg, +tractor_weight_front_observed_kg, +tractor_weight_front_remark, +weight_reactions_rear_kg, +tractor_weight_rear_observed_kg, +tractor_weight_rear_remark, +tractor_weight_total_kg, +tractor_weight_total_observed_kg, +tractor_weight_total_remark +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +front_weight_declared::numeric , +front_weight_observed::numeric, +front_weight_remark, +rear_weight_declared::numeric, +rear_weight_observed::numeric, +rear_weight_remark, +total_weight_declared::numeric, +total_weight_observed::numeric, +total_weight_remark +from staging2.IHTNST_nst_weight_block where trx_record=1; + +update transactional.test_instance_tractor_info +set mahindra_model_yn = ( +case when tractor_make like 'Mahindra%' then 'Y' else 'N' end +) where file_syspk =__file_syspk; + +update transactional.test_instance_tractor_info a +set test_tractor_yn ='Y' where syspk in +(select min(syspk) from transactional.test_instance_tractor_info b +where b.file_syspk =a.file_syspk) +and a.file_syspk =__file_syspk; + + +/*block */ + +insert into transactional.test_instance_atmospheric_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +ambient_temp_c, +humidity_pct, +pressure_kpa, +background_noise_dba, +wind_velocity_kmph +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +ambient_temp_c::numeric, +humidity::numeric, +pressure_kpa::numeric, +background_noise::numeric, +wind_velocity +from staging2.IHTNST_nst_atmos_cond_block where trx_record=1; + +insert into transactional.IHT_noise_measurement_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_type, +test_mode, +gear, +noise_level_1_db_a, +noise_level_2_db_a, +noise_level_3_db_a +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column1, +column2, +column3, +column4::numeric, +column5::numeric, +column6::numeric +from staging2.IHTNST_nst_stand_noise_block where trx_record=1; + +update transactional.IHT_noise_measurement_results +set test_condition = (select column4 +from staging2.IHTNST_nst_stand_noise_block +where block_row_number=3) where file_syspk = __file_syspk; + +insert into transactional.IHT_noise_measurement_test +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +test_type, +test_mode +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +test_type, +test_mode +from transactional.IHT_noise_measurement_results where test_type='BY STANDER’S NOISE'; + +update transactional.IHT_noise_measurement_test +set acceptance_criteria=b.acceptance_criteria, +remarks =b.remarks +from staging2.IHTNST_nst_stand_noise_block b +where b.column1 ='BY STANDER’S NOISE' and test_type='BY STANDER’S NOISE' and trx_record=1; + +insert into transactional.IHT_noise_measurement_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_type, +test_mode, +gear, +noise_level_1_db_a, +noise_level_2_db_a, +noise_level_3_db_a +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column1, +column2, +column3, +column7::numeric, +column8::numeric, +column9::numeric +from staging2.IHTNST_nst_stand_noise_block where trx_record=1; + +update transactional.IHT_noise_measurement_results +set test_condition = (select column7 +from staging2.IHTNST_nst_stand_noise_block +where block_row_number=3) where test_condition is null; + +insert into transactional.IHT_noise_measurement_test +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +test_type, +test_mode +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +test_type, +test_mode +from transactional.IHT_noise_measurement_results where test_type='BY STANDER’S NOISE'; + +update transactional.IHT_noise_measurement_test +set acceptance_criteria=b.acceptance_criteria, +remarks =b.remarks +from staging2.IHTNST_nst_stand_noise_block b +where b.column1 ='BY STANDER’S NOISE' and test_type='BY STANDER’S NOISE' and trx_record=1; + +insert into transactional.IHT_noise_measurement_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_type, +test_mode, +gear, +load_kg, +speed_kmph, +speed_rpm, +noise_level_1_db_a, +noise_level_2_db_a, +noise_level_3_db_a +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column1, +column2, +column3, +column4::numeric, +column5::numeric, +column6::numeric, +column7::numeric, +column8::numeric, +column9::numeric +from staging2.IHTNST_nst_oel_noise_block where trx_record=1; + +update transactional.IHT_noise_measurement_test +set acceptance_criteria=b.acceptance_criteria, +remarks =b.remarks +from staging2.IHTNST_nst_oel_noise_block b +where b.column1 ='OEL Noise without Load' and test_type='OEL Noise without Load'; + +insert into transactional.IHT_noise_measurement_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_type, +test_mode, +gear, +load_kg, +speed_kmph, +speed_rpm, +noise_level_1_db_a, +noise_level_2_db_a, +noise_level_3_db_a +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column1, +column2, +column3, +column4::numeric, +column5::numeric, +column6::numeric, +column7::numeric, +column8::numeric, +column9::numeric +from staging2.IHTNST_nst_oel_noise_load_block where trx_record=1; + +update transactional.IHT_noise_measurement_test +set acceptance_criteria=b.acceptance_criteria, +remarks =b.remarks +from staging2.IHTNST_nst_oel_noise_load_block b +where b.column1 ='OEL Noise with Load' and test_type='OEL Noise with Load'; + +insert into transactional.IHT_noise_measurement_test +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +test_type, +test_mode +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +test_type, +test_mode +from transactional.IHT_noise_measurement_results where test_type ='OEL Noise without Load' ; + +insert into transactional.IHT_noise_measurement_test +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +test_type, +test_mode +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +test_type, +test_mode +from transactional.IHT_noise_measurement_results where test_type ='OEL Noise with Load'; + +delete from transactional.IHT_noise_measurement_test a +using transactional.IHT_noise_measurement_test b +where (a.syspk < b.syspk and +a.test_condition is not null and +a.test_condition =b.test_condition and +a.test_mode =b.test_mode and a.test_type=b.test_type) or +(a.syspk < b.syspk and a.test_condition is null and a.test_mode =b.test_mode and a.test_type=b.test_type); + +update transactional.IHT_noise_measurement_results a +set noise_measurement_id =(select syspk +from transactional.IHT_noise_measurement_test b +where (a.test_condition =b.test_condition and a.test_condition is not null and +a.test_mode =b.test_mode and a.test_type=b.test_type) or +(a.test_condition is null and a.test_mode =b.test_mode and a.test_type=b.test_type)); + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk; +select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk; +select syspk from transactional.test_master into __test_master_id where test_type ='In House'; +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk; + + +update transactional.test_instance +set test_master_id =__test_master_id, +test_tractor_id =__test_instance_tractor_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_engine_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.test_instance_tyre_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.test_instance_atmospheric_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.IHT_noise_measurement_results +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.IHT_noise_measurement_test +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_IHTNST_NST_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + + diff --git a/onetime/dataloadfunctions/IHT/IHT_NST_STG2.sql b/onetime/dataloadfunctions/IHT/IHT_NST_STG2.sql new file mode 100755 index 0000000..d845683 --- /dev/null +++ b/onetime/dataloadfunctions/IHT/IHT_NST_STG2.sql @@ -0,0 +1,917 @@ +drop function if exists staging2.fn_IHTNST_NST_block; +CREATE OR REPLACE FUNCTION staging2.fn_IHTNST_NST_block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + + + begin + +/************************************************************ +Function Name:fn_IHTNST_NST_block +Function Desc: This function populates data into staging 2 block +File Format: IHTNST +Sheet Format: IHTNST_NST +Creation Date: March 25 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_IHTNST_NST_block(p_client_id,p_function_id, p_file_mnemonic, +p_file_sheet_mnemonic, p_file_syspk) +Function call ex: select staging2.fn_IHTNST_NST_block(1,2,'IHTNST','IHTNST_NST',456) +***************************************************************/ + + +SET search_path TO staging2; + +/* to process multiple files - re-runnability*/ + +truncate table staging2.IHTNST_NST_H1_Int; +truncate table staging2.IHTNST_NST_H1_block; +truncate table staging2.IHTNST_NST_Tyre_Details_Block; +truncate table staging2.IHTNST_NST_Engine_RPM_Atmos_Int; +truncate table staging2.IHTNST_NST_Engine_RPM_Block; +truncate table staging2.IHTNST_NST_Weight_Block; +truncate table staging2.IHTNST_NST_Atmos_Cond_Block; +truncate table staging2.IHTNST_NST_STAND_Noise_Block; +truncate table staging2.IHTNST_NST_OEL_Noise_Block; +truncate table staging2.IHTNST_NST_OEL_Noise_Load_Block; +truncate table staging2.IHTNST_NST_Footer_Block; +truncate table staging2.stg_specific_table_IHTNST_NST; +truncate table staging2.stg_process_table_IHTNST_NST; + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* transfer data from generic to specific for IHTNST */ +execute 'insert into staging2.stg_specific_table_IHTNST_NST +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_IHTNST_NST; + + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for IHT NST', + detail = 'No data in table stg_specific_table_IHTNST_NST', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + +/* trimming data */ +update staging2.stg_specific_table_IHTNST_NST set column8='Objective' where lower(column8) like 'objective%'; + +update staging2.stg_specific_table_IHTNST_NST set column8='Condition' where lower(column8) like 'condition%'; + +update staging2.stg_specific_table_IHTNST_NST set column3='Remarks' where lower(column3) like 'remarks%'; + +update staging2.stg_specific_table_IHTNST_NST set column7='Acceptance Criteria' +where lower(column7) like 'acceptance criteria%'; + + +update transactional.source_config set F1_source=F1_modified ; + + +/* keyword match in config table*/ +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_IHTNST_NST b +where upper(F1_modified)=upper(column3) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update in process table for match*/ +execute 'update staging2.stg_specific_table_IHTNST_NST a +set is_rownumber_fetched=1 +from transactional.source_config b +where upper(F1_modified)=upper(column3) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* update config files for row numbers start, end */ +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a +set row_read_end = null ,run_time=current_timestamp +where f1_modified =''Prepared by'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers*/ +execute 'insert into staging2.stg_process_table_IHTNST_NST +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTNST_NST a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Request No'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTNST_NST +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTNST_NST a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Tyre Details'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTNST_NST +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTNST_NST a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Engine RPM'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTNST_NST +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTNST_NST a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''BY STANDER’S NOISE'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTNST_NST +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTNST_NST a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''OEL Noise without Load'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTNST_NST +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTNST_NST a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''OEL Noise with Load'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTNST_NST +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTNST_NST a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Prepared by'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/*selecting tractor model*/ +select column4 into __model from staging2.stg_process_table_IHTNST_nst a +where block_tag='IHTNST_NST_H1' and trim(column3)='Tractor Model'; + +/*block starts - IHTNST_NST_H1_BLOCK */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTNST_NST_H1_BLOCK',__file_mnemonic,__file_sheet_mnemonic,1); +err_block:='IHTNST_NST_H1_BLOCK'; +insert into staging2.IHTNST_NST_H1_INT (c1,c2) +select a.column3,column4 from staging2.stg_process_table_IHTNST_NST a where block_tag='IHTNST_NST_H1'; + +insert into staging2.IHTNST_NST_H1_INT (c1,c2) +select a.column6,column7 from staging2.stg_process_table_IHTNST_NST a where block_tag='IHTNST_NST_H1'; + +insert into staging2.IHTNST_NST_H1_INT (c1,c2) +select 'Objective',column8 +from staging2.stg_process_table_IHTNST_NST a +where block_tag='IHTNST_NST_H1' +and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTNST_NST a +where column8='Objective' +and block_tag='IHTNST_NST_H1' +); + +insert into staging2.IHTNST_NST_H1_INT (c1,c2) +select 'Condition',column8 +from staging2.stg_process_table_IHTNST_NST a +where block_tag='IHTNST_NST_Tyre_Details' +and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTNST_NST a +where column8='Condition' +and block_tag='IHTNST_NST_Tyre_Details' +); + +insert into staging2.IHTNST_NST_H1_INT (c1,c2) +select 'Test Purpose',column6 +from staging2.stg_process_table_IHTNST_NST a +where column3='Test Purpose' and block_tag ='IHTNST_NST_Engine_RPM_Atmos'; + + +update staging2.IHTNST_NST_H1_Int set model=__model; +execute 'update staging2.IHTNST_NST_H1_Int set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +insert into staging2.IHTNST_NST_H1_Block +( +dummy_f, +Test_Request_no, +Sample_Receipt_Date, +Test_report_No, +Tractor_Model, +Generation, +Customer_Name, +Test_Engineer, +Test_Report_Date, +No_of_Sample, +Test_Start_Date, +Test_End_Date, +Tractor_Sr_No, +Test_Facility, +Operator_Name, +Project_Group, +Test_standard_refer, +Objective, +condition, +Test_Purpose +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{c2}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[c2::text]) AS val + FROM staging2.IHTNST_NST_H1_INT + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text, + a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text); + + +delete from staging2.IHTNST_NST_H1_Block where dummy_f is null ; +update staging2.IHTNST_NST_H1_Block set model=__model; +execute 'update staging2.IHTNST_NST_H1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTNST_NST_H1_BLOCK'); + +/*block starts - IHTNST_NST_Tyre_Details_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTNST_NST_Tyre_Details_Block',__file_mnemonic,__file_sheet_mnemonic,2); +err_block:='IHTNST_NST_Tyre_Details_Block'; + +insert into staging2.IHTNST_NST_Tyre_Details_Block +( +dummy_f, +Tyre_Details, +Tyre_Make, +Tyre_size, +Ply_Rating, +Load_Carrying_Capacity, +Wheel_rim_Make_size +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column4,column6}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column4::text,column6::text]) AS val + FROM staging2.stg_process_table_IHTNST_NST where block_tag=''IHTNST_NST_Tyre_Details'' + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text); + +update staging2.IHTNST_NST_Tyre_Details_Block +set ply_rating =replace(ply_rating,' Ply',''); + +delete from staging2.IHTNST_NST_Tyre_Details_Block where dummy_f is null ; +update staging2.IHTNST_NST_Tyre_Details_Block set model=__model; +execute 'update staging2.IHTNST_NST_Tyre_Details_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTNST_NST_Tyre_Details_Block'); + + +/* inserting Engine_RPM_Atmos_INT */ + +insert into staging2.IHTNST_NST_Engine_RPM_Atmos_Int +( +column3,column4,column5,column6,column7, +column8,column9,block_row_number +) +select +column3,column4,column5,column6,column7, +column8,column9,block_row_number +from staging2.stg_process_table_IHTNST_NST a +where block_tag='IHTNST_NST_Engine_RPM_Atmos' +order by block_row_number; + +update staging2.IHTNST_NST_Engine_RPM_Atmos_Int +set column8=(select column6 from staging2.IHTNST_NST_Engine_RPM_Atmos_Int +where block_row_number=9) where block_row_number=5; + + +update staging2.IHTNST_NST_Engine_RPM_Atmos_Int +set column6 = null where block_row_number=9; + +update staging2.IHTNST_NST_Engine_RPM_Atmos_Int +set column9=(select column7 from staging2.IHTNST_NST_Engine_RPM_Atmos_Int +where block_row_number=9) where block_row_number=5; + +update staging2.IHTNST_NST_Engine_RPM_Atmos_Int +set column7=null where block_row_number=9; + +update staging2.IHTNST_NST_Engine_RPM_Atmos_Int +set column8=(select column8 from staging2.IHTNST_NST_Engine_RPM_Atmos_Int +where block_row_number=9)where block_row_number=6; + +update staging2.IHTNST_NST_Engine_RPM_Atmos_Int +set column8 =null where block_row_number=9; + +update staging2.IHTNST_NST_Engine_RPM_Atmos_Int +set column9=(select column9 from staging2.IHTNST_NST_Engine_RPM_Atmos_Int +where block_row_number=9)where block_row_number=6; + + +update staging2.IHTNST_NST_Engine_RPM_Atmos_Int +set column9 =null where block_row_number=9; + +update staging2.IHTNST_NST_Engine_RPM_Atmos_Int set model=__model; +execute 'update staging2.IHTNST_NST_Engine_RPM_Atmos_Int set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/*block starts - IHTNST_NST_Engine_RPM_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTNST_NST_Engine_RPM_Block',__file_mnemonic,__file_sheet_mnemonic,3); +err_block:='IHTNST_NST_Engine_RPM_Block'; +insert into staging2.IHTNST_NST_Engine_RPM_Block(dummy_f) values ('dummy'); + +update staging2.IHTNST_NST_Engine_RPM_Block +set low_idle_declared=(select column4 from +staging2.IHTNST_NST_Engine_RPM_Atmos_Int +where block_row_number=2 and column3='Low Idle RPM') +where dummy_f='dummy'; + +update staging2.IHTNST_NST_Engine_RPM_Block +set low_idle_observed=(select column6 from +staging2.IHTNST_NST_Engine_RPM_Atmos_Int +where block_row_number=2 and column3='Low Idle RPM') +where dummy_f='dummy'; + +update staging2.IHTNST_NST_Engine_RPM_Block +set high_idle_declared=(select column4 from +staging2.IHTNST_NST_Engine_RPM_Atmos_Int +where block_row_number=3 and column3='High IdleRPM') +where dummy_f='dummy'; + +update staging2.IHTNST_NST_Engine_RPM_Block +set high_idle_observed=(select column6 from +staging2.IHTNST_NST_Engine_RPM_Atmos_Int +where block_row_number=3 and column3='High IdleRPM') +where dummy_f='dummy'; + +update staging2.IHTNST_NST_Engine_RPM_Block +set rated_rpm_declared=(select column4 from +staging2.IHTNST_NST_Engine_RPM_Atmos_Int +where block_row_number=4 and column3='Rated RPM') +where dummy_f='dummy'; + +update staging2.IHTNST_NST_Engine_RPM_Block +set rated_rpm_observed=(select column6 from +staging2.IHTNST_NST_Engine_RPM_Atmos_Int +where block_row_number=4 and column3='Rated RPM') +where dummy_f='dummy'; + +update staging2.IHTNST_NST_Engine_RPM_Block +set Engine_to_PTO_Ratio=(select column4 from +staging2.IHTNST_NST_Engine_RPM_Atmos_Int +where block_row_number=9 and column3='Engine to PTO Ratio') +where dummy_f='dummy'; + +update staging2.IHTNST_NST_Engine_RPM_Block +set low_idle_remark= (select column7 +FROM staging2.IHTNST_NST_Engine_RPM_Atmos_Int +where block_row_number=2 and column3='Low Idle RPM') +where dummy_f='dummy'; + +update staging2.IHTNST_NST_Engine_RPM_Block +set high_idle_remark= (select column7 +FROM staging2.IHTNST_NST_Engine_RPM_Atmos_Int +where block_row_number=3 and column3='High IdleRPM') +where dummy_f='dummy'; + + +update staging2.IHTNST_NST_Engine_RPM_Block set model=__model; +execute 'update staging2.IHTNST_NST_Engine_RPM_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTNST_NST_Engine_RPM_Block'); + +/*block starts -IHTNST_NST_Weight_Block*/ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTNST_NST_Weight_Block',__file_mnemonic,__file_sheet_mnemonic,4); +err_block:='IHTNST_NST_Weight_Block'; +insert into staging2.IHTNST_NST_Weight_Block(dummy_f) values ('dummy'); + +update staging2.IHTNST_NST_Weight_Block +set Front_weight_declared=(select column4 from +staging2.IHTNST_NST_Engine_RPM_Atmos_Int +where block_row_number=6 and column3='Front') +where dummy_f='dummy'; + +update staging2.IHTNST_NST_Weight_Block +set Front_weight_observed=(select column6 from +staging2.IHTNST_NST_Engine_RPM_Atmos_Int +where block_row_number=6 and column3='Front') +where dummy_f='dummy'; + +update staging2.IHTNST_NST_Weight_Block +set Rear_weight_declared=(select column4 from +staging2.IHTNST_NST_Engine_RPM_Atmos_Int +where block_row_number=7 and column3='Rear') +where dummy_f='dummy'; + +update staging2.IHTNST_NST_Weight_Block +set Rear_weight_observed=(select column6 from +staging2.IHTNST_NST_Engine_RPM_Atmos_Int +where block_row_number=7 and column3='Rear') +where dummy_f='dummy'; + +update staging2.IHTNST_NST_Weight_Block +set Total_weight_declared=(select column4 from +staging2.IHTNST_NST_Engine_RPM_Atmos_Int +where block_row_number=8 and column3='Total') +where dummy_f='dummy'; + +update staging2.IHTNST_NST_Weight_Block +set Total_weight_observed=(select column6 from +staging2.IHTNST_NST_Engine_RPM_Atmos_Int +where block_row_number=8 and column3='Total') +where dummy_f='dummy'; + +update staging2.IHTNST_NST_Weight_Block +set front_weight_remark= (select column7 +FROM staging2.IHTNST_NST_Engine_RPM_Atmos_Int +where block_row_number=6 and column3='Front') +where dummy_f='dummy'; + +update staging2.IHTNST_NST_Weight_Block +set rear_weight_remark= (select column7 +FROM staging2.IHTNST_NST_Engine_RPM_Atmos_Int +where block_row_number=7 and column3='Rear') +where dummy_f='dummy'; + +update staging2.IHTNST_NST_Weight_Block +set total_weight_remark= (select column7 +FROM staging2.IHTNST_NST_Engine_RPM_Atmos_Int +where block_row_number=8 and column3='Total') +where dummy_f='dummy'; + + +update staging2.IHTNST_NST_Weight_Block set model=__model; +execute 'update staging2.IHTNST_NST_Weight_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTNST_NST_Weight_Block'); + + +/*block starts - IHTNST_NST_Atmos_Cond_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTNST_NST_Atmos_Cond_Block',__file_mnemonic,__file_sheet_mnemonic,5); +err_block:='IHTNST_NST_Atmos_Cond_Block'; +insert into staging2.IHTNST_NST_Atmos_Cond_Block +( +dummy_f, +Ambient_temp_C, +humidity, +Pressure_kPa, +Background_Noise, +wind_velocity +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column9}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column9::text]) AS val + FROM staging2.IHTNST_NST_Engine_RPM_Atmos_Int where block_row_number between 2 and 6 + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text); + +delete from staging2.IHTNST_NST_Atmos_Cond_Block where dummy_f is null ; +update staging2.IHTNST_NST_Atmos_Cond_Block set model=__model; +execute 'update staging2.IHTNST_NST_Atmos_Cond_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTNST_NST_Atmos_Cond_Block'); + + +/*block starts - IHTNST_NST_STAND_Noise_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTNST_NST_STAND_Noise_Block',__file_mnemonic,__file_sheet_mnemonic,6); +err_block:='IHTNST_NST_STAND_Noise_Block'; +insert into staging2.IHTNST_NST_STAND_Noise_Block +( +column3,column4,column5,column6,column7, +column8,column9,block_row_number +) +select +column3,column4,column5,column6,column7, +column8,column9,block_row_number +from staging2.stg_process_table_IHTNST_NST a +where block_tag='IHTNST_NST_STAND_Noise' +order by block_row_number; + +update staging2.IHTNST_NST_STAND_Noise_Block +set column2=column3 where column4 is null and block_row_number in (2,6); + +update staging2.IHTNST_NST_STAND_Noise_Block +set column1=column3 where column4 is null and block_row_number =1; + +update staging2.IHTNST_NST_STAND_Noise_Block a + set column1= b.first_value from (SELECT +block_row_number, column1, value_partition, first_value(column1) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column1, +sum(case when column1 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTNST_NST_STAND_Noise_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + +update staging2.IHTNST_NST_STAND_Noise_Block a + set column2= b.first_value from (SELECT +block_row_number, column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column2, +sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTNST_NST_STAND_Noise_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + +update staging2.IHTNST_NST_STAND_Noise_Block +set trx_record=0 where block_row_number <>5; + +update staging2.IHTNST_NST_STAND_Noise_Block +set remarks=(select column3 +from staging2.stg_process_table_IHTNST_NST a +where block_tag='IHTNST_NST_STAND_Noise' and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTNST_NST a +where lower(column3)='remarks' +and block_tag='IHTNST_NST_STAND_Noise' +)); + +update staging2.IHTNST_NST_STAND_Noise_Block +set acceptance_criteria=(select column7 +from staging2.stg_process_table_IHTNST_NST a +where block_tag='IHTNST_NST_STAND_Noise' and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTNST_NST a +where lower(column7)='acceptance criteria' +and block_tag='IHTNST_NST_STAND_Noise' +)); + +update staging2.IHTNST_NST_STAND_Noise_Block set model=__model; +execute 'update staging2.IHTNST_NST_STAND_Noise_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTNST_NST_STAND_Noise_Block'); + + +/*block starts - IHTNST_NST_OEL_Noise_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTNST_NST_OEL_Noise_Block',__file_mnemonic,__file_sheet_mnemonic,7); +err_block:='IHTNST_NST_OEL_Noise_Block'; +insert into staging2.IHTNST_NST_OEL_Noise_Block +( +column3,column4,column5,column6,column7, +column8,column9,block_row_number +) +select +column3,column4,column5,column6,column7, +column8,column9,block_row_number +from staging2.stg_process_table_IHTNST_NST a +where block_tag='IHTNST_NST_OEL_Noise' +order by block_row_number; + +update staging2.IHTNST_NST_OEL_Noise_Block +set column2=column3 where column4 is null and block_row_number in (2,8,14); + +update staging2.IHTNST_NST_OEL_Noise_Block +set column1=column3 where column4 is null and block_row_number =1; + +update staging2.IHTNST_NST_OEL_Noise_Block a + set column1= b.first_value from (SELECT +block_row_number, column1, value_partition, first_value(column1) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column1, +sum(case when column1 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTNST_NST_OEL_Noise_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + +update staging2.IHTNST_NST_OEL_Noise_Block a + set column2= b.first_value from (SELECT +block_row_number, column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column2, +sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTNST_NST_OEL_Noise_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + +update staging2.IHTNST_NST_OEL_Noise_Block +set trx_record=0 where block_row_number in (1,2,3,4,8,9,10,14,15,16,17,18); + +update staging2.IHTNST_NST_OEL_Noise_Block +set remarks=(select column3 +from staging2.stg_process_table_IHTNST_NST a +where block_tag='IHTNST_NST_OEL_Noise' and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTNST_NST a +where lower(column3)='remarks' +and block_tag='IHTNST_NST_OEL_Noise' +)); + +update staging2.IHTNST_NST_OEL_Noise_Block +set acceptance_criteria=(select column7 +from staging2.stg_process_table_IHTNST_NST a +where block_tag='IHTNST_NST_OEL_Noise' and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTNST_NST a +where lower(column7)='acceptance criteria' +and block_tag='IHTNST_NST_OEL_Noise' +)); + +update staging2.IHTNST_NST_OEL_Noise_Block set model=__model; +execute 'update staging2.IHTNST_NST_OEL_Noise_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTNST_NST_OEL_Noise_Block'); + +/*block starts - IHTNST_NST_OEL_Noise_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTNST_NST_OEL_Noise_Load_Block',__file_mnemonic,__file_sheet_mnemonic,8); +err_block:='IHTNST_NST_OEL_Noise_Load_Block'; +insert into staging2.IHTNST_NST_OEL_Noise_Load_Block +( +column3,column4,column5,column6,column7, +column8,column9,block_row_number +) +select +column3,column4,column5,column6,column7, +column8,column9,block_row_number +from staging2.stg_process_table_IHTNST_NST a +where block_tag='IHTNST_NST_OEL_Noise_Load' +order by block_row_number; + +update staging2.IHTNST_NST_OEL_Noise_Load_Block +set column2=column3 where column4 is null and block_row_number in (2,5,11); + +update staging2.IHTNST_NST_OEL_Noise_Load_Block +set column1=column3 where column4 is null and block_row_number =1; + +update staging2.IHTNST_NST_OEL_Noise_Load_Block a + set column1= b.first_value from (SELECT +block_row_number, column1, value_partition, first_value(column1) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column1, +sum(case when column1 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTNST_NST_OEL_Noise_Load_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + +update staging2.IHTNST_NST_OEL_Noise_Load_Block a + set column2= b.first_value from (SELECT +block_row_number, column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column2, +sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTNST_NST_OEL_Noise_Load_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + +update staging2.IHTNST_NST_OEL_Noise_Load_Block +set trx_record=0 where block_row_number not in (8,9,10,14,15,16); + +update staging2.IHTNST_NST_OEL_Noise_Load_Block +set remarks=(select column3 +from staging2.stg_process_table_IHTNST_NST a +where block_tag='IHTNST_NST_OEL_Noise_Load' and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTNST_NST a +where lower(column3)='remarks' +and block_tag='IHTNST_NST_OEL_Noise_Load' +)); + +update staging2.IHTNST_NST_OEL_Noise_Load_Block +set acceptance_criteria=(select column7 +from staging2.stg_process_table_IHTNST_NST a +where block_tag='IHTNST_NST_OEL_Noise_Load' and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTNST_NST a +where lower(column7)='acceptance criteria' +and block_tag='IHTNST_NST_OEL_Noise_Load' +)); + +update staging2.IHTNST_NST_OEL_Noise_Load_Block set model=__model; +execute 'update staging2.IHTNST_NST_OEL_Noise_Load_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTNST_NST_OEL_Noise_Load_Block'); + + + +/*block starts - IHTNST_NST_Footer_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTNST_NST_Footer_block',__file_mnemonic,__file_sheet_mnemonic,9); +err_block:='IHTNST_NST_Footer_block'; + +insert into staging2.IHTNST_NST_Footer_block(dummy_f) values ('dummy'); + +update staging2.IHTNST_NST_Footer_block a +set prepared_by=( select column4 from staging2.stg_process_table_IHTNST_NST b +where b.block_tag='IHTNST_NST_Footer' +and lower(column3)='prepared by' ) +where dummy_F='dummy'; + +update staging2.IHTNST_NST_Footer_block a +set reviewed_by=( select column4 from staging2.stg_process_table_IHTNST_NST b +where b.block_tag='IHTNST_NST_Footer' +and lower(column3)='reviewed by' ) +where dummy_F='dummy'; + +update staging2.IHTNST_NST_Footer_block a +set approved_by=( select column4 from staging2.stg_process_table_IHTNST_NST b +where b.block_tag='IHTNST_NST_Footer' +and lower(column3)='approved by' ) +where dummy_F='dummy'; + +update staging2.IHTNST_NST_Footer_block a +set comments=( select column3 from staging2.stg_process_table_IHTNST_NST b +where b.block_tag='IHTNST_NST_Footer' +and block_row_number=5 ) +where dummy_F='dummy'; + +update staging2.IHTNST_NST_Footer_block a +set rev1=( select column3 from staging2.stg_process_table_IHTNST_NST b +where b.block_tag='IHTNST_NST_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + + +update staging2.IHTNST_NST_Footer_block a +set rev2=( select column5 from staging2.stg_process_table_IHTNST_NST b +where b.block_tag='IHTNST_NST_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + +update staging2.IHTNST_NST_Footer_block a +set rev3=( select column8 from staging2.stg_process_table_IHTNST_NST b +where b.block_tag='IHTNST_NST_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + +update staging2.IHTNST_NST_Footer_block a +set replaces=( select column9 from staging2.stg_process_table_IHTNST_NST b +where b.block_tag='IHTNST_NST_Footer' +and block_row_number=1) +where dummy_F='dummy'; + +update staging2.IHTNST_NST_Footer_block a +set revision_no=( select column9 from staging2.stg_process_table_IHTNST_NST b +where b.block_tag='IHTNST_NST_Footer' +and block_row_number=2) +where dummy_F='dummy'; + +update staging2.IHTNST_NST_Footer_block a +set prepared_date=( select column8 from staging2.stg_process_table_IHTNST_NST b +where b.block_tag='IHTNST_NST_Footer' +and block_row_number=1) +where dummy_F='dummy'; + +update staging2.IHTNST_NST_Footer_block a +set reviewed_date=( select column8 from staging2.stg_process_table_IHTNST_NST b +where b.block_tag='IHTNST_NST_Footer' +and block_row_number=2) +where dummy_F='dummy'; + +update staging2.IHTNST_NST_Footer_block a +set approved_date=( select column8 from staging2.stg_process_table_IHTNST_NST b +where b.block_tag='IHTNST_NST_Footer' +and block_row_number=3) +where dummy_F='dummy'; + +update staging2.IHTNST_NST_Footer_block set model=__model; +execute 'update staging2.IHTNST_NST_Footer_block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTNST_NST_Footer_block'); +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_IHTNST_NST_block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + + + + diff --git a/onetime/dataloadfunctions/IHT/IHT_SLL_ODS.sql b/onetime/dataloadfunctions/IHT/IHT_SLL_ODS.sql new file mode 100755 index 0000000..b60a742 --- /dev/null +++ b/onetime/dataloadfunctions/IHT/IHT_SLL_ODS.sql @@ -0,0 +1,379 @@ +drop function if exists staging2.fn_IHTSLL_SLL_TRX; +CREATE OR REPLACE FUNCTION staging2.fn_IHTSLL_SLL_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + declare __test_instance_tractor_id int; + begin +__file_syspk := p_file_syspk; +/************************************************************ +Function Name:fn_IHTSLL_SLL_TRX +Function Desc: This function populates data into ODS +File Format: IHTSLL +Sheet Format: IHTSLL_SLL +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_IHTSLL_SLL_TRX() +***************************************************************/ +insert into transactional.test_instance +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +job_order_no, +sample_receipt_date, +test_report_no, +generation, +customer_name, +test_engineer, +test_report_date, +no_of_sample, +test_start_date, +test_end_date, +tractor_sr_no, +test_standard_ref, +test_location_name, +test_operator, +project_group, +objective_of_test, +acceptance_criteria, +remarks, +test_purpose +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +Test_Request_no, +date '1899-12-30' + sample_receipt_date::int * interval '1' day as Sample_Receipt_Date, +Test_report_No, +Generation, +Customer_Name, +Test_Engineer, +date '1899-12-30' + Test_Report_Date::int * interval '1' day as Test_Report_Date, +No_of_Sample, +date '1899-12-30' + Test_Start_Date::int * interval '1' day as Test_Start_Date, +date '1899-12-30' + Test_End_Date::int * interval '1' day as Test_End_Date, +Tractor_Sr_No, +Test_Standard_Refer, +Test_Location, +Operator_Name, +Project_Group, +Objective, +Acceptance_Criteria, +Remarks, +Test_Purpose +from staging2.IHTSLL_SLL_H1_block where trx_record=1; + +update transactional.test_instance a +set +report_prepared_date=to_date(b.prepared_date,'DD-MM-YYYY'), +report_reviewed_date=to_date(b.reviewed_date,'DD-MM-YYYY'), +report_approved_date=to_date(b.approved_date,'DD-MM-YYYY'), +report_prepared_by=b.prepared_by, +report_reviewed_by=b.reviewed_by, +report_approved_by=b.approved_by, +report_template_replaces=b.replaces, +report_title=b.comments, +report_template_no=b.rev1, +report_template_rev_date=b.rev2, +report_template_rev_no= b.rev3 +from staging2.IHTSLL_SLL_footer_block b +where a.file_sheet_mnemonic ='IHTSLL_SLL' and trx_record=1; + +insert into transactional.test_instance_tyre_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +tyre_type, +tyre_make, +tyre_size, +tyre_ply_rating, +tyre_load_carrying_capacity, +tyre_pressure_kg_per_cm2, +tyre_static_rolling_radius_mm, +tyre_dynamic_rolling_radius_mm, +tyre_wheel_rim_make_and_size +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +tyre_details, +tyre_make, +tyre_size, +ply_rating::numeric, +load_carrying_capacity, +Pressure_kg_cm2::numeric , +Dynamic_rolling_radius::numeric , +Static_rolling_radius::numeric , +wheel_rim_make_size +from staging2.IHTSLL_SLL_tyre_details_block where trx_record=1; + + insert into transactional.test_instance_tractor_info + ( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +wheel_base_mm, +rear_track_width_mm +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +wheel_base::numeric , +rear_track_width::numeric +from staging2.IHTSLL_SLL_wheel_block where trx_record=1; + +update transactional.test_instance_tractor_info +set mahindra_model_yn = ( +case when lower(tractor_make) like 'mahindra%' then 'Y' else 'N' end +) where file_syspk =__file_syspk; + +update transactional.test_instance_tractor_info a +set test_tractor_yn ='Y' where syspk in +(select min(syspk) from transactional.test_instance_tractor_info b +where b.file_syspk =a.file_syspk) +and a.file_syspk =__file_syspk; + + +/*block */ + +insert into transactional.test_instance_weight_reaction +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +total_weight_kg, +front_reaction_kg, +rear_reaction_kg, +left_reaction_fl_rl_kg, +right_reaction_fr_rr_kg, +front_left_reaction_kg, +front_right_reactionkg, +rear_left_reaction_kg, +rear_right_reactionkg, +distance_of_lifting_point_from_rear_axle_mm_d1 +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +Weight_Reaction, +Total_Weight_kg::numeric, +Front_Reaction_kg::numeric , +Rear_Reaction_kg::numeric , +Left_Reaction_FL_RL_kg::numeric , +Right_reaction_FR_RR_kg::numeric , +Front_Left_Reaction_kg::numeric , +Front_Right_Reaction_kg::numeric , +Rear_Left_Reaction_kg::numeric , +Rear_Right_Reaction_kg::numeric , +Distance_of_lifting_point_from_rear_axle_mm_d1::numeric +from staging2.IHTSLL_SLL_weight_block where trx_record=1; + + +insert into transactional.IHT_gear_max_speed +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +gear, +low_1000_rpm, +rated_2300_rpm, +specification, +high_2500_rpm, +actual_speed_pct, +diff_in_speed_kmph +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column2, +column3, +column4::numeric , +column5::numeric, +column6::numeric, +column7::numeric, +column8::numeric, +column9::numeric +from staging2.IHTSLL_sll_forward_block where trx_record=1; + +insert into transactional.IHT_gear_max_speed +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +gear, +low_1000_rpm, +rated_2300_rpm, +specification, +high_2500_rpm, +actual_speed_pct, +diff_in_speed_kmph +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column2, +column3, +column4::numeric , +column5::numeric, +column6::numeric, +column7::numeric, +column8::numeric, +column9::numeric +from staging2.IHTSLL_sll_reverse_block where trx_record=1; + +insert into transactional.IHT_speed_lead_lag_measurement +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +gear, +engine_rpm, +wheel_drive_type, +no_of_revolution_front, +ratio, +lead_lag_pct +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column3, +column4::numeric , +column5, +column6::numeric, +column7::numeric, +column8 +from staging2.IHTSLL_sll_lead_lag_block where trx_record=1; + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk; +select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk; +select syspk from transactional.test_master into __test_master_id where test_type ='In House'; +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk; + + +update transactional.test_instance +set test_master_id =__test_master_id, +test_tractor_id =__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.test_instance_tyre_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.test_instance_weight_reaction +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.IHT_gear_max_speed +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.IHT_speed_lead_lag_measurement +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_IHTSLL_SLL_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + diff --git a/onetime/dataloadfunctions/IHT/IHT_SLL_STG2.sql b/onetime/dataloadfunctions/IHT/IHT_SLL_STG2.sql new file mode 100755 index 0000000..dd1dc40 --- /dev/null +++ b/onetime/dataloadfunctions/IHT/IHT_SLL_STG2.sql @@ -0,0 +1,670 @@ +drop function if exists staging2.fn_IHTSLL_SLL_block; +CREATE OR REPLACE FUNCTION staging2.fn_IHTSLL_SLL_block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + + begin + + +/************************************************************ +Function Name:fn_IHTSLL_SLL_block +Function Desc: This function populates data into staging 2 block +File Format: IHTSLL +Sheet Format: IHTSLL_SLL +Creation Date: March 25 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_IHTSLL_SLL_block(p_client_id,p_function_id, p_file_mnemonic, +p_file_sheet_mnemonic, p_file_syspk) +Function call ex: select staging2.fn_IHTSLL_SLL_block(1,2,'IHTSLL','IHTSLL_SLL',456) +***************************************************************/ + + +SET search_path TO staging2; + +/* to process multiple files - re-runnability*/ + +truncate table staging2.IHTSLL_SLL_H1_Int; +truncate table staging2.IHTSLL_SLL_H1_block; +truncate table staging2.IHTSLL_SLL_Weight_Tyre_Int; +truncate table staging2.IHTSLL_SLL_Weight_Block; +truncate table staging2.IHTSLL_SLL_Wheel_Block; +truncate table staging2.IHTSLL_SLL_Tyre_Details_Block; +truncate table staging2.IHTSLL_SLL_Forward_Block; +truncate table staging2.IHTSLL_SLL_Reverse_Block; +truncate table staging2.IHTSLL_SLL_Lead_Lag_Block; +truncate table staging2.IHTSLL_SLL_Footer_Block; +truncate table staging2.stg_specific_table_IHTSLL_SLL; +truncate table staging2.stg_process_table_IHTSLL_SLL; + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* transfer data from generic to specific for IHTSLL */ +execute 'insert into staging2.stg_specific_table_IHTSLL_SLL +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_IHTSLL_SLL; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for IHTSLL', + detail = 'No data in table stg_specific_table_IHTSLL_SLL', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + +/* trimming data */ +update staging2.stg_specific_table_IHTSLL_SLL +set column15='Objective' where lower(column15) like 'objective%'; + +update staging2.stg_specific_table_IHTSLL_SLL +set column15='Acceptance criteria' where lower(column15) like 'acceptance criteria%'; + +update transactional.source_config set F1_source=F1_modified; + +/* keyword match in config table*/ +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_IHTSLL_SLL b +where upper(F1_modified)=upper(column3) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update in process table for match*/ +execute 'update staging2.stg_specific_table_IHTSLL_SLL a +set is_rownumber_fetched=1 +from transactional.source_config b +where upper(F1_modified)=upper(column3) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* update config files for row numbers start, end */ +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a +set row_read_end = null ,run_time=current_timestamp +where f1_modified =''Remarks:'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers*/ +execute 'insert into staging2.stg_process_table_IHTSLL_SLL +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTSLL_SLL a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Request No'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTSLL_SLL +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTSLL_SLL a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Weight Reaction'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTSLL_SLL +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTSLL_SLL a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''K2-4WD HST EACH GEAR MAX SPEED - FORWARD'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTSLL_SLL +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTSLL_SLL a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''K2- 4WD HST EACH GEAR MAX SPEED REVERSE'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_IHTSLL_SLL +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTSLL_SLL a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Lead / Lag Measurement on K2 4WD HST'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'insert into staging2.stg_process_table_IHTSLL_SLL +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_IHTSLL_SLL a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Prepared by'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/*selecting tractor model*/ +select column6 into __model from staging2.stg_process_table_IHTSLL_SLL a +where block_tag='IHTSLL_SLL_H1' and trim(column3)='Tractor Model'; + +/*block starts - IHTSLL_SLL_H1_BLOCK */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTSLL_SLL_H1_BLOCK',__file_mnemonic,__file_sheet_mnemonic,1); +err_block:='IHTSLL_SLL_H1_BLOCK'; + +insert into staging2.IHTSLL_SLL_H1_INT (c1,c2) +select a.column3,column6 from staging2.stg_process_table_IHTSLL_SLL a where block_tag='IHTSLL_SLL_H1'; + +insert into staging2.IHTSLL_SLL_H1_INT (c1,c2) +select a.column9,column12 from staging2.stg_process_table_IHTSLL_SLL a where block_tag='IHTSLL_SLL_H1'; + +insert into staging2.IHTSLL_SLL_H1_INT (c1,c2) +select 'Objective',column15 +from staging2.stg_process_table_IHTSLL_SLL a +where block_tag='IHTSLL_SLL_H1' +and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTSLL_SLL a +where column15='Objective' +and block_tag='IHTSLL_SLL_H1' +); + +insert into staging2.IHTSLL_SLL_H1_INT (c1,c2) +select 'Acceptance criteria',column15 +from staging2.stg_process_table_IHTSLL_SLL a +where block_tag='IHTSLL_SLL_H1' +and row_number= +( +select row_number+1 from +staging2.stg_process_table_IHTSLL_SLL a +where column15='Acceptance criteria' +and block_tag='IHTSLL_SLL_H1' +); + +insert into staging2.IHTSLL_SLL_H1_INT (c1,c2) +select split_part(column3,':',1),split_part(column3,':',2) +from staging2.stg_process_table_IHTSLL_SLL +where block_tag='IHTSLL_SLL_Lead_Lag' and block_row_number=10; + +insert into staging2.IHTSLL_SLL_H1_INT (c1,c2) +select 'Test Purpose',column10 +from staging2.stg_process_table_IHTSLL_SLL a +where column3='Test Purpose' and block_tag='IHTSLL_SLL_Weight_Tyre'; + +update staging2.IHTSLL_SLL_H1_Int set model=__model; +execute 'update staging2.IHTSLL_SLL_H1_Int set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +insert into staging2.IHTSLL_SLL_H1_Block +( +dummy_f, +Test_Request_no, +Sample_Receipt_Date, +Test_report_No, +Tractor_Model, +Generation, +Customer_Name, +Test_Engineer, +Test_Report_Date, +No_of_Sample, +Test_Start_Date, +Test_End_Date, +Tractor_Sr_No, +Test_Standard_Refer, +Test_Location, +Operator_Name, +Project_Group, +Objective, +Acceptance_Criteria, +Remarks, +Test_Purpose +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{c2}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[c2::text]) AS val + FROM staging2.IHTSLL_SLL_H1_INT + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text, + a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text, + a_18 text,a_19 text,a_20 text); + + +delete from staging2.IHTSLL_SLL_H1_Block where dummy_f is null ; +update staging2.IHTSLL_SLL_H1_Block set model=__model; +execute 'update staging2.IHTSLL_SLL_H1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTSLL_SLL_H1_BLOCK'); + + +insert into staging2.IHTSLL_SLL_Weight_Tyre_Int +( +column3,column6,column10,column11,column13,column15,column17,column19, +column20,block_row_number +) +select +column3,column6,column10,column11,column13,column15,column17,column19, +column20,block_row_number +from staging2.stg_process_table_IHTSLL_SLL a +where block_tag='IHTSLL_SLL_Weight_Tyre' +order by block_row_number; + +update staging2.IHTSLL_SLL_Weight_Tyre_Int set model=__model; +execute 'update staging2.IHTSLL_SLL_Weight_Tyre_Int set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/*block starts - IHTSLL_SLL_Weight_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTSLL_SLL_Weight_Block',__file_mnemonic,__file_sheet_mnemonic,2); +err_block:='IHTSLL_SLL_Weight_Block'; +insert into staging2.IHTSLL_SLL_Weight_Block +( +dummy_f, +Weight_Reaction, +Total_Weight_kg, +Front_Reaction_kg, +Rear_Reaction_kg, +Left_Reaction_FL_RL_kg, +Right_reaction_FR_RR_kg, +Front_Left_Reaction_kg, +Front_Right_Reaction_kg, +Rear_Left_Reaction_kg, +Rear_Right_Reaction_kg, +Distance_of_lifting_point_from_rear_axle_mm_d1 +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column6}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column6::text]) AS val + FROM staging2.IHTSLL_SLL_Weight_Tyre_Int + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text, + a_10 text,a_11 text); + +delete from staging2.IHTSLL_SLL_Weight_Block where dummy_f is null ; +update staging2.IHTSLL_SLL_Weight_Block set model=__model; +execute 'update staging2.IHTSLL_SLL_Weight_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTSLL_SLL_Weight_Block'); + +/*block starts - IHTSLL_SLL_Tyre_Details_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTSLL_SLL_Tyre_Details_Block',__file_mnemonic,__file_sheet_mnemonic,3); +err_block:='IHTSLL_SLL_Tyre_Details_Block'; +insert into staging2.IHTSLL_SLL_Tyre_Details_Block +( +dummy_f, +Tyre_Details, +Tyre_Make, +Tyre_size, +Ply_Rating, +Load_Carrying_Capacity, +Pressure_kg_cm2, +Dynamic_rolling_radius, +Static_rolling_radius, +Wheel_rim_Make_size +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column15,column19}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column15::text,column19::text]) AS val + FROM staging2.IHTSLL_SLL_Weight_Tyre_Int where block_row_number between 3 and 11 + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text); + +delete from staging2.IHTSLL_SLL_Tyre_Details_Block where dummy_f is null ; +update staging2.IHTSLL_SLL_Tyre_Details_Block set model=__model; +execute 'update staging2.IHTSLL_SLL_Tyre_Details_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTSLL_SLL_Tyre_Details_Block'); + + +/*block starts - IHTSLL_SLL_Wheel_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTSLL_SLL_Wheel_Block',__file_mnemonic,__file_sheet_mnemonic,4); +err_block:='IHTSLL_SLL_Wheel_Block'; +insert into staging2.IHTSLL_SLL_Wheel_Block(dummy_f) values ('dummy'); + +update staging2.IHTSLL_SLL_Wheel_Block +set Wheel_Base=(select column13 from +staging2.IHTSLL_SLL_Weight_Tyre_Int +where block_row_number=1 and column10='Wheel Base in mm') +where dummy_f='dummy'; + +update staging2.IHTSLL_SLL_Wheel_Block +set Rear_Track_Width=(select column20 from +staging2.IHTSLL_SLL_Weight_Tyre_Int +where block_row_number=1 and column17='Rear Track Width in mm') +where dummy_f='dummy'; + + +update staging2.IHTSLL_SLL_Wheel_Block set model=__model; +execute 'update staging2.IHTSLL_SLL_Wheel_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTSLL_SLL_Wheel_Block'); + +/*block starts - IHTSLL_SLL_Forward_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTSLL_SLL_Forward_Block',__file_mnemonic,__file_sheet_mnemonic,5); +err_block:='IHTSLL_SLL_Forward_Block'; + +insert into staging2.IHTSLL_SLL_Forward_Block +( +column3,column4,column5,column6,column7, +column8,column9,block_row_number +) +select +column3,column4,column5,column6,column7, +column8,column9,block_row_number +from staging2.stg_process_table_IHTSLL_SLL a +where block_tag='IHTSLL_SLL_Forward' +order by block_row_number; + +update staging2.IHTSLL_SLL_Forward_Block +set column2=(select split_part(column3,'-',3) +from staging2.IHTSLL_SLL_Forward_Block where block_row_number =1); + +delete from staging2.IHTSLL_SLL_Forward_Block where column3 is null; + + +update staging2.IHTSLL_SLL_Forward_Block set model=__model; +execute 'update staging2.IHTSLL_SLL_Forward_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +update staging2.IHTSLL_SLL_Forward_Block set trx_record =0 where block_row_number in (1,2); +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTSLL_SLL_Forward_Block'); + +/*block starts - IHTSLL_SLL_Reverse_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTSLL_SLL_Reverse_Block',__file_mnemonic,__file_sheet_mnemonic,6); + +err_block:='IHTSLL_SLL_Reverse_Block'; + +insert into staging2.IHTSLL_SLL_Reverse_Block +( +column2,column3,column4,column5,column6,column7, +column8,column9,block_row_number +) +select +column2,column3,column4,column5,column6,column7, +column8,column9,block_row_number +from staging2.stg_process_table_IHTSLL_SLL a +where block_tag='IHTSLL_SLL_Reverse' +order by block_row_number; + +update staging2.IHTSLL_sll_reverse_block +set column2=(select split_part(column3,' ',8) +from staging2.IHTSLL_sll_reverse_block where block_row_number =1); + +delete from staging2.IHTSLL_sll_reverse_block where column3 is null; + +update staging2.IHTSLL_SLL_Reverse_Block set model=__model; +execute 'update staging2.IHTSLL_SLL_Reverse_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +update staging2.IHTSLL_SLL_Reverse_Block set trx_record =0 where block_row_number in (1,2); + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTSLL_SLL_Reverse_Block'); + +/*block starts - IHTSLL_SLL_Lead_Lag_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTSLL_SLL_Lead_Lag_Block',__file_mnemonic,__file_sheet_mnemonic,7); +err_block='IHTSLL_SLL_Lead_Lag_Block'; +insert into staging2.IHTSLL_SLL_Lead_Lag_Block +( +column3,column4,column5,column6,column7, +column8,block_row_number +) +select +column3,column4,column5,column6,column7, +column8,block_row_number +from staging2.stg_process_table_IHTSLL_SLL a +where block_tag='IHTSLL_SLL_Lead_Lag' +order by block_row_number; + + +update staging2.IHTSLL_SLL_Lead_Lag_Block a + set column3= b.first_value from (SELECT +block_row_number, column3, value_partition, first_value(column3) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column3, +sum(case when column3 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTSLL_SLL_Lead_Lag_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + +update staging2.IHTSLL_SLL_Lead_Lag_Block a + set column4= b.first_value from (SELECT +block_row_number, column4, value_partition, first_value(column4) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column4, +sum(case when column4 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTSLL_SLL_Lead_Lag_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + + +update staging2.IHTSLL_SLL_Lead_Lag_Block a + set column7= b.first_value from (SELECT +block_row_number, column7, value_partition, first_value(column7) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column7, +sum(case when column7 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTSLL_SLL_Lead_Lag_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + + +update staging2.IHTSLL_SLL_Lead_Lag_Block a + set column8= b.first_value from (SELECT +block_row_number, column8, value_partition, first_value(column8) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column8, +sum(case when column8 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.IHTSLL_SLL_Lead_Lag_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + +update staging2.IHTSLL_SLL_Lead_Lag_Block set model=__model; +execute 'update staging2.IHTSLL_SLL_Lead_Lag_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + + +update staging2.IHTSLL_SLL_Lead_Lag_Block set trx_record =0 where block_row_number in (1,2,3); + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTSLL_SLL_Lead_Lag_Block'); + +/*block starts - IHTSLL_SLL_Footer_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'IHTSLL_SLL_Footer_block',__file_mnemonic,__file_sheet_mnemonic,8); +err_block:='IHTSLL_SLL_Footer_block'; +insert into staging2.IHTSLL_SLL_Footer_block(dummy_f) values ('dummy'); + +update staging2.IHTSLL_SLL_Footer_block a +set prepared_by=( select column7 from staging2.stg_process_table_IHTSLL_SLL b +where b.block_tag='IHTSLL_SLL_Footer' +and lower(column3)='prepared by' ) +where dummy_F='dummy'; + +update staging2.IHTSLL_SLL_Footer_block a +set reviewed_by=( select column7 from staging2.stg_process_table_IHTSLL_SLL b +where b.block_tag='IHTSLL_SLL_Footer' +and lower(column3)='reviewed by' ) +where dummy_F='dummy'; + +update staging2.IHTSLL_SLL_Footer_block a +set approved_by=( select column7 from staging2.stg_process_table_IHTSLL_SLL b +where b.block_tag='IHTSLL_SLL_Footer' +and lower(column3)='approved by' ) +where dummy_F='dummy'; + +update staging2.IHTSLL_SLL_Footer_block a +set comments=( select column3 from staging2.stg_process_table_IHTSLL_SLL b +where b.block_tag='IHTSLL_SLL_Footer' +and block_row_number=5 ) +where dummy_F='dummy'; + +update staging2.IHTSLL_SLL_Footer_block a +set rev1=( select column3 from staging2.stg_process_table_IHTSLL_SLL b +where b.block_tag='IHTSLL_SLL_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + + +update staging2.IHTSLL_SLL_Footer_block a +set rev2=( select column9 from staging2.stg_process_table_IHTSLL_SLL b +where b.block_tag='IHTSLL_SLL_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + +update staging2.IHTSLL_SLL_Footer_block a +set rev3=( select column18 from staging2.stg_process_table_IHTSLL_SLL b +where b.block_tag='IHTSLL_SLL_Footer' +and block_row_number=6 ) +where dummy_F='dummy'; + +update staging2.IHTSLL_SLL_Footer_block a +set replaces=( select column19 from staging2.stg_process_table_IHTSLL_SLL b +where b.block_tag='IHTSLL_SLL_Footer' +and block_row_number=1) +where dummy_F='dummy'; + +update staging2.IHTSLL_SLL_Footer_block a +set revision_no=( select column19 from staging2.stg_process_table_IHTSLL_SLL b +where b.block_tag='IHTSLL_SLL_Footer' +and block_row_number=3) +where dummy_F='dummy'; + +update staging2.IHTSLL_SLL_Footer_block a +set prepared_date=( select column16 from staging2.stg_process_table_IHTSLL_SLL b +where b.block_tag='IHTSLL_SLL_Footer' +and block_row_number=1) +where dummy_F='dummy'; + +update staging2.IHTSLL_SLL_Footer_block a +set reviewed_date=( select column16 from staging2.stg_process_table_IHTSLL_SLL b +where b.block_tag='IHTSLL_SLL_Footer' +and block_row_number=2) +where dummy_F='dummy'; + +update staging2.IHTSLL_SLL_Footer_block a +set approved_date=( select column16 from staging2.stg_process_table_IHTSLL_SLL b +where b.block_tag='IHTSLL_SLL_Footer' +and block_row_number=3) +where dummy_F='dummy'; + +update staging2.IHTSLL_SLL_Footer_block set model=__model; +execute 'update staging2.IHTSLL_SLL_Footer_block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTSLL_SLL_Footer_block'); +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_IHTSLL_SLL_block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + diff --git a/onetime/dataloadfunctions/ODS_Load/fn_fw_ods_load.sql b/onetime/dataloadfunctions/ODS_Load/fn_fw_ods_load.sql new file mode 100755 index 0000000..873cb7f --- /dev/null +++ b/onetime/dataloadfunctions/ODS_Load/fn_fw_ods_load.sql @@ -0,0 +1,1183 @@ +--drop function if exists fw_ods.fn_fw_ods_load(); + +CREATE OR REPLACE FUNCTION fw_ods.fn_fw_ods_load(p_client_id int,p_function_id int,p_job_id int,p_step_id int) + RETURNS void AS $$ +declare + f record; +begin +-- Adding data to file fw_ods_field: + +for f in select distinct file_syspk, file_mnemonic from fw_core.fw_jobctl_file_runschedule + where latest_runschedule_flag = '1' and end_status = 'success' and end_status_note = 'TRX_completed' +loop + +if f.file_mnemonic = 'FTDRY' +then + insert into fw_ods.fw_ods + ( + -- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name, + client_id, + function_id, + test_file_mnemonic, + test_sheet_mnemonic, + test_file_id, + test_file_name, + test_instance_id, + test_iteration_number, + -- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id + tractor_make, + tractor_model, + mahindra_model_yn, + test_tractor_yn, + tractor_engine_hp, + wheel_drive_type, + configuration, + test_instance_tractor_id, + -- Test Season: + season, + --test specific: date & test dimensions + test_date, + test_date_year, + test_date_quarter, + test_date_month, + test_date_dayofmonth, + test_date_dayofweek, + --test specific: condition + test_condition, + --test specific: location + location_name, + ----test specific: Implement details(name, type and Weight_kg) + name_of_implement, + type_of_implement, + implement_weight_kg, + -- test specific measures: Speed and gear + engine_speed_var, + gear_used, + -- test specific measures: fuel, area, speed,wheel-slip, productivity,rpm and depth-of-operation + fuel_consumption_lit_per_hr, + fuel_consumption_lit_per_acr, + area_covered_acr_per_hr, + speed_kmph, + wheel_slippage_pct, + field_efficiency_pct, + productivity, + erpmdrop_straight_1stpass_low, + erpmdrop_straight_1stpass_high, + depth_of_cut_cm_low, + depth_of_cut_cm_high, + created_by, + updated_by, + create_timestamp, + update_timestamp + ) + select + -- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name, + a.client_id, + a.function_id, + a.file_mnemonic, + a.file_sheet_mnemonic, + a.file_syspk, + a.test_file_name, + a.syspk, + c.test_iteration_number, + -- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id + b.tractor_make, + b.tractor_model, + b.mahindra_model_yn, + b.test_tractor_yn, + b.tractor_engine_hp, + b.wheel_drive_type, + b.configuration, + b.syspk, + -- Test Season: + a.season, + --test specific: date & test dimensions + a.date_of_test, + extract( year from a.date_of_test), + extract( quarter from a.date_of_test), + extract( month from a.date_of_test), + extract( day from a.date_of_test), + extract( dow from a.date_of_test), + --test specific: condition + c.test_condition, + --test specific: location + a.test_location_name, + ----test specific: Implement details(name, type and Weight_kg) + d.name_of_implement, + d.Type_of_implement, + d.implement_weight_kg, + -- test specific measures: Speed and gear + c.engine_rpm_set, + c.gear_used, + -- test specific measures: fuel, area, speed,wheel-slip, productivity,rpm and depth-of-operation + c.fuel_consumption_lit_per_hr, + c.fuel_consumption_lit_per_acr, + c.area_covered_acr_per_hr, + c.on_load_speed_kmph, + c.wheel_slippage_pct, + ---- test specific measures: effeciency + null, + ---- test specific measures: productivity,rpm and depth-of-operation + (c.fuel_consumption_lit_per_hr/c.area_covered_acr_per_hr), + c.erpmdrop_straight_1stpass_low, + c.erpmdrop_straight_1stpass_high, + c.depth_of_cut_cm_low , + c.depth_of_cut_cm_high, + current_user, + current_user, + current_timestamp, + current_timestamp + -- add user and timestamp fields + from + transactional.test_instance a, + transactional.test_instance_tractor_info b, + transactional.field_perf_summary c, + transactional.test_instance_implement_info d + where + a.file_syspk = b.file_syspk + and b.file_syspk = c.file_syspk + and c.file_syspk = d.file_syspk + and c.tractor_model = b.tractor_model + and a.file_mnemonic = f.file_mnemonic + and a.file_syspk = f.file_syspk; + +elsif f.file_mnemonic = 'FTWET' +then + insert into fw_ods.fw_ods + ( + -- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name, + client_id, + function_id, + test_file_mnemonic, + test_sheet_mnemonic, + test_file_id, + test_file_name, + test_instance_id, + test_iteration_number, + -- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id + tractor_make, + tractor_model, + mahindra_model_yn, + test_tractor_yn, + tractor_engine_hp, + wheel_drive_type, + configuration, + test_instance_tractor_id, + -- Test Season: + season, + --test specific: date & test dimensions + test_date, + test_date_year, + test_date_quarter, + test_date_month, + test_date_dayofmonth, + test_date_dayofweek, + --test specific: condition + test_condition, + --test specific: location + location_name, + ----test specific: Implement details(name, type and Weight_kg) + name_of_implement, + type_of_implement, + implement_weight_kg, + -- test specific measures: Speed and gear + engine_speed_var, + gear_used, + -- test specific measures: fuel, area, speed,wheel-slip, productivity,rpm and depth-of-operation + fuel_consumption_lit_per_hr, + fuel_consumption_lit_per_acr, + area_covered_acr_per_hr, + speed_kmph, + speed_pto_rpm, + wheel_slippage_pct, + no_of_passes, + field_efficiency_pct, + productivity, + erpmdrop_straight_1stpass_low, + erpmdrop_straight_1stpass_high, + erpmdrop_straight_2ndpass_low, + erpmdrop_straight_2ndpass_high, + erpmdrop_straight_3rdpass_low, + erpmdrop_straight_3rdpass_high, + erpmdrop_turn_1stpass_low, + erpmdrop_turn_1stpass_high, + erpmdrop_turn_2ndpass_low, + erpmdrop_turn_2ndpass_high, + erpmdrop_turn_3rdpass_low, + erpmdrop_turn_3rdpass_high, + depth_of_cut_cm_low, + depth_of_cut_cm_high, + created_by, + updated_by, + create_timestamp, + update_timestamp + --created_by, updated_by, create_timestamp, update_timestamp + ) + select + -- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name, + a.client_id, + a.function_id, + a.file_mnemonic, + a.file_sheet_mnemonic, + a.file_syspk, + a.test_file_name, + a.syspk, + c.test_iteration_number, + -- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id + b.tractor_make, + b.tractor_model, + b.mahindra_model_yn, + b.test_tractor_yn, + b.tractor_engine_hp, + b.wheel_drive_type, + b.configuration, + b.syspk, + -- Test Season: + a.season, + --test specific: date & test dimensions + a.date_of_test, + extract( year from a.date_of_test), + extract( quarter from a.date_of_test), + extract( month from a.date_of_test), + extract( day from a.date_of_test), + extract( dow from a.date_of_test), + --test specific: condition + c.test_condition, + --test specific: location + a.test_location_name, + ----test specific: Implement details(name, type and Weight_kg) + d.name_of_implement, + d.Type_of_implement, + d.implement_weight_kg, + -- test specific measures: Speed and gear + c.engine_rpm_set, + c.gear_used, + -- test specific measures: fuel, area, speed,wheel-slip, productivity,rpm and depth-of-operation + c.fuel_consumption_lit_per_hr, + c.fuel_consumption_lit_per_acr, + c.area_covered_acr_per_hr, + c.nominal_speed_kmph, + c.pto_rpm_set, + c.wheel_slippage_pct, + c.no_of_passes, + ---- test specific measures: effeciency + null, + ---- test specific measures: productivity,rpm and depth-of-operation + c.fuel_consumption_lit_per_hr/area_covered_acr_per_hr, + c.erpmdrop_straight_1stpass_low, + c.erpmdrop_straight_1stpass_high, + c.erpmdrop_straight_2ndpass_low, + c.erpmdrop_straight_2ndpass_high, + c.erpmdrop_straight_3rdpass_low, + c.erpmdrop_straight_3rdpass_high, + c.erpmdrop_turn_1stpass_low, + c.erpmdrop_turn_1stpass_high, + c.erpmdrop_turn_2ndpass_low, + c.erpmdrop_turn_2ndpass_high, + c.erpmdrop_turn_3rdpass_low, + c.erpmdrop_turn_3rdpass_high, + c.depth_of_cut_cm_low , + c.depth_of_cut_cm_high, + current_user, + current_user, + current_timestamp, + current_timestamp + + -- add user and timestamp fields + from + transactional.test_instance a, + transactional.test_instance_tractor_info b, + transactional.field_perf_summary c, + transactional.test_instance_implement_info d + where + a.file_syspk = b.file_syspk + and b.file_syspk = c.file_syspk + and c.file_syspk = d.file_syspk + and c.tractor_model = b.tractor_model + and a.file_mnemonic = f.file_mnemonic + and a.file_syspk = f.file_syspk; + + +elsif f.file_mnemonic = 'FTHLG' +then + insert into fw_ods.fw_ods + ( + -- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name, + client_id, + function_id, + test_file_mnemonic, + test_sheet_mnemonic, + test_file_id, + test_file_name, + test_instance_id, + -- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id + tractor_make, + tractor_model, + mahindra_model_yn, + test_tractor_yn, + tractor_engine_hp, + wheel_drive_type, + configuration, + test_instance_tractor_id, + --test specific: date & test dimensions + test_date, + test_date_year, + test_date_quarter, + test_date_month, + test_date_dayofmonth, + test_date_dayofweek, + --test specific: condition + test_condition, + test_iteration_number, + --test specific: location + location_name, + ----test specific: Implement details(name, type and Weight_kg) + name_of_implement, + type_of_implement, + implement_weight_kg, + -- test specific measures: Speed and gear + -- test specific measures: fuel, area, speed,wheel-slip, productivity,rpm and depth-of-operation + fuel_consumption_lit_per_hr, + gear_used, + gear_user_up_slope_1, + gear_user_up_slope_2, + gear_user_down_slope, + speed_kmph, + mileage_kmpl, + total_dist_travelled_km, + erpmdrop_straight_1stpass_low, + erpmdrop_straight_1stpass_high, + erpmdrop_turn_1stpass_low, + erpmdrop_turn_1stpass_high, + erpmdrop_turn_2ndpass_low, + erpmdrop_turn_2ndpass_high, + erpmdrop_turn_3rdpass_low, + erpmdrop_turn_3rdpass_high, + created_by, + updated_by, + create_timestamp, + update_timestamp + --created_by, updated_by, create_timestamp, update_timestamp + ) + select + -- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name, + a.client_id, + a.function_id, + a.file_mnemonic, + a.file_sheet_mnemonic, + a.file_syspk, + a.test_file_name, + a.syspk, + -- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id + b.tractor_make, + b.tractor_model, + b.mahindra_model_yn, + b.test_tractor_yn, + b.tractor_engine_hp, + b.wheel_drive_type, + b.configuration, + b.syspk, + --test specific: date & test dimensions + a.date_of_test, + extract( year from a.date_of_test), + extract( quarter from a.date_of_test), + extract( month from a.date_of_test), + extract( day from a.date_of_test), + extract( dow from a.date_of_test), + --test specific: condition + c.test_condition, + c.test_iteration_number, + --test specific: location + a.test_location_name, + ----test specific: Implement details(name, type and Weight_kg) + 'Trailer', + d.trailer_type, + d.trailer_gross_weight_kg, + -- test specific measures: Speed and gear + -- test specific measures: fuel, area, speed,wheel-slip, productivity,rpm and depth-of-operation + c.fuel_consumption_lit_per_hr, + c. gear_used_on_straight_road, + c.gear_used_on_up_slope_1, + c.gear_used_on_up_slope_2, + c.gear_used_on_down_slope, + c.avg_speed_of_travel_kmph, + c.Mileage_Km_per_Ltr, + c.total_dist_travelled_km, + c.erpmdrop_straight_1stpass_low, + c.erpmdrop_straight_1stpass_high, + c.erpmdrop_turn_1stpass_low, + c.erpmdrop_turn_1stpass_high, + c.erpmdrop_turn_2ndpass_low, + c.erpmdrop_turn_2ndpass_high, + c.erpmdrop_turn_3rdpass_low, + c.erpmdrop_turn_3rdpass_high, + current_user, + current_user, + current_timestamp, + current_timestamp + -- add user and timestamp fields + from + transactional.test_instance a, + transactional.test_instance_tractor_info b, + transactional.field_perf_summary c, + transactional.field_perf_summary_trailer_info d + where + a.file_syspk = b.file_syspk + and b.file_syspk = c.file_syspk + and c.file_syspk = d.file_syspk + and c.tractor_model = b.tractor_model + and a.file_mnemonic = f.file_mnemonic + and a.file_syspk = f.file_syspk; + + +elsif f.file_mnemonic like 'IHT%' +then + insert into fw_ods.fw_ods( + -- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name, + client_id, + function_id, + test_file_mnemonic, + test_sheet_mnemonic, + test_file_id, + test_file_name, + test_instance_id, + -- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id + tractor_make, + tractor_model, + mahindra_model_yn, + test_tractor_yn, + tractor_engine_hp, + wheel_drive_type, + configuration, + test_instance_tractor_id, + --test specific: date & test dimensions + test_date, + test_date_year, + test_date_quarter, + test_date_month, + test_date_dayofmonth, + test_date_dayofweek, + --test specific: location and test purpose + test_condition, + test_purpose, + location_name, + --Test Specific: + engine_rpm_type, + lifting_time_in_secs, + lowering_time_secs, + created_by, + updated_by, + create_timestamp, + update_timestamp + ) + select + -- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name, + a.client_id, + a.function_id, + a.file_mnemonic, + a.file_sheet_mnemonic, + a.file_syspk, + a.test_file_name, + a.syspk, + -- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id + b.tractor_make, + b.tractor_model, + b.mahindra_model_yn, + b.test_tractor_yn, + b.tractor_engine_hp, + b.wheel_drive_type, + b.configuration, + b.syspk, + --test specific: date & test dimensions + a.date_of_test, + extract( year from a.date_of_test), + extract( quarter from a.date_of_test), + extract( month from a.date_of_test), + extract( day from a.date_of_test), + extract( dow from a.date_of_test), + --test specific: location + c.TPL_load, + a.test_purpose, + a.test_location_name, + -- Test Specific: + c.engine_rpm_type, + c.lifting_time_sec, + c.lowering_time_sec, + current_user, + current_user, + current_timestamp, + current_timestamp + from + transactional.test_instance a, + transactional.test_instance_tractor_info b, + transactional.IHT_hyd_lift_sensitivity c + where + a.file_syspk = b.file_syspk + and b.file_syspk = c.file_syspk + and c.tractor_model = b.tractor_model + and a.test_file_format in ('IHTHLS') + and a.file_syspk = f.file_syspk; + + -- Insert data to fw_ods_iht: for Noise: + insert into fw_ods.fw_ods( + -- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name, + client_id, + function_id, + test_file_mnemonic, + test_sheet_mnemonic, + test_file_id, + test_file_name, + test_instance_id, + -- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id + tractor_make, + tractor_model, + mahindra_model_yn, + test_tractor_yn, + tractor_engine_hp, + wheel_drive_type, + configuration, + test_instance_tractor_id, + --test specific: date & test dimensions + test_date, + test_date_year, + test_date_quarter, + test_date_month, + test_date_dayofmonth, + test_date_dayofweek, + --test specific: location and test purpose + test_mode, + test_type, + test_purpose, + location_name, + --Test Specific: + engine_speed_var, + gear_used, + speed_kmph, + load_kg, + noise_dba, + created_by, + updated_by, + create_timestamp, + update_timestamp + ) + select + -- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name, + a.client_id, + a.function_id, + a.file_mnemonic, + a.file_sheet_mnemonic, + a.file_syspk, + a.test_file_name, + a.syspk, + -- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id + b.tractor_make, + b.tractor_model, + b.mahindra_model_yn, + b.test_tractor_yn, + b.tractor_engine_hp, + b.wheel_drive_type, + b.configuration, + b.syspk, + --test specific: date & test dimensions + a.date_of_test, + extract( year from a.date_of_test), + extract( quarter from a.date_of_test), + extract( month from a.date_of_test), + extract( day from a.date_of_test), + extract( dow from a.date_of_test), + --test specific: location + c.test_mode, + c.test_type, + a.test_purpose, + a.test_location_name, + -- Test Specific: + c.speed_rpm, + c.gear, + c.speed_kmph, + c.load_kg, + (( c.Noise_Level_1_dB_A + c.Noise_Level_2_dB_A +c.Noise_Level_3_dB_A )/3), + current_user, + current_user, + current_timestamp, + current_timestamp + + from + transactional.test_instance a, + transactional.test_instance_tractor_info b, + transactional.iht_noise_measurement_results c + where + a.file_syspk = b.file_syspk + and b.file_syspk = c.file_syspk + and c.tractor_model = b.tractor_model + and a.test_file_format in ('IHTNST') + and a.file_syspk = f.file_syspk; + + + -- Insert data to fw_ods_iht: for Speed Lag: + insert into fw_ods.fw_ods( + -- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name, + client_id, + function_id, + test_file_mnemonic, + test_sheet_mnemonic, + test_file_id, + test_file_name, + test_instance_id, + -- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id + tractor_make, + tractor_model, + mahindra_model_yn, + test_tractor_yn, + tractor_engine_hp, + wheel_drive_type, + configuration, + test_instance_tractor_id, + --test specific: date & test dimensions + test_date, + test_date_year, + test_date_quarter, + test_date_month, + test_date_dayofmonth, + test_date_dayofweek, + --test specific: location and test purpose + test_condition, + test_purpose, + location_name, + --Test Specific: + gear_used, + gear_forward_reverse, + speed_on_high_rpm_kmph, + speed_on_low_rpm_kmph, + speed_on_rated_rpm_kmph, + created_by, + updated_by, + create_timestamp, + update_timestamp + ) + select + -- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name, + a.client_id, + a.function_id, + a.test_file_format, + a.test_file_sheet_format, + a.file_syspk, + a.test_file_name, + a.syspk, + -- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id + b.tractor_make, + b.tractor_model, + b.mahindra_model_yn, + b.test_tractor_yn, + b.tractor_engine_hp, + b.wheel_drive_type, + b.configuration, + b.syspk, + --test specific: date & test dimensions + a.date_of_test, + extract( year from a.date_of_test), + extract( quarter from a.date_of_test), + extract( month from a.date_of_test), + extract( day from a.date_of_test), + extract( dow from a.date_of_test), + --test specific: location + c.test_condition, + a.test_purpose, + a.test_location_name, + -- Test Specific: + c.gear, + c.test_condition, + c.high_2500_rpm, + c.low_1000_rpm, + c.rated_2300_rpm, + current_user, + current_user, + current_timestamp, + current_timestamp + from + transactional.test_instance a, + transactional.test_instance_tractor_info b, + transactional.iht_gear_max_speed c + where + a.file_syspk = b.file_syspk + and b.file_syspk = c.file_syspk + and c.tractor_model = b.tractor_model + and a.test_file_format in ('IHTSLL') + and a.file_syspk = f.file_syspk; + + + -- Insert data to fw_ods_iht: for Brake: + insert into fw_ods.fw_ods( + -- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name, + client_id, + function_id, + test_file_mnemonic, + test_sheet_mnemonic, + test_file_id, + test_file_name, + test_instance_id, + -- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id + tractor_make, + tractor_model, + mahindra_model_yn, + test_tractor_yn, + tractor_engine_hp, + wheel_drive_type, + configuration, + test_instance_tractor_id, + --test specific: date & test dimensions + test_date, + test_date_year, + test_date_quarter, + test_date_month, + test_date_dayofmonth, + test_date_dayofweek, + --test specific: location and test purpose + test_mode, + test_condition, + location_name, + --Test Specific: + effort_type, + speed_kmph, + effort_kg, + required_stopping_distance_m, + actual_stopping_distance_m, + decceleartoin_m_per_s2 , + created_by, + updated_by, + create_timestamp, + update_timestamp + ) + select + -- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name, + a.client_id, + a.function_id, + a.test_file_format, + a.test_file_sheet_format, + a.file_syspk, + a.test_file_name, + a.syspk, + -- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id + b.tractor_make, + b.tractor_model, + b.mahindra_model_yn, + b.test_tractor_yn, + b.tractor_engine_hp, + b.wheel_drive_type, + b.configuration, + b.syspk, + --test specific: date & test dimensions + a.date_of_test, + extract( year from a.date_of_test), + extract( quarter from a.date_of_test), + extract( month from a.date_of_test), + extract( day from a.date_of_test), + extract( dow from a.date_of_test), + --test specific: location + c.test_mode, + c.test_condition, + a.test_location_name, + -- Test Specific: + 'Brake', + c.trigger_speed_km_per_h, + c.brake_control_input_force_kg, + c.required_corrected_stopping_distance_m, + c.actual_stopping_distance_m, + c.deceleration_m_s2_v2_2s, + current_user, + current_user, + current_timestamp, + current_timestamp + from + transactional.test_instance a, + transactional.test_instance_tractor_info b, + transactional.iht_brake_perf_test_results c + where + a.file_syspk = b.file_syspk + and b.file_syspk = c.file_syspk + and c.tractor_model = b.tractor_model + and a.test_file_format in ('IHTBT50', 'IHTBT30', 'IHTBTD') + and a.file_syspk = f.file_syspk; + + + -- data for Pedal Effort: from transactional.iht_pedal_effort + insert into fw_ods.fw_ods( + -- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name, + client_id, + function_id, + test_file_mnemonic, + test_sheet_mnemonic, + test_file_id, + test_file_name, + test_instance_id, + -- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id + tractor_make, + tractor_model, + mahindra_model_yn, + test_tractor_yn, + tractor_engine_hp, + wheel_drive_type, + configuration, + test_instance_tractor_id, + --test specific: date & test dimensions + test_date, + test_date_year, + test_date_quarter, + test_date_month, + test_date_dayofmonth, + test_date_dayofweek, + --test specific: location and test purpose + test_purpose, + location_name, + --Test Specific: + gear_pedal_effort_parameters, + effort_type, + effort_kg, + brake_pedal_travel_lh_in_mm, + brake_pedal_travel_rh_in_mm, + brake_pedal_travel_latched_in_mm, + pedal_travel_mm, + created_by, + updated_by, + create_timestamp, + update_timestamp + ) + select + -- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name, + a.client_id, + a.function_id, + a.test_file_format, + a.test_file_sheet_format, + a.file_syspk, + a.test_file_name, + a.syspk, + -- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id + b.tractor_make, + b.tractor_model, + b.mahindra_model_yn, + b.test_tractor_yn, + b.tractor_engine_hp, + b.wheel_drive_type, + b.configuration, + b.syspk, + --test specific: date & test dimensions + a.date_of_test, + extract( year from a.date_of_test), + extract( quarter from a.date_of_test), + extract( month from a.date_of_test), + extract( day from a.date_of_test), + extract( dow from a.date_of_test), + --test specific: location + a.test_purpose, + a.test_location_name, + -- Test Specific: + c.parameters, + 'pedal', + c.efforts_kg, + null, + null, + null, + c.travel_mm, + current_user, + current_user, + current_timestamp, + current_timestamp + from + transactional.test_instance a, + transactional.test_instance_tractor_info b, + transactional.iht_pedal_effort c + where + a.file_syspk = b.file_syspk + and b.file_syspk = c.file_syspk + and c.tractor_model = b.tractor_model + and a.test_file_format in ('IHTEMT') + and a.file_syspk = f.file_syspk; + + + -- Data for Gear Effort from transactional.iht_gear_effort + insert into fw_ods.fw_ods( + -- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name, + client_id, + function_id, + test_file_mnemonic, + test_sheet_mnemonic, + test_file_id, + test_file_name, + test_instance_id, + -- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id + tractor_make, + tractor_model, + mahindra_model_yn, + test_tractor_yn, + tractor_engine_hp, + wheel_drive_type, + configuration, + test_instance_tractor_id, + --test specific: date & test dimensions + test_date, + test_date_year, + test_date_quarter, + test_date_month, + test_date_dayofmonth, + test_date_dayofweek, + --test specific: location + test_purpose, + location_name, + --Test Specific: + gear_pedal_effort_parameters, + effort_type, + effort_kg, + brake_pedal_travel_lh_in_mm, + brake_pedal_travel_rh_in_mm, + brake_pedal_travel_latched_in_mm, + pedal_travel_mm, + created_by, + updated_by, + create_timestamp, + update_timestamp + ) + select + -- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name, + a.client_id, + a.function_id, + a.test_file_format, + a.test_file_sheet_format, + a.file_syspk, + a.test_file_name, + a.syspk, + -- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id + b.tractor_make, + b.tractor_model, + b.mahindra_model_yn, + b.test_tractor_yn, + b.tractor_engine_hp, + b.wheel_drive_type, + b.configuration, + b.syspk, + --test specific: date & test dimensions + a.date_of_test, + extract( year from a.date_of_test), + extract( quarter from a.date_of_test), + extract( month from a.date_of_test), + extract( day from a.date_of_test), + extract( dow from a.date_of_test), + --test specific: location + a.test_purpose, + a.test_location_name, + -- Test Specific: + c.parameters, + 'Gear', + c.efforts_kg, + null, + null, + null, + null, + current_user, + current_user, + current_timestamp, + current_timestamp + from + transactional.test_instance a, + transactional.test_instance_tractor_info b, + transactional.iht_gear_effort c + where + a.file_syspk = b.file_syspk + and b.file_syspk = c.file_syspk + and c.tractor_model = b.tractor_model + and a.test_file_format in ('IHTEMT') + and a.file_syspk = f.file_syspk; + + + + -- Data for Break Pedal Effor: from table transactional.iht_brake_pedal_effort + insert into fw_ods.fw_ods( + -- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name, + client_id, + function_id, + test_file_mnemonic, + test_sheet_mnemonic, + test_file_id, + test_file_name, + test_instance_id, + -- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id + tractor_make, + tractor_model, + mahindra_model_yn, + test_tractor_yn, + tractor_engine_hp, + wheel_drive_type, + configuration, + test_instance_tractor_id, + --test specific: date & test dimensions + test_date, + test_date_year, + test_date_quarter, + test_date_month, + test_date_dayofmonth, + test_date_dayofweek, + --test specific: location + test_purpose, + location_name, + --Test Specific: + gear_pedal_effort_parameters, + effort_type, + effort_kg, + brake_pedal_travel_lh_in_mm, + brake_pedal_travel_rh_in_mm, + brake_pedal_travel_latched_in_mm, + pedal_travel_mm, + created_by, + updated_by, + create_timestamp, + update_timestamp + ) + select + -- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name, + a.client_id, + a.function_id, + a.test_file_format, + a.test_file_sheet_format, + a.file_syspk, + a.test_file_name, + a.syspk, + -- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id + b.tractor_make, + b.tractor_model, + b.mahindra_model_yn, + b.test_tractor_yn, + b.tractor_engine_hp, + b.wheel_drive_type, + b.configuration, + b.syspk, + --test specific: date & test dimensions + a.date_of_test, + extract( year from a.date_of_test), + extract( quarter from a.date_of_test), + extract( month from a.date_of_test), + extract( day from a.date_of_test), + extract( dow from a.date_of_test), + --test specific: location + a.test_purpose, + a.test_location_name, + -- Test Specific: + null, + 'Brake Pedal', + c.pedal_effort_kg, + pedal_travel_rh_mm, + pedal_travel_lh_mm, + pedal_travel_latched_mm, + null, + current_user, + current_user, + current_timestamp, + current_timestamp + from + transactional.test_instance a, + transactional.test_instance_tractor_info b, + transactional.iht_brake_pedal_effort c + where + a.file_syspk = b.file_syspk + and b.file_syspk = c.file_syspk + and c.tractor_model = b.tractor_model + and a.test_file_format in ('IHTEMT') + and a.file_syspk = f.file_syspk; + + --Data for Cluth PedalEffort: from transactional.iht_clutch_pedal_effort + insert into fw_ods.fw_ods( + -- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name, + client_id, + function_id, + test_file_mnemonic, + test_sheet_mnemonic, + test_file_id, + test_file_name, + test_instance_id, + -- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id + tractor_make, + tractor_model, + mahindra_model_yn, + test_tractor_yn, + tractor_engine_hp, + wheel_drive_type, + configuration, + test_instance_tractor_id, + --test specific: date & test dimensions + test_date, + test_date_year, + test_date_quarter, + test_date_month, + test_date_dayofmonth, + test_date_dayofweek, + --test specific: location + test_purpose, + location_name, + --Test Specific: + gear_pedal_effort_parameters, + effort_type, + effort_kg, + brake_pedal_travel_lh_in_mm, + brake_pedal_travel_rh_in_mm, + brake_pedal_travel_latched_in_mm, + pedal_travel_mm, + created_by, + updated_by, + create_timestamp, + update_timestamp + ) + select + -- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name, + a.client_id, + a.function_id, + a.test_file_format, + a.test_file_sheet_format, + a.file_syspk, + a.test_file_name, + a.syspk, + -- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id + b.tractor_make, + b.tractor_model, + b.mahindra_model_yn, + b.test_tractor_yn, + b.tractor_engine_hp, + b.wheel_drive_type, + b.configuration, + b.syspk, + --test specific: date & test dimensions + a.date_of_test, + extract( year from a.date_of_test), + extract( quarter from a.date_of_test), + extract( month from a.date_of_test), + extract( day from a.date_of_test), + extract( dow from a.date_of_test), + --test specific: location + a.test_purpose, + a.test_location_name, + -- Test Specific: + null, + 'Clutch Pedal', + c.pedal_effort_kg, + null, + null, + null, + c.pedal_travel_mm, + current_user, + current_user, + current_timestamp, + current_timestamp + from + transactional.test_instance a, + transactional.test_instance_tractor_info b, + transactional.iht_clutch_pedal_effort c + where + a.file_syspk = b.file_syspk + and b.file_syspk = c.file_syspk + and c.tractor_model = b.tractor_model + and a.test_file_format in ('IHTEMT') + and a.file_syspk = f.file_syspk; + end if; + end loop; + +update fw_core.fw_jobctl_runschedule_jobstep set end_status_note = 'trx_load_completed', end_status='success', end_time=now() where job_id = p_job_id and step_id = p_step_id and latest_runschedule_flag = '1'; + +end +$$ +LANGUAGE plpgsql; \ No newline at end of file diff --git a/onetime/dataloadfunctions/PTO/PTO_GVG_ods.sql b/onetime/dataloadfunctions/PTO/PTO_GVG_ods.sql new file mode 100755 index 0000000..2080e85 --- /dev/null +++ b/onetime/dataloadfunctions/PTO/PTO_GVG_ods.sql @@ -0,0 +1,261 @@ +drop function if exists staging2.fn_PTO_GVG_TRX; +CREATE OR REPLACE FUNCTION staging2.fn_PTO_GVG_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS text AS $$ + declare __make text; + declare __model text; + declare __test_instance_id int; + declare __test_instance_tractor_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + begin + +SET search_path TO staging2; + +/************************************************************ +Function Name:fn_PTOBEN_GVG_TRX +Function Desc: This function populates data into ODS blocks +File Format: PTOBEN +Sheet Format: PTOBEN_GVG +Creation Date: April 27 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_PTO_GVG_TRX(907) +***************************************************************/ +select tractor_model into __model from transactional.test_instance_tractor_info where file_syspk =__file_syspk; +select tractor_make into __make from transactional.test_instance_tractor_info where file_syspk =__file_syspk; +select syspk from transactional.test_master into __test_master_id where test_type ='PTO'; + + +insert into transactional.test_instance +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic , +tractor_make, +tractor_model +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +case when __file_sheet_mnemonic = 'PTOBEN_GVG' then 'PTOBEN_GVG' +else 'PTOSTD_GVG' +end, +make, +model +from staging2.ptoben_prf_tractor_specs_block where trx_record=1; + +update transactional.test_instance +set test_file_name =(select a.file_name from staging1.staging_generic_table a where file_syspk = __file_syspk limit 1) +where file_syspk = __file_syspk; + + +insert into transactional.PTO_Perf_Governing_Graph +(client_id, +function_id, +file_syspk, +tractor_make, +tractor_model, +test_condition, +test_type, +engine_speed_rpm, +torque_kg_m, +power_hp, +sfc_gm_per_hp_hr, +fuelling_mm3_per_stroke_per_cyl, +file_mnemonic, +file_sheet_mnemonic) +select +client_id, +function_id, +file_syspk, +make, +model, +test_condition , +c1, +c2::numeric, +c3::numeric, +c4::numeric, +c5::numeric, +c6::numeric, +file_mnemonic, +file_sheet_mnemonic +from staging2.PTOBEN_GVG_performance_governing_trails_block +where trx_record=1 +union +select +client_id, +function_id, +file_syspk, +make, +model, +test_condition , +c7_1, +c7::numeric, +c8::numeric, +c9::numeric, +c10::numeric, +c11::numeric, +file_mnemonic, +file_sheet_mnemonic +from staging2.PTOBEN_GVG_performance_governing_trails_block +where trx_record=1 +and (c7 is not null and c8 is not null and c9 is not null and c10 is not null and c11 is not null) +union +select +client_id, +function_id, +file_syspk, +make, +model, +test_condition , +c12_1, +c12::numeric, +c13::numeric, +c14::numeric, +c15::numeric, +c16::numeric, +file_mnemonic, +file_sheet_mnemonic +from staging2.PTOBEN_GVG_performance_governing_trails_block +where trx_record=1 +and (c12 is not null and c13 is not null and c14 is not null and c15 is not null and c16 is not null) +union +select +client_id, +function_id, +file_syspk, +make, +model, +test_condition , +c17_1, +c17::numeric, +c18::numeric, +c19::numeric, +c20::numeric, +c21::numeric, +file_mnemonic, +file_sheet_mnemonic +from staging2.PTOBEN_GVG_performance_governing_trails_block +where trx_record=1 +and (c17 is not null and c18 is not null and c19 is not null and c20 is not null and c21 is not null) +union +select +client_id, +function_id, +file_syspk, +model, +make, +test_condition , +c22_1, +c22::numeric, +c23::numeric, +c24::numeric, +c25::numeric, +c26::numeric, +file_mnemonic, +file_sheet_mnemonic +from staging2.PTOBEN_GVG_performance_governing_trails_block +where trx_record=1 +and (c22 is not null and c23 is not null and c24 is not null and c25 is not null and c26 is not null) +union +select +client_id, +function_id, +file_syspk, +model, +make, +test_condition , +c27_1, +c27::numeric, +c28::numeric, +c29::numeric, +c30::numeric, +c31::numeric, +file_mnemonic, +file_sheet_mnemonic +from staging2.PTOBEN_GVG_performance_governing_trails_block +where trx_record=1 +and (c27 is not null and c28 is not null and c29 is not null and c30 is not null and c32 is not null) +union +select +client_id, +function_id, +file_syspk, +model, +make, +test_condition , +c32_1, +c32::numeric, +c33::numeric, +c34::numeric, +c35::numeric, +c36::numeric, +file_mnemonic, +file_sheet_mnemonic +from staging2.PTOBEN_GVG_performance_governing_trails_block +where trx_record=1 +and (c32 is not null and c33 is not null and c34 is not null and c35 is not null and c36 is not null); + +update transactional.PTO_Perf_Governing_Graph set test_mode = 'Normal Mode' where file_sheet_mnemonic = 'PTOBEN_GVGN' and file_syspk = __file_syspk; +update transactional.PTO_Perf_Governing_Graph set test_mode = 'Boost Mode' where file_sheet_mnemonic = 'PTOBEN_GVGB' and file_syspk = __file_syspk; +update transactional.PTO_Perf_Governing_Graph set test_mode = 'Eco Mode' where file_sheet_mnemonic = 'PTOBEN_GVGE' and file_syspk = __file_syspk; +update transactional.PTO_Perf_Governing_Graph set test_mode = 'Standard Mode' where file_sheet_mnemonic = 'PTOSTD_GVG' and file_syspk = __file_syspk; + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk; + + +update transactional.PTO_Perf_Governing_Graph +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.test_instance +set test_tractor_id = __test_instance_tractor_id, +test_master_id = __test_master_id +where file_syspk=__file_syspk and file_sheet_mnemonic =__file_sheet_mnemonic; + +update transactional.test_instance a +set (test_location_name,test_engineer,date_of_test) = (select place,test_engineer,TO_DATE(test_date, 'DD/MM/YYYY') from staging2.PTOBEN_PRF_Key_Performance_Parameters_block where file_syspk = __file_syspk and test_condition='observed') +where file_syspk = __file_syspk; + +UPDATE transactional.pto_perf_governing_graph a set test_mode = CASE WHEN a.test_condition like '%Normal%' THEN 'Normal' + WHEN a.test_condition like '%Eco%' THEN 'Eco' + WHEN a.test_condition like '%Boost%' THEN 'Boost' + WHEN a.test_condition like '%Standard%' THEN 'Standard' + ELSE NULL + end; + + err_context := ''; +perform fw_core.fn_insert_db_error( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_PTO_GVG_trx', err_state, err_msg, err_detail, err_hint, err_context,'success'); +return err_context; + +EXCEPTION when OTHERS then + +GET STACKED DIAGNOSTICS + err_state = returned_sqlstate, + err_msg = message_text, + err_detail = pg_exception_detail, + err_hint = pg_exception_hint, + err_context = pg_exception_context; + + perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_PTO_GVG_trx', err_state, err_msg, err_detail, err_hint, err_context,'error'); +return err_context; +end +$$ LANGUAGE plpgsql; diff --git a/onetime/dataloadfunctions/PTO/PTO_GVG_stg2.sql b/onetime/dataloadfunctions/PTO/PTO_GVG_stg2.sql new file mode 100755 index 0000000..c765813 --- /dev/null +++ b/onetime/dataloadfunctions/PTO/PTO_GVG_stg2.sql @@ -0,0 +1,383 @@ +drop function if exists staging2.fn_PTO_GVG_block; +CREATE OR REPLACE FUNCTION staging2.fn_PTO_GVG_block(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS text AS $$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + + begin +/************************************************************************************ +Function Name:fn_PTOBEN_GVG_block +Function Desc: This function populates data into staging2 blocks +File Format: PTOBEN +Sheet Format: PTOBEN_GVG +Creation Date: April 27 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_PTO_GVG_block(1,1,'PTOBEN','PTOBEN_GVG',944) +***************************************************************************************/ + +SET search_path TO staging2; + + +/* rerunnability - delete block tables and update config tables to null */ +truncate table staging2.stg_specific_table_PTOBEN_GVG; +truncate table staging2.stg_process_table_PTOBEN_GVG; +truncate table staging2.PTOBEN_GVG_performance_governing_trails_block; + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* transfer data from generic to specific for PTOBEN */ +execute 'insert into staging2.stg_specific_table_PTOBEN_GVG +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_PTOBEN_GVG; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for pto', + detail = 'No data in table stg_specific_table_PTOBEN_PRF', + errcode = 'PTO', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + + +/* trimming data */ +update staging2.stg_specific_table_PTOBEN_GVG set column3 = TRIM (TRAILING FROM column3 ); +update staging2.stg_specific_table_PTOBEN_GVG set column3 = TRIM (LEADING FROM column3 ); + +update transactional.source_config set F1_modified = TRIM (TRAILING FROM F1_modified) ; +update transactional.source_config set F1_modified = TRIM (LEADING FROM F1_modified) ; +update transactional.source_config set F1_source=F1_modified ; +update transactional.source_config set F1_source = TRIM (TRAILING FROM F1_source); +update transactional.source_config set F1_source = TRIM (LEADING FROM F1_source); + +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_PTOBEN_GVG b +where trim(upper(F1_modified))=trim(upper(column2)) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* keyword match in config table*/ +execute 'update staging2.stg_specific_table_PTOBEN_GVG a +set is_rownumber_fetched=1 +from transactional.source_config b +where trim(upper(F1_modified))=trim(upper(column3)) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a +set row_read_end = null ,run_time=current_timestamp +where f1_modified =''Graphs - for Example'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers*/ + +execute 'insert into staging2.stg_process_table_PTOBEN_GVG +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_PTOBEN_GVG a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Data Inputs'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_PTOBEN_GVG +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_PTOBEN_GVG a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Graphs - for Example'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +select column5 into __make from staging2.stg_process_table_PTOBEN_PRF a +where block_tag='PTOBEN_PRF_Key_Performance_Parameters' and block_row_number=7 ; + +select column5 into __model from staging2.stg_process_table_PTOBEN_PRF a +where block_tag='PTOBEN_PRF_Key_Performance_Parameters' and block_row_number=9; + + +/* block PTOBEN_GVG_performance_governing_trails_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'PTOBEN_GVG_performance_governing_trails_block',__file_mnemonic,__file_sheet_mnemonic,1); + +err_block := 'PTOBEN_GVG_performance_governing_trails_block'; + +insert into staging2.PTOBEN_GVG_performance_governing_trails_block +( +c2, +c3, +c4, +c5, +c6, +c7, +c8, +c9, +c10, +c11, +c12, +c13, +c14, +c15, +c16, +c17, +c18, +c19, +c20, +c21, +c22, +c23, +c24, +c25, +c26, +c27, +c28, +c29, +c30, +c31, +c32, +c33, +c34, +c35, +c36, +block_row_number +) + +select column2, +column3, +column4, +column5, +column6, +column7, +column8, +column9, +column10, +column11, +column12, +column13, +column14, +column15, +column16, +column17, +column18, +column19, +column20, +column21, +column22, +column23, +column24, +column25, +column26, +column27, +column28, +column29, +column30, +column31, +column32, +column33, +column34, +column35, +column36, +block_row_number + from staging2.stg_process_table_PTOBEN_GVG a +where block_tag='PTOBEN_GVG_data_inputs'; + +update staging2.PTOBEN_GVG_performance_governing_trails_block +set test_condition=c2 +where block_row_number=2; + +update staging2.PTOBEN_GVG_performance_governing_trails_block +set c2=null +where block_row_number=2; + +update staging2.PTOBEN_GVG_performance_governing_trails_block a +set test_condition= b.first_value from (SELECT + block_row_number, test_condition, value_partition, first_value(test_condition) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + test_condition, + sum(case when test_condition is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.PTOBEN_GVG_performance_governing_trails_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + +update staging2.PTOBEN_GVG_performance_governing_trails_block +set c1=c2 where block_row_number=5; + +update staging2.PTOBEN_GVG_performance_governing_trails_block a +set c1= b.first_value from (SELECT + block_row_number, c1, value_partition, first_value(c1) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + c1, + sum(case when c1 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.PTOBEN_GVG_performance_governing_trails_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + + +update staging2.PTOBEN_GVG_performance_governing_trails_block +set c7_1=c7 where block_row_number=5; + +update staging2.PTOBEN_GVG_performance_governing_trails_block a +set c7_1= b.first_value from (SELECT + block_row_number, c7_1, value_partition, first_value(c7_1) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + c7_1, + sum(case when c7_1 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.PTOBEN_GVG_performance_governing_trails_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + +update staging2.PTOBEN_GVG_performance_governing_trails_block +set c12_1=c12 where block_row_number=5; + +update staging2.PTOBEN_GVG_performance_governing_trails_block a +set c12_1= b.first_value from (SELECT + block_row_number, c12_1, value_partition, first_value(c12_1) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + c12_1, + sum(case when c12_1 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.PTOBEN_GVG_performance_governing_trails_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + +update staging2.PTOBEN_GVG_performance_governing_trails_block +set c17_1=c17 where block_row_number=5; + +update staging2.PTOBEN_GVG_performance_governing_trails_block a +set c17_1= b.first_value from (SELECT + block_row_number, c17_1, value_partition, first_value(c17_1) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + c17_1, + sum(case when c17_1 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.PTOBEN_GVG_performance_governing_trails_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + +update staging2.PTOBEN_GVG_performance_governing_trails_block +set c22_1=c22 where block_row_number=5; + +update staging2.PTOBEN_GVG_performance_governing_trails_block a +set c22_1= b.first_value from (SELECT + block_row_number, c22_1, value_partition, first_value(c22_1) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + c22_1, + sum(case when c22_1 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.PTOBEN_GVG_performance_governing_trails_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + +update staging2.PTOBEN_GVG_performance_governing_trails_block +set c27_1=c27 where block_row_number=5; + +update staging2.PTOBEN_GVG_performance_governing_trails_block a +set c27_1= b.first_value from (SELECT + block_row_number, c27_1, value_partition, first_value(c27_1) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + c27_1, + sum(case when c27_1 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.PTOBEN_GVG_performance_governing_trails_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + +update staging2.PTOBEN_GVG_performance_governing_trails_block +set c32_1=c32 where block_row_number=5; + +update staging2.PTOBEN_GVG_performance_governing_trails_block a +set c32_1= b.first_value from (SELECT + block_row_number, c32_1, value_partition, first_value(c32_1) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + c32_1, + sum(case when c32_1 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.PTOBEN_GVG_performance_governing_trails_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + + +update staging2.PTOBEN_GVG_performance_governing_trails_block +set trx_record=0 where block_row_number in (1,2,3,4,5); + + execute 'update staging2.PTOBEN_GVG_performance_governing_trails_block set client_id='||p_client_id||''; + execute 'update staging2.PTOBEN_GVG_performance_governing_trails_block set function_id='||p_function_id||''; + execute 'update staging2.PTOBEN_GVG_performance_governing_trails_block set file_mnemonic='''||p_file_mnemonic||''''; + execute 'update staging2.PTOBEN_GVG_performance_governing_trails_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.PTOBEN_GVG_performance_governing_trails_block set file_syspk='||p_file_syspk||''; + + update staging2.PTOBEN_GVG_performance_governing_trails_block set make=__make; + update staging2.PTOBEN_GVG_performance_governing_trails_block set model=__model; + + +perform fw_core.fn_jobctl_block_end(__file_syspk,'PTOBEN_GVG_performance_governing_trails_block'); + + err_context := ''; +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_PTO_GVG_block', err_state, err_msg, err_detail, err_hint, err_context,'success'); +return err_context; + +EXCEPTION when OTHERS then + +GET STACKED DIAGNOSTICS + err_state = returned_sqlstate, + err_msg = message_text, + err_detail = pg_exception_detail, + err_hint = pg_exception_hint, + err_context = pg_exception_context; + + perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_PTO_GVG_block', err_state, err_msg, err_detail, err_hint, err_context,'error'); +return err_context; +end +$$ LANGUAGE plpgsql; diff --git a/onetime/dataloadfunctions/PTO/PTO_MPM_ods.sql b/onetime/dataloadfunctions/PTO/PTO_MPM_ods.sql new file mode 100755 index 0000000..c06bcd1 --- /dev/null +++ b/onetime/dataloadfunctions/PTO/PTO_MPM_ods.sql @@ -0,0 +1,133 @@ +drop function if exists staging2.fn_PTO_MPM_TRX; +CREATE OR REPLACE FUNCTION staging2.fn_PTO_MPM_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS text AS $$ + declare __test_instance_id int; + declare __test_instance_tractor_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; +begin + +/*********************************************************** +Function Name:fn_PTOBEN_MPM_TRX +Function Desc: This function populates data into ODS blocks +File Format: PTOBEN +Sheet Format: PTOBEN_MPM +Creation Date: April 27 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_PTO_MPM_TRX(907) +***************************************************************/ + +select tractor_model into __model from transactional.test_instance_tractor_info where file_syspk =__file_syspk; +select tractor_make into __make from transactional.test_instance_tractor_info where file_syspk =__file_syspk; +select syspk from transactional.test_master into __test_master_id where test_type ='PTO'; + + +insert into transactional.test_instance +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic , +tractor_make, +tractor_model +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +case when __file_sheet_mnemonic = 'PTOBEN_MPM' then 'PTOBEN_MPM' +else 'PTOSTD_MPM' +end, +make, +model +from staging2.ptoben_prf_tractor_specs_block where trx_record=1; + +update transactional.test_instance +set test_file_name =(select a.file_name from staging1.staging_generic_table a where file_syspk = __file_syspk limit 1) +where file_syspk = __file_syspk; + + + + insert into transactional.PTO_Multipoint_Mapping +( +client_id,function_id,file_syspk,file_mnemonic,file_sheet_mnemonic, +tractor_make ,tractor_model , +test_condition, +engine_speed_rpm, +engine_load_pct, +sfc_gm_per_hp_hr, +fuel_consumption_ltr_per_hr +) + +select client_id,function_id,file_syspk,file_mnemonic,file_sheet_mnemonic,make,model,test_condition, +c2::numeric,c3::numeric,c4::numeric,c5::numeric +from staging2.PTOBEN_MPM_performance_boost_natural_block +where trx_record=1 ; + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk; + + +update transactional.PTO_Multipoint_Mapping set test_mode = 'Normal Mode' where file_sheet_mnemonic = 'PTOBEN_MPMN' and file_syspk = __file_syspk; +update transactional.PTO_Multipoint_Mapping set test_mode = 'Boost Mode' where file_sheet_mnemonic = 'PTOBEN_MPMB' and file_syspk = __file_syspk; +update transactional.PTO_Multipoint_Mapping set test_mode = 'Eco Mode' where file_sheet_mnemonic = 'PTOBEN_MPME' and file_syspk = __file_syspk; +update transactional.PTO_Multipoint_Mapping set test_mode = 'Standard Mode' where file_sheet_mnemonic = 'PTOSTD_MPM' and file_syspk = __file_syspk; + + +update transactional.PTO_Multipoint_Mapping +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.test_instance +set test_tractor_id = __test_instance_tractor_id, +test_master_id = __test_master_id +where file_syspk=__file_syspk and file_sheet_mnemonic =__file_sheet_mnemonic; + +update transactional.test_instance a +set (test_location_name,test_engineer,date_of_test) = (select place,test_engineer,TO_DATE(test_date, 'DD/MM/YYYY') from staging2.PTOBEN_PRF_Key_Performance_Parameters_block where file_syspk = __file_syspk and test_condition='observed') +where file_syspk = __file_syspk; + +UPDATE transactional.pto_multipoint_mapping a set test_mode = CASE WHEN a.test_condition like '%Normal%' THEN 'Normal' + WHEN a.test_condition like '%Eco%' THEN 'Eco' + WHEN a.test_condition like '%Boost%' THEN 'Boost' + WHEN a.test_condition like '%Standard%' THEN 'Standard' + ELSE NULL + end; + +err_context := ''; +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_PTO_MPM_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); +return err_context; + + + +EXCEPTION when OTHERS then + +GET STACKED DIAGNOSTICS + err_state = returned_sqlstate, + err_msg = message_text, + err_detail = pg_exception_detail, + err_hint = pg_exception_hint, + err_context = pg_exception_context; + + perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_PTO_MPM_TRX', err_state, err_msg, err_detail, err_hint, err_context,'error'); +return err_context; +end +$$ LANGUAGE plpgsql; + diff --git a/onetime/dataloadfunctions/PTO/PTO_MPM_stg2.sql b/onetime/dataloadfunctions/PTO/PTO_MPM_stg2.sql new file mode 100755 index 0000000..3efd92d --- /dev/null +++ b/onetime/dataloadfunctions/PTO/PTO_MPM_stg2.sql @@ -0,0 +1,195 @@ +drop function if exists staging2.fn_PTO_MPM_block; +CREATE OR REPLACE FUNCTION staging2.fn_PTO_MPM_block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS text AS $$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + + begin + +/************************************************************************************ +Function Name:fn_PTOBEN_MPM_block +Function Desc: This function populates data into staging2 blocks +File Format: PTOBEN +Sheet Format: PTOBEN_MPMB +Creation Date: April 26 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_PTO_MPM_block(1,1,'PTOBEN','PTOBEN_MPM',944) +***************************************************************************************/ + +SET search_path TO staging2; + +/* rerunnability - delete block tables and update config tables to null */ +truncate table staging2.stg_specific_table_PTOBEN_MPM; +truncate table staging2.stg_process_table_PTOBEN_MPM; +truncate table staging2.PTOBEN_MPM_performance_boost_natural_block; + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* transfer data from generic to specific for PTOBST */ +execute 'insert into staging2.stg_specific_table_PTOBEN_MPM +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_PTOBEN_MPM; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for pto', + detail = 'No data in table stg_specific_table_PTOBEN_PRF', + errcode = 'PTO', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + +/* trimming data */ +update staging2.stg_specific_table_PTOBEN_MPM set column3 = TRIM (TRAILING FROM column3 ); +update staging2.stg_specific_table_PTOBEN_MPM set column3 = TRIM (LEADING FROM column3 ); + +update transactional.source_config set F1_source=F1_modified ; + +/* keyword match in config table*/ +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_PTOBEN_MPM b +where trim(upper(F1_modified))=trim(upper(column2)) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update*/ +execute 'update staging2.stg_specific_table_PTOBEN_MPM a +set is_rownumber_fetched=1 +from transactional.source_config b +where trim(upper(F1_modified))=trim(upper(column3)) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a +set row_read_end = null ,run_time=current_timestamp +where f1_modified =''Performance - Boost Mode @ Natural Ambient'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers*/ + +execute 'insert into staging2.stg_process_table_PTOBEN_MPM +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_PTOBEN_MPM a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Data Inputs'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +select column5 into __make from staging2.stg_process_table_PTOBEN_PRF a +where block_tag='PTOBEN_PRF_Key_Performance_Parameters' and block_row_number=7 ; + +select column5 into __model from staging2.stg_process_table_PTOBEN_PRF a +where block_tag='PTOBEN_PRF_Key_Performance_Parameters' and block_row_number=9; + +/* block - PTOBEN_MPM_performance_boost_natural_block*/ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'PTOBEN_MPM_performance_boost_natural_block',__file_mnemonic,__file_sheet_mnemonic,1); +err_block :='PTOBEN_MPM_performance_boost_natural_block'; +insert into staging2.PTOBEN_MPM_performance_boost_natural_block +( +c2, +c3, +c4, +c5, +block_row_number +) +select column2,column3,column4 ,column5,block_row_number from staging2.stg_process_table_PTOBEN_MPM +where block_tag='PTOBEN_MPM_data_inputs'; + + +update staging2.PTOBEN_MPM_performance_boost_natural_block +set test_condition=c2 +where block_row_number=2; + +update staging2.PTOBEN_MPM_performance_boost_natural_block +set c2=null +where block_row_number=2; + + +update staging2.PTOBEN_MPM_performance_boost_natural_block a +set test_condition= b.first_value from (SELECT + block_row_number, test_condition, value_partition, first_value(test_condition) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + test_condition, + sum(case when test_condition is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.PTOBEN_MPM_performance_boost_natural_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + + +update staging2.PTOBEN_MPM_performance_boost_natural_block +set trx_record=0 +where block_row_number in (1,2,3); + + execute 'update staging2.PTOBEN_MPM_performance_boost_natural_block set client_id='||p_client_id||''; + execute 'update staging2.PTOBEN_MPM_performance_boost_natural_block set function_id='||p_function_id||''; + execute 'update staging2.PTOBEN_MPM_performance_boost_natural_block set file_mnemonic='''||p_file_mnemonic||''''; + execute 'update staging2.PTOBEN_MPM_performance_boost_natural_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.PTOBEN_MPM_performance_boost_natural_block set file_syspk='||p_file_syspk||''; + + update staging2.PTOBEN_MPM_performance_boost_natural_block set make=__make; + update staging2.PTOBEN_MPM_performance_boost_natural_block set model=__model; + + +perform fw_core.fn_jobctl_block_end(__file_syspk,'PTOBEN_MPM_performance_boost_natural_block'); + err_context := ''; +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_PTO_MPM_block', err_state, err_msg, err_detail, err_hint, err_context,'success'); +return err_context; + +EXCEPTION when OTHERS then + +GET STACKED DIAGNOSTICS + err_state = returned_sqlstate, + err_msg = message_text, + err_detail = pg_exception_detail, + err_hint = pg_exception_hint, + err_context = pg_exception_context; + + perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,err_block,'stg2', 'fn_PTO_MPM_block', err_state, err_msg, err_detail, err_hint, err_context,'error'); +return err_context; +end +$$ LANGUAGE plpgsql; diff --git a/onetime/dataloadfunctions/PTO/PTO_PRF_ods.sql b/onetime/dataloadfunctions/PTO/PTO_PRF_ods.sql new file mode 100755 index 0000000..7f9dfe8 --- /dev/null +++ b/onetime/dataloadfunctions/PTO/PTO_PRF_ods.sql @@ -0,0 +1,691 @@ +drop function if exists staging2.fn_PTO_PRF_TRX; +CREATE OR REPLACE FUNCTION staging2.fn_PTO_PRF_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS text AS $$ + declare __test_instance_id int; + declare __test_instance_tractor_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + begin + +/*********************************************************** +Function Name:fn_PTO_PNA_TRX +Function Desc: This function populates data into ODS blocks +File Format: PTOBST +Sheet Format: PTOBST_PNA +Creation Date: April 27 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_PTO_PRF_TRX(907) +***************************************************************/ + + +SET search_path TO staging2; +select syspk from transactional.test_master into __test_master_id where test_type ='PTO'; + + +insert into transactional.test_instance +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +tractor_sr_no, +test_standard_ref +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make, +model, +tractor_serial_number, +test_standard +from staging2.ptoben_prf_tractor_specs_block where trx_record=1; + +insert into transactional.test_instance_tractor_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +tractor_sr_no +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make, +model, +tractor_serial_number +from staging2.ptoben_prf_tractor_specs_block where trx_record=1; + +update transactional.test_instance a +set (test_location_name,test_engineer,date_of_test) = (select place,test_engineer,TO_DATE(test_date, 'DD/MM/YYYY') from staging2.PTOBEN_PRF_Key_Performance_Parameters_block where file_syspk = __file_syspk and test_condition='observed') +where file_syspk = __file_syspk; + +update transactional.test_instance +set test_file_name =(select a.file_name from staging1.staging_generic_table a where file_syspk = __file_syspk limit 1) +where file_syspk = __file_syspk; + +update transactional.test_instance_tractor_info a +set (gear_ratio) = (select engine_to_pto_ratio::numeric from staging2.PTOBEN_PRF_Key_Performance_Parameters_block where file_syspk = __file_syspk and test_condition='observed') +where file_syspk = __file_syspk; + + +insert into transactional.PTO_Key_Perf_Parameters +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_model, +tractor_make, +tractor_serial_number, +tractor_emission, +test_standard, +pto_gear_ratio, +specific_gravity_of_fuel_kg_per_m3, +pto_power_declared_hp, +pto_power_declared_kw, +pto_sfc_declared_gm_per_hp_hr, +pto_sfc_declared_kg_per_kw_hr, +pct_of_backup_torque_declared, +max_equ_crankshaft_torque_declared_nm, +equ_crankshaft_torque_at_max_power_declared_nm, +engine_speed_at_max_equ_crankshaft_torque_declared_rpm, +rated_engine_speed_declared_rpm, +max_torque_engine_speed_declared_rpm, +engine_high_idle_speed_declared_rpm, +engine_low_idle_speed_declared_rpm, +engine_oil_temp_at_na_declared_c, +coolant_temp_at_na_declared_c, +engine_oil_temp_at_ha_declared_c, +coolant_temp_at_ha_declared_c, +ambient_pressure_declared_bar, +ambient_pressure_declared_mm_of_hg, +back_pressure_declared_bar, +back_pressure_declared_mm_of_hg, +engine_oil_pressure_declared_bar, +exhaust_temp_declared_c, +relative_humidity_declared_pct, +coolant_water_pct_of_total_coolant_capacity_declared, +test_engineer,test_bed,location_name,total_run_hrs,test_date,tooled_up, +created_by +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +model, +make, +tractor_serial_number, +tractor_emmission, +test_standard, +engine_to_pto_ratio::numeric, +specific_gravity_of_fuel::numeric, +pto_power_hp, +pto_power_kw, +pto_sfc_gm_hp, +pto_sfc_kw_hp, +pct_of_backup_torque, +maximum_equ_crankshaft_torque_nm, +equ_crankshaft_torque_maximum_power_nm, +engine_speed_at_maximum_equivalent_crankshaft_torque_rpm, +rated_engine_speed, +max_torque_engine_speed, +engine_high_idle_speed, +engine_low_idle_speed, +engine_oil_temp_na, +coolant_temp_na, +engine_oil_temp_ha, +coolant_temp_ha, +ambient_pressure_bar, +ambient_pressure_mm_of_hg, +back_pressure_bar, +back_pressure_mm_of_hg, +engine_oil_pressure_bar, +exhaust_temperature_c, +relative_humidity_pct, +coolant_water_pct, +test_engineer,test_bed,place,total_run_hrs::int, +TO_DATE(test_date, 'DD/MM/YYYY') , +tooled_up, +'Compegence' +from staging2.ptoben_prf_key_performance_parameters_block +where trx_record=1 and test_condition ='declared'; + + +update transactional.PTO_Key_Perf_Parameters a +set (pto_power_observed_hp,pto_power_observed_kw,pto_sfc_observed_gm_per_hp_hr,pto_sfc_observed_kg_per_kw_hr, +pct_of_backup_torque_observed,max_equ_crankshaft_torque_observed_nm,equ_crankshaft_torque_at_max_power_observed_nm, +engine_speed_at_max_equ_crankshaft_torque_observed_rpm,rated_engine_speed_observed_rpm +,max_torque_engine_speed_observed_rpm,engine_high_idle_speed_observed_rpm,engine_low_idle_speed_observed_rpm, +engine_oil_temp_at_na_observed_c,coolant_temp_at_na_observed_c,engine_oil_temp_at_ha_observed_c,coolant_temp_at_ha_observed_c, +ambient_pressure_observed_bar,ambient_pressure_observed_mm_of_hg,back_pressure_observed_bar,back_pressure_observed_mm_of_hg, +engine_oil_pressure_observed_bar,exhaust_temp_observed_c,relative_humidity_observed_pct,coolant_water_pct_of_total_coolant_capacity_observed) += (select pto_power_hp::numeric, +pto_power_kw::numeric, +pto_sfc_gm_hp::numeric, +pto_sfc_kw_hp::numeric, +pct_of_backup_torque::numeric, +maximum_equ_crankshaft_torque_nm::numeric, +equ_crankshaft_torque_maximum_power_nm::numeric, +engine_speed_at_maximum_equivalent_crankshaft_torque_rpm::numeric, +rated_engine_speed::numeric, +max_torque_engine_speed::numeric, +engine_high_idle_speed::numeric, +engine_low_idle_speed::numeric, +engine_oil_temp_na::numeric, +coolant_temp_na::numeric, +engine_oil_temp_ha::numeric, +coolant_temp_ha::numeric, +ambient_pressure_bar::numeric, +ambient_pressure_mm_of_hg::numeric, +back_pressure_bar::numeric, +back_pressure_mm_of_hg::numeric, +engine_oil_pressure_bar::numeric, +exhaust_temperature_c::numeric, +relative_humidity_pct::numeric, +coolant_water_pct::numeric from staging2.PTOBEN_PRF_Key_Performance_Parameters_block where test_condition='observed') where file_syspk = __file_syspk; + +update transactional.PTO_Key_Perf_Parameters set test_mode = 'Normal' where file_sheet_mnemonic = 'PTOBEN_PRFN' and file_syspk = __file_syspk; +update transactional.PTO_Key_Perf_Parameters set test_mode = 'Boost' where file_sheet_mnemonic = 'PTOBEN_PRFB' and file_syspk = __file_syspk; +update transactional.PTO_Key_Perf_Parameters set test_mode = 'Eco' where file_sheet_mnemonic = 'PTOBEN_PRFE' and file_syspk = __file_syspk; +update transactional.PTO_Key_Perf_Parameters set test_mode = 'Standard' where file_sheet_mnemonic = 'PTOSTD_PRF' and file_syspk = __file_syspk; + + +/* block */ +insert into transactional.PTO_Perf_Results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_model, +tractor_make, +pto_test_type, +serial_number, +speed_engine_rpm, +speed_pto_rpm, +brake_torque_n_m, +brake_torque_kg_m, +power_kw, +power_hp, +eq_cblock_row_number_torque_nm, +fuel_consumption_kg_per_hr, +fuel_consumption_gm_per_hp_hr, +fuel_consumption_kg_per_kwh, +fuel_consumption_ltr_per_hr, +fuel_consumption_mm3_per_str_per_cyl, +sp_energy_kwh_per_ltr, +temperatures_fuel_c, +temperatures_ambient_c, +temperatures_air_intake_c, +temperatures_water_outlet_c, +temperatures_exhaust_c, +temperatures_engine_oil_c, +pressure_ambient_bar, +pressure_ambient_mm_of_hg, +pressure_exhaust_bar, +pressure_exhaust_mm_of_hg, +pressure_lub_oil_bar, +pressure_lub_oil_mm_of_hg, +rh_pct +) + +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +model, +make, +test_condition, +c2, +c3::numeric,c4::numeric,c5::numeric,c6::numeric,c7::numeric,c8::numeric,c9::numeric,c10::numeric, +c11::numeric, +c12::numeric,c13::numeric,c14::numeric,c15::numeric,c16::numeric,c17::numeric,c18::numeric, +c19::numeric,c20::numeric,c21::numeric,c22::numeric,c23::numeric,c24::numeric,c25::numeric, +c26::numeric,c27::numeric,c28::numeric + from staging2.ptoben_prf_varying_speed_natural_ambient_block +where trx_record=1; + +/* block */ +insert into transactional.PTO_Perf_Results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_model, +tractor_make, +pto_test_type, +serial_number, +speed_engine_rpm, +speed_pto_rpm, +brake_torque_n_m, +brake_torque_kg_m, +power_kw, +power_hp, +eq_cblock_row_number_torque_nm, +fuel_consumption_kg_per_hr, +fuel_consumption_gm_per_hp_hr, +fuel_consumption_kg_per_kwh, +fuel_consumption_ltr_per_hr, +fuel_consumption_mm3_per_str_per_cyl, +sp_energy_kwh_per_ltr, +temperatures_fuel_c, +temperatures_ambient_c, +temperatures_air_intake_c, +temperatures_water_outlet_c, +temperatures_exhaust_c, +temperatures_engine_oil_c, +pressure_ambient_bar, +pressure_ambient_mm_of_hg, +pressure_exhaust_bar, +pressure_exhaust_mm_of_hg, +pressure_lub_oil_bar, +pressure_lub_oil_mm_of_hg, +rh_pct +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +model, +make, +test_condition, +c2, +c3::numeric,c4::numeric,c5::numeric,c6::numeric,c7::numeric,c8::numeric,c9::numeric,c10::numeric, +c11::numeric, +c12::numeric,c13::numeric,c14::numeric,c15::numeric,c16::numeric,c17::numeric,c18::numeric, +c19::numeric,c20::numeric,c21::numeric,c22::numeric,c23::numeric,c24::numeric,c25::numeric, +c26::numeric,c27::numeric,c28::numeric + from staging2.ptoben_prf_2hrs_max_power_natural_ambient_block +where trx_record=1; + +update transactional.PTO_Perf_Results set average_yn = CASE WHEN serial_number = 'Avg' THEN 'Y' + end where + pto_test_type = '2Hrs Max Power Test @ Natural Ambient'; + +/* block */ +insert into transactional.PTO_Perf_Results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_model, +tractor_make, +pto_test_type, +pto_test_sub_type, +serial_number, +speed_engine_rpm, +speed_pto_rpm, +brake_torque_n_m, +brake_torque_kg_m, +power_kw, +power_hp, +eq_cblock_row_number_torque_nm, +fuel_consumption_kg_per_hr, +fuel_consumption_gm_per_hp_hr, +fuel_consumption_kg_per_kwh, +fuel_consumption_ltr_per_hr, +fuel_consumption_mm3_per_str_per_cyl, +sp_energy_kwh_per_ltr, +temperatures_fuel_c, +temperatures_ambient_c, +temperatures_air_intake_c, +temperatures_water_outlet_c, +temperatures_exhaust_c, +temperatures_engine_oil_c, +pressure_ambient_bar, +pressure_ambient_mm_of_hg, +pressure_exhaust_bar, +pressure_exhaust_mm_of_hg, +pressure_lub_oil_bar, +pressure_lub_oil_mm_of_hg, +rh_pct +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +model, +make, +test_condition, +c3, +c2, +c1::numeric,c4::numeric,c5::numeric,c6::numeric,c7::numeric,c8::numeric,c9::numeric,c10::numeric, +c11::numeric, +c12::numeric,c13::numeric,c14::numeric,c15::numeric,c16::numeric,c17::numeric,c18::numeric, +c19::numeric,c20::numeric,c21::numeric,c22::numeric,c23::numeric,c24::numeric,c25::numeric, +c26::numeric,c27::numeric,c28::numeric + from staging2.ptoben_prf_varying_load_rated_rpm_block +where trx_record=1; + +/* block */ +insert into transactional.PTO_Perf_Results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_model, +tractor_make, +pto_test_type, +pto_test_sub_type, +serial_number, +speed_engine_rpm, +speed_pto_rpm, +brake_torque_n_m, +brake_torque_kg_m, +power_kw, +power_hp, +eq_cblock_row_number_torque_nm, +fuel_consumption_kg_per_hr, +fuel_consumption_gm_per_hp_hr, +fuel_consumption_kg_per_kwh, +fuel_consumption_ltr_per_hr, +fuel_consumption_mm3_per_str_per_cyl, +sp_energy_kwh_per_ltr, +temperatures_fuel_c, +temperatures_ambient_c, +temperatures_air_intake_c, +temperatures_water_outlet_c, +temperatures_exhaust_c, +temperatures_engine_oil_c, +pressure_ambient_bar, +pressure_ambient_mm_of_hg, +pressure_exhaust_bar, +pressure_exhaust_mm_of_hg, +pressure_lub_oil_bar, +pressure_lub_oil_mm_of_hg, +rh_pct +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +model, +make, +test_condition, +c3, +c2, +c1::numeric,c4::numeric,c5::numeric,c6::numeric,c7::numeric,c8::numeric,c9::numeric,c10::numeric, +c11::numeric, +c12::numeric,c13::numeric,c14::numeric,c15::numeric,c16::numeric,c17::numeric,c18::numeric, +c19::numeric,c20::numeric,c21::numeric,c22::numeric,c23::numeric,c24::numeric,c25::numeric, +c26::numeric,c27::numeric,c28::numeric + from staging2.ptoben_prf_varying_load_std_pto_block +where trx_record=1; + +/* block */ +insert into transactional.PTO_Perf_Results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_model, +tractor_make, +pto_test_type, +serial_number, +speed_engine_rpm, +speed_pto_rpm, +brake_torque_n_m, +brake_torque_kg_m, +power_kw, +power_hp, +eq_cblock_row_number_torque_nm, +fuel_consumption_kg_per_hr, +fuel_consumption_gm_per_hp_hr, +fuel_consumption_kg_per_kwh, +fuel_consumption_ltr_per_hr, +fuel_consumption_mm3_per_str_per_cyl, +sp_energy_kwh_per_ltr, +temperatures_fuel_c, +temperatures_ambient_c, +temperatures_air_intake_c, +temperatures_water_outlet_c, +temperatures_exhaust_c, +temperatures_engine_oil_c, +pressure_ambient_bar, +pressure_ambient_mm_of_hg, +pressure_exhaust_bar, +pressure_exhaust_mm_of_hg, +pressure_lub_oil_bar, +pressure_lub_oil_mm_of_hg, +rh_pct +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +model, +make, +test_condition, +c2, +c3::numeric,c4::numeric,c5::numeric,c6::numeric,c7::numeric,c8::numeric,c9::numeric,c10::numeric, +c11::numeric, +c12::numeric,c13::numeric,c14::numeric,c15::numeric,c16::numeric,c17::numeric,c18::numeric, +c19::numeric,c20::numeric,c21::numeric,c22::numeric,c23::numeric,c24::numeric,c25::numeric, +c26::numeric,c27::numeric,c28::numeric + from staging2.ptoben_prf_varying_speed_test_high_ambient_block +where trx_record=1; + +insert into transactional.PTO_Perf_Results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_model, +tractor_make, +pto_test_type, +serial_number, +speed_engine_rpm, +speed_pto_rpm, +brake_torque_n_m, +brake_torque_kg_m, +power_kw, +power_hp, +eq_cblock_row_number_torque_nm, +fuel_consumption_kg_per_hr, +fuel_consumption_gm_per_hp_hr, +fuel_consumption_kg_per_kwh, +fuel_consumption_ltr_per_hr, +fuel_consumption_mm3_per_str_per_cyl, +sp_energy_kwh_per_ltr, +temperatures_fuel_c, +temperatures_ambient_c, +temperatures_air_intake_c, +temperatures_water_outlet_c, +temperatures_exhaust_c, +temperatures_engine_oil_c, +pressure_ambient_bar, +pressure_ambient_mm_of_hg, +pressure_exhaust_bar, +pressure_exhaust_mm_of_hg, +pressure_lub_oil_bar, +pressure_lub_oil_mm_of_hg, +rh_pct +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +model, +make, +test_condition, +c2, +c3::numeric,c4::numeric,c5::numeric,c6::numeric,c7::numeric,c8::numeric,c9::numeric,c10::numeric, +c11::numeric, +c12::numeric,c13::numeric,c14::numeric,c15::numeric,c16::numeric,c17::numeric,c18::numeric, +c19::numeric,c20::numeric,c21::numeric,c22::numeric,c23::numeric,c24::numeric,c25::numeric, +c26::numeric,c27::numeric,c28::numeric + from staging2.ptoben_prf_2hrs_max_power_test_high_ambient_block +where trx_record=1; + +update transactional.PTO_Perf_Results set test_mode = 'Normal' where file_sheet_mnemonic = 'PTOBEN_PRFN' and file_syspk = __file_syspk; +update transactional.PTO_Perf_Results set test_mode = 'Boost' where file_sheet_mnemonic = 'PTOBEN_PRFB' and file_syspk = __file_syspk; +update transactional.PTO_Perf_Results set test_mode = 'Eco' where file_sheet_mnemonic = 'PTOBEN_PRFE' and file_syspk = __file_syspk; +update transactional.PTO_Perf_Results set test_mode = 'Standard' where file_sheet_mnemonic = 'PTOSTD_PRF' and file_syspk = __file_syspk; + +update transactional.PTO_Perf_Results set average_yn = CASE WHEN serial_number = 'Avg' THEN 'Y' + end where + pto_test_type = '2Hrs Max Power Test @ High Ambient'; + +/* block */ +insert into transactional.pto_smoke_test +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +srl_no, +engine_speed_rpm, +pto_speed_rpm , +torque_100_pct , +torque_80_pct , +smoke_fsn_100_pct , +smoke_fsn_80_pct +) +select client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make, +model, +c2::numeric,c3::numeric,c4::numeric,c5::numeric,c6::numeric,c7::numeric,c8::numeric +from staging2.ptoben_prf_smoke_test_block ppstb +where trx_record=1 ; + +update transactional.pto_smoke_test set test_mode = 'Normal' where file_sheet_mnemonic = 'PTOBEN_PRFN' and file_syspk = __file_syspk; +update transactional.pto_smoke_test set test_mode = 'Boost' where file_sheet_mnemonic = 'PTOBEN_PRFB' and file_syspk = __file_syspk; +update transactional.pto_smoke_test set test_mode = 'Eco' where file_sheet_mnemonic = 'PTOBEN_PRFE' and file_syspk = __file_syspk; +update transactional.pto_smoke_test set test_mode = 'Standard' where file_sheet_mnemonic = 'PTOSTD_PRF' and file_syspk = __file_syspk; + + +insert into transactional.pto_engine_oil_consumption +( +client_id,function_id,file_syspk,file_mnemonic,file_sheet_mnemonic, +tractor_make, +tractor_model, +srl_no, +oil_consumption_gm_per_hr, +oil_consumption_pct_of_fuel_consumption +) +select client_id,function_id,file_syspk,file_mnemonic,file_sheet_mnemonic,make,model, +c2::numeric,c3::numeric,c5::numeric +from staging2.ptoben_prf_engine_oil_consumption_block ppeocb +where trx_record=1; + +update transactional.pto_engine_oil_consumption set test_mode = 'Normal' where file_sheet_mnemonic = 'PTOBEN_PRFN' and file_syspk = __file_syspk; +update transactional.pto_engine_oil_consumption set test_mode = 'Boost' where file_sheet_mnemonic = 'PTOBEN_PRFB' and file_syspk = __file_syspk; +update transactional.pto_engine_oil_consumption set test_mode = 'Eco' where file_sheet_mnemonic = 'PTOBEN_PRFE' and file_syspk = __file_syspk; +update transactional.pto_engine_oil_consumption set test_mode = 'Standard' where file_sheet_mnemonic = 'PTOSTD_PRF' and file_syspk = __file_syspk; + +update transactional.test_instance set test_mode = 'Normal' where file_sheet_mnemonic = 'PTOBEN_PRFN' and file_syspk = __file_syspk; +update transactional.test_instance set test_mode = 'Boost' where file_sheet_mnemonic = 'PTOBEN_PRFB' and file_syspk = __file_syspk; +update transactional.test_instance set test_mode = 'Eco' where file_sheet_mnemonic = 'PTOBEN_PRFE' and file_syspk = __file_syspk; +update transactional.test_instance set test_mode = 'Standard' where file_sheet_mnemonic = 'PTOSTD_PRF' and file_syspk = __file_syspk; + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk and file_sheet_mnemonic =__file_sheet_mnemonic; +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk and file_sheet_mnemonic =__file_sheet_mnemonic; + +update transactional.test_instance +set test_tractor_id = __test_instance_tractor_id, +test_master_id = __test_master_id +where file_syspk=__file_syspk and file_sheet_mnemonic =__file_sheet_mnemonic; + +update transactional.PTO_Key_Perf_Parameters +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id +where file_syspk=__file_syspk and file_sheet_mnemonic =__file_sheet_mnemonic; + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk and file_sheet_mnemonic =__file_sheet_mnemonic; + +update transactional.PTO_Perf_Results +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.pto_engine_oil_consumption +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.pto_smoke_test +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id +where file_syspk=__file_syspk; + +err_context := ''; +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_PTO_PRF_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); +return err_context; + +EXCEPTION when OTHERS then + +GET STACKED DIAGNOSTICS + err_state = returned_sqlstate, + err_msg = message_text, + err_detail = pg_exception_detail, + err_hint = pg_exception_hint, + err_context = pg_exception_context; + + perform fw_core.fn_insert_db_error (__client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_PTO_PRF_TRX', err_state, err_msg, err_detail, err_hint, err_context,'error'); +return err_context; +end +$$ LANGUAGE plpgsql; + + diff --git a/onetime/dataloadfunctions/PTO/PTO_PRF_stg2.sql b/onetime/dataloadfunctions/PTO/PTO_PRF_stg2.sql new file mode 100755 index 0000000..7b1ad0a --- /dev/null +++ b/onetime/dataloadfunctions/PTO/PTO_PRF_stg2.sql @@ -0,0 +1,1113 @@ +drop function if exists staging2.fn_PTO_PRF_block; +CREATE OR REPLACE FUNCTION staging2.fn_PTO_PRF_block(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS text AS $$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + begin + + /*********************************************************************************** +Function Name:fn_PTOBEN_PRF_block +Function Desc: This function populates data into staging2 blocks +File Format: PTOBEN +Sheet Format: PTOBEN_PRF +Creation Date: April 26 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_PTO_PRF_block(1,1,'PTOBEN','PTOBEN_PRFN',944) +***************************************************************************************/ + + +SET search_path TO staging2; +/* rerunnability - delete block tables and update config tables to null */ +truncate table staging2.stg_specific_table_PTOBEN_PRF; +truncate table staging2.stg_process_table_PTOBEN_PRF; +truncate table staging2.PTOBEN_PRF_tractor_specs_int; +truncate table staging2.PTOBEN_PRF_tractor_specs_block; +truncate table staging2.PTOBEN_PRF_key_performance_parameters_int; +truncate table staging2.PTOBEN_PRF_key_performance_parameters_block; +truncate table staging2.PTOBEN_PRF_varying_speed_natural_ambient_block; +truncate table staging2.PTOBEN_PRF_2hrs_max_power_natural_ambient_block; +truncate table staging2.PTOBEN_PRF_varying_load_rated_rpm_block; +truncate table staging2.PTOBEN_PRF_varying_load_std_pto_block; +truncate table staging2.PTOBEN_PRF_smoke_test_block; +truncate table staging2.PTOBEN_PRF_varying_speed_test_high_ambient_block ; +truncate table staging2.PTOBEN_PRF_2hrs_max_power_test_high_ambient_block ; +truncate table staging2.PTOBEN_PRF_engine_oil_consumption_block ; + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* transfer data from generic to specific for PTOBEN */ +execute 'insert into staging2.stg_specific_table_PTOBEN_PRF +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + + +/* trimming data */ +update staging2.stg_specific_table_PTOBEN_PRF set column3 = TRIM (TRAILING FROM column3 ); +update staging2.stg_specific_table_PTOBEN_PRF set column3 = TRIM (LEADING FROM column3 ); + +update transactional.source_config set F1_source=F1_modified ; + +/* keyword match in config table*/ +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_PTOBEN_PRF b +where trim(upper(F1_modified))=trim(upper(column2)) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/* update config files for row numbers start, end */ +execute 'update staging2.stg_specific_table_PTOBEN_PRF a +set is_rownumber_fetched=1 +from transactional.source_config b +where trim(upper(F1_modified))=trim(upper(column3)) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a +set row_read_end = null ,run_time=current_timestamp +where f1_modified =''Engine Oil Consumption @ High Ambient'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers for each block in process table*/ + +execute 'insert into staging2.stg_process_table_PTOBEN_PRF +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_PTOBEN_PRF a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Key Performance Parameters'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_PTOBEN_PRF +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_PTOBEN_PRF a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Varying Speed Test / Full Throttle Performance @ Natural Ambient'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_PTOBEN_PRF +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_PTOBEN_PRF a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''2Hrs Max Power Test @ Natural Ambient'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_PTOBEN_PRF +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag from staging2.stg_specific_table_PTOBEN_PRF a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Varying loads @ Rated RPM @ Natural Ambient'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_PTOBEN_PRF +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag from staging2.stg_specific_table_PTOBEN_PRF a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Varying load @ STD. PTO @ Natural Ambient'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_PTOBEN_PRF +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_PTOBEN_PRF a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Smoke Test @ Natural Ambient'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_PTOBEN_PRF +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_PTOBEN_PRF a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Varying Speed Test / Full Throttle Performance @ High Ambient'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'insert into staging2.stg_process_table_PTOBEN_PRF +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_PTOBEN_PRF a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''2Hrs Max Power Test @ High Ambient'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + + +execute 'insert into staging2.stg_process_table_PTOBEN_PRF +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_PTOBEN_PRF a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Engine Oil Consumption @ High Ambient'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/* fetcching tractor model and make */ +select column5 into __make from staging2.stg_process_table_PTOBEN_PRF a +where block_tag='PTOBEN_PRF_Key_Performance_Parameters' and block_row_number=7 ; + +select column5 into __model from staging2.stg_process_table_PTOBEN_PRF a +where block_tag='PTOBEN_PRF_Key_Performance_Parameters' and block_row_number=9; + + +/* blocks data loading start - PTOBEN_PRF_key_performance_parameters_int */ + + +insert into staging2.PTOBEN_PRF_tractor_specs_int(c1,c2,block_row_number) +select column2,column5,block_row_number from staging2.stg_process_table_PTOBEN_PRF +where block_tag = 'PTOBEN_PRF_Key_Performance_Parameters' and block_row_number in (3,7,8,9,10); + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'PTOBEN_PRF_tractor_specs_block',__file_mnemonic,__file_sheet_mnemonic,1); +err_block := 'PTOBEN_PRF_tractor_specs_block'; +insert into staging2.PTOBEN_PRF_tractor_specs_block +( +dummy_f, +test_standard, +make, +tractor_emmission, +model, +tractor_serial_number +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{c2}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[c2::text]) AS val + FROM staging2.PTOBEN_PRF_tractor_specs_int + ORDER BY generate_series(1,9),2' + ) t (col text,a1 text,a2 text,a3 text,a4 text,a5 text); + +delete from staging2.PTOBEN_PRF_tractor_specs_block where dummy_f is null ; +execute 'update staging2.PTOBEN_PRF_tractor_specs_block set file_syspk='||p_file_syspk||''; +execute 'update staging2.PTOBEN_PRF_tractor_specs_block set client_id='||p_client_id||''; +execute 'update staging2.PTOBEN_PRF_tractor_specs_block set function_id='||p_function_id||''; +execute 'update staging2.PTOBEN_PRF_tractor_specs_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +execute 'update staging2.PTOBEN_PRF_tractor_specs_block set file_mnemonic='''||p_file_mnemonic||''''; +update staging2.PTOBEN_PRF_tractor_specs_block set make=__make; +update staging2.PTOBEN_PRF_tractor_specs_block set model=__model; +perform fw_core.fn_jobctl_block_end(__file_syspk,'PTOBEN_PRF_tractor_specs_block'); + + + +insert into staging2.PTOBEN_PRF_key_performance_parameters_int +( file_syspk,c1,c2,c3,block_row_number) +select file_syspk,column2,column5,column53,block_row_number from staging2.stg_process_table_PTOBEN_PRF +where block_tag = 'PTOBEN_PRF_Key_Performance_Parameters' and block_row_number not in (1,2,5,7,9) +union +select file_syspk,column8,column10,column11,block_row_number from staging2.stg_process_table_PTOBEN_PRF +where block_tag = 'PTOBEN_PRF_Key_Performance_Parameters' and block_row_number not in (1,2) +union +select file_syspk,column12,column14,column15,block_row_number from staging2.stg_process_table_PTOBEN_PRF +where block_tag = 'PTOBEN_PRF_Key_Performance_Parameters' and block_row_number not in (1,2) +union +select file_syspk,column16,column19,column20,block_row_number from staging2.stg_process_table_PTOBEN_PRF +where block_tag = 'PTOBEN_PRF_Key_Performance_Parameters' and block_row_number not in (1,2) +union +select file_syspk,column21,column25,column53 ,block_row_number from staging2.stg_process_table_PTOBEN_PRF +where block_tag = 'PTOBEN_PRF_Key_Performance_Parameters' and block_row_number not in (1,2,4,6) +order by block_row_number,column2; + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'PTOBEN_PRF_key_performance_parameters_block',__file_mnemonic,__file_sheet_mnemonic,2); +err_block := 'PTOBEN_PRF_key_performance_parameters_block'; +insert into staging2.PTOBEN_PRF_key_performance_parameters_block +( +dummy_f, +Ambient_Pressure_Bar, +PTO_power_hp, +Rated_engine_speed, +Test_Engineer, +test_standard, +Ambient_pressure_mm_of_hg, +max_torque_engine_speed, +Engine_to_PTO_ratio, +PTO_power_Kw, +back_pressure_bar, +Engine_high_Idle_speed, +PTO_SFC_gm_hp, +Test_Bed, +back_pressure_mm_of_hg, +Engine_low_Idle_speed, +PTO_SFC_Kw_hp, +specific_gravity_of_fuel, +pct_of_backup_torque, +Engine_oil_pressure_bar, +Engine_oil_temp_NA, +Place, +Coolant_temp_NA, +exhaust_temperature_C, +Maximum_Equ_crankshaft_Torque_Nm, +Total_run_hrs, +tractor_emmission, +Engine_oil_temp_HA, +Equ_crankshaft_Torque_Maximum_Power_Nm, +Relative_humidity_pct, +Test_date, +Coolant_water_pct, +Coolant_temp_HA, +Engine_speed_at_maximum_equivalent_crankshaft_torque_rpm, +Tooled_up, +tractor_serial_number +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{c2,c3}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[c2::text,c3::text]) AS val + FROM staging2.PTOBEN_PRF_Key_Performance_Parameters_int + ORDER BY generate_series(1,15),2' + ) t (col text,a1 text,a2 text,a3 text,a4 text,a5 text, + a6 text,a7 text,a8 text,a9 text,a10 text,a11 text,a12 text,a13 text,a14 text, + a15 text,a16 text,a17 text,a18 text,a19 text,a20 text,a21 text,a22 text,a23 text,a24 text,a25 text +,a26 text,a27 text,a28 text,a29 text,a30 text,a31 text,a32 text,a33 text, a34 text, a35 text); + + + +delete from staging2.PTOBEN_PRF_Key_Performance_Parameters_block where dummy_f is null; + +update staging2.PTOBEN_PRF_Key_Performance_Parameters_block set trx_record=0 where dummy_f='c1'; + +update staging2.PTOBEN_PRF_Key_Performance_Parameters_block set test_condition='declared' where dummy_f='c2'; +update staging2.PTOBEN_PRF_Key_Performance_Parameters_block set test_condition='observed' where dummy_f='c3'; + + +update staging2.PTOBEN_PRF_Key_Performance_Parameters_block a +set (test_standard,tractor_serial_number,tractor_emmission,engine_to_pto_ratio,specific_gravity_of_fuel,test_engineer,test_bed,place,total_run_hrs,test_date,tooled_up) = (select test_standard,tractor_serial_number,tractor_emmission,engine_to_pto_ratio,specific_gravity_of_fuel,test_engineer,test_bed,place,total_run_hrs,test_date,tooled_up from staging2.PTOBEN_PRF_Key_Performance_Parameters_block where test_condition='declared') +where test_condition='observed'; + + +execute 'update staging2.PTOBEN_PRF_Key_Performance_Parameters_block set file_syspk='||p_file_syspk||''; +execute 'update staging2.PTOBEN_PRF_Key_Performance_Parameters_block set client_id='||p_client_id||''; + execute 'update staging2.PTOBEN_PRF_Key_Performance_Parameters_block set function_id='||p_function_id||''; + execute 'update staging2.PTOBEN_PRF_Key_Performance_Parameters_block set file_mnemonic='''||p_file_mnemonic||''''; + execute 'update staging2.PTOBEN_PRF_Key_Performance_Parameters_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.PTOBEN_PRF_Key_Performance_Parameters_block set file_syspk='||p_file_syspk||''; + + update staging2.PTOBEN_PRF_Key_Performance_Parameters_block set make=__make; + update staging2.PTOBEN_PRF_Key_Performance_Parameters_block set model=__model; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'PTOBEN_PRF_key_performance_parameters_block'); + +/* blocks data loading start - PTOBEN_PRF_varying_speed_natural_ambient_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'PTOBEN_PRF_varying_speed_natural_ambient_block',__file_mnemonic,__file_sheet_mnemonic,3); +err_block := 'PTOBEN_PRF_varying_speed_natural_ambient_block'; +insert into staging2.PTOBEN_PRF_varying_speed_natural_ambient_block +( +c2, +c3, +c4, +c5, +c6, +c7, +c8, +c9, +c10, +c11, +c12, +c13, +c14, +c15, +c16, +c17, +c18, +c19, +c20, +c21, +c22, +c23, +c24, +c25, +c26,c27,c28, +block_row_number +) +select column2, +column3, +column4, +column5, +column6, +column7, +column8, +column9, +column10, +column11, +column12, +column13, +column14, +column15, +column16, +column17, +column18, +column19, +column20, +column21, +column22, +column23, +column24, +column25, +column26, +column27, +column28, +block_row_number +from staging2.stg_process_table_PTOBEN_PRF +where block_tag = 'PTOBEN_PRF_varying_speed_test_natural_ambient'; + +update staging2.PTOBEN_PRF_varying_speed_natural_ambient_block +set test_condition=c2 where block_row_number=1; + +update staging2.PTOBEN_PRF_varying_speed_natural_ambient_block a +set test_condition= b.first_value from (SELECT + block_row_number, test_condition, value_partition, first_value(test_condition) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + test_condition, + sum(case when test_condition is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.PTOBEN_PRF_varying_speed_natural_ambient_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + + +update staging2.PTOBEN_PRF_varying_speed_natural_ambient_block set trx_record=0 where +block_row_number in (1,2,3,4) or c4 is null; + + +execute 'update staging2.PTOBEN_PRF_varying_speed_natural_ambient_block set client_id='||p_client_id||''; +execute 'update staging2.PTOBEN_PRF_varying_speed_natural_ambient_block set function_id='||p_function_id||''; +execute 'update staging2.PTOBEN_PRF_varying_speed_natural_ambient_block set file_mnemonic='''||p_file_mnemonic||''''; +execute 'update staging2.PTOBEN_PRF_varying_speed_natural_ambient_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; +execute 'update staging2.PTOBEN_PRF_varying_speed_natural_ambient_block set file_syspk='||p_file_syspk||''; + +update staging2.PTOBEN_PRF_varying_speed_natural_ambient_block set make=__make; +update staging2.PTOBEN_PRF_varying_speed_natural_ambient_block set model=__model; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'PTOBEN_PRF_varying_speed_natural_ambient_block'); + +/* blocks data loading start - PTOBEN_PRF_2hrs_max_power_natural_ambient_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'PTOBEN_PRF_2hrs_max_power_natural_ambient_block',__file_mnemonic,__file_sheet_mnemonic,4); +err_block := 'PTOBEN_PRF_2hrs_max_power_natural_ambient_block'; + +insert into staging2.PTOBEN_PRF_2hrs_max_power_natural_ambient_block +( +c2, +c3, +c4, +c5, +c6, +c7, +c8, +c9, +c10, +c11, +c12, +c13, +c14, +c15, +c16, +c17, +c18, +c19, +c20, +c21, +c22, +c23, +c24, +c25, +c26,c27,c28, +block_row_number +) +select column2, +column3, +column4, +column5, +column6, +column7, +column8, +column9, +column10, +column11, +column12, +column13, +column14, +column15, +column16, +column17, +column18, +column19, +column20, +column21, +column22, +column23, +column24, +column25, +column26, +column27, +column28, +block_row_number +from staging2.stg_process_table_PTOBEN_PRF +where block_tag = 'PTOBEN_PRF_2hrs_max_power_natural_ambient'; + +update staging2.PTOBEN_PRF_2hrs_max_power_natural_ambient_block +set test_condition=c2 where block_row_number=1; + +update staging2.PTOBEN_PRF_2hrs_max_power_natural_ambient_block a +set test_condition= b.first_value from (SELECT + block_row_number, test_condition, value_partition, first_value(test_condition) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + test_condition, + sum(case when test_condition is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.PTOBEN_PRF_2hrs_max_power_natural_ambient_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + +update staging2.PTOBEN_PRF_2hrs_max_power_natural_ambient_block set trx_record=0 where +block_row_number in (1,2,3,4) or c4 is null; + +update staging2.PTOBEN_PRF_2hrs_max_power_natural_ambient_block set trx_record=0 where (c3 is null or c3::numeric = 0) and c2 = 'Avg'; + + + execute 'update staging2.PTOBEN_PRF_2hrs_max_power_natural_ambient_block set client_id='||p_client_id||''; + execute 'update staging2.PTOBEN_PRF_2hrs_max_power_natural_ambient_block set function_id='||p_function_id||''; + execute 'update staging2.PTOBEN_PRF_2hrs_max_power_natural_ambient_block set file_mnemonic='''||p_file_mnemonic||''''; + execute 'update staging2.PTOBEN_PRF_2hrs_max_power_natural_ambient_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.PTOBEN_PRF_2hrs_max_power_natural_ambient_block set file_syspk='||p_file_syspk||''; + + update staging2.PTOBEN_PRF_2hrs_max_power_natural_ambient_block set make=__make; + update staging2.PTOBEN_PRF_2hrs_max_power_natural_ambient_block set model=__model; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'PTOBEN_PRF_2hrs_max_power_natural_ambient_block'); + +/* blocks data loading start - PTOBEN_PRF_varying_load_rated_rpm_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'PTOBEN_PRF_varying_load_rated_rpm_block',__file_mnemonic,__file_sheet_mnemonic,5); +err_block := 'PTOBEN_PRF_varying_load_rated_rpm_block'; + + insert into staging2.PTOBEN_PRF_varying_load_rated_rpm_block +( +c2, +c3, +c4, +c5, +c6, +c7, +c8, +c9, +c10, +c11, +c12, +c13, +c14, +c15, +c16, +c17, +c18, +c19, +c20, +c21, +c22, +c23, +c24, +c25,c26,c27,c28, +block_row_number +) +select column2, +column3, +column4, +column5, +column6, +column7, +column8, +column9, +column10, +column11, +column12, +column13, +column14, +column15, +column16, +column17, +column18, +column19, +column20, +column21, +column22, +column23, +column24, +column25, +column26, +column27, +column28, +block_row_number +from staging2.stg_process_table_PTOBEN_PRF +where block_tag='PTOBEN_PRF_varying_load_rated_rpm'; + +update staging2.PTOBEN_PRF_varying_load_rated_rpm_block +set c1 =c3 +where c2 is null and trx_record=1; + +update staging2.PTOBEN_PRF_varying_load_rated_rpm_block a +set c1= b.first_value from (SELECT + block_row_number, c1, value_partition, first_value(c1) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + c1, + sum(case when c1 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.PTOBEN_PRF_varying_load_rated_rpm_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + + +update staging2.PTOBEN_PRF_varying_load_rated_rpm_block +set test_condition=c2 where block_row_number=1; + +update staging2.PTOBEN_PRF_varying_load_rated_rpm_block a +set test_condition= b.first_value from (SELECT + block_row_number, test_condition, value_partition, first_value(test_condition) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + test_condition, + sum(case when test_condition is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.PTOBEN_PRF_varying_load_rated_rpm_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + +update staging2.PTOBEN_PRF_varying_load_rated_rpm_block +set c3 = null +where c1=c3; + +update staging2.PTOBEN_PRF_varying_load_rated_rpm_block a +set c3= b.first_value from (SELECT + block_row_number, c3, value_partition, first_value(c3) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + c3, + sum(case when c3 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.PTOBEN_PRF_varying_load_rated_rpm_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + +update staging2.PTOBEN_PRF_varying_load_rated_rpm_block a +set c2= b.first_value from (SELECT + block_row_number, c2, value_partition, first_value(c2) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + c2, + sum(case when c2 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.PTOBEN_PRF_varying_load_rated_rpm_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + +update staging2.PTOBEN_PRF_varying_load_rated_rpm_block +set trx_record = 0 +where c4 is null or block_row_number=3; + + + + execute 'update staging2.PTOBEN_PRF_varying_load_rated_rpm_block set client_id='||p_client_id||''; + execute 'update staging2.PTOBEN_PRF_varying_load_rated_rpm_block set function_id='||p_function_id||''; + execute 'update staging2.PTOBEN_PRF_varying_load_rated_rpm_block set file_mnemonic='''||p_file_mnemonic||''''; + execute 'update staging2.PTOBEN_PRF_varying_load_rated_rpm_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.PTOBEN_PRF_varying_load_rated_rpm_block set file_syspk='||p_file_syspk||''; + + update staging2.PTOBEN_PRF_varying_load_rated_rpm_block set make=__make; + update staging2.PTOBEN_PRF_varying_load_rated_rpm_block set model=__model; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'PTOBEN_PRF_varying_load_rated_rpm_block'); + +/* blocks data loading start - PTOBEN_PRF_varying_load_std_pto_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'PTOBEN_PRF_varying_load_std_pto_block',__file_mnemonic,__file_sheet_mnemonic,6); +err_block := 'PTOBEN_PRF_varying_load_std_pto_block'; + + insert into staging2.PTOBEN_PRF_varying_load_std_pto_block +( +c2, +c3, +c4, +c5, +c6, +c7, +c8, +c9, +c10, +c11, +c12, +c13, +c14, +c15, +c16, +c17, +c18, +c19, +c20, +c21, +c22, +c23, +c24, +c25,c26,c27,c28, +block_row_number +) +select column2, +column3, +column4, +column5, +column6, +column7, +column8, +column9, +column10, +column11, +column12, +column13, +column14, +column15, +column16, +column17, +column18, +column19, +column20, +column21, +column22, +column23, +column24, +column25, +column26, +column27, +column28, +block_row_number +from staging2.stg_process_table_PTOBEN_PRF +where block_tag='PTOBEN_PRF_varying_load_std_pto' ; + +update staging2.PTOBEN_PRF_varying_load_std_pto_block +set c1 =c3 +where c2 is null and trx_record=1; + +update staging2.PTOBEN_PRF_varying_load_std_pto_block a +set c1= b.first_value from (SELECT + block_row_number, c1, value_partition, first_value(c1) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + c1, + sum(case when c1 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.PTOBEN_PRF_varying_load_std_pto_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + +update staging2.PTOBEN_PRF_varying_load_std_pto_block +set test_condition=c2 where block_row_number=1; + +update staging2.PTOBEN_PRF_varying_load_std_pto_block a +set test_condition= b.first_value from (SELECT + block_row_number, test_condition, value_partition, first_value(test_condition) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + test_condition, + sum(case when test_condition is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.PTOBEN_PRF_varying_load_std_pto_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + +update staging2.PTOBEN_PRF_varying_load_std_pto_block +set c3 = null +where c1=c3; + +update staging2.PTOBEN_PRF_varying_load_std_pto_block a +set c3= b.first_value from (SELECT + block_row_number, c3, value_partition, first_value(c3) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + c3, + sum(case when c3 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.PTOBEN_PRF_varying_load_std_pto_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + +update staging2.PTOBEN_PRF_varying_load_std_pto_block a +set c2= b.first_value from (SELECT + block_row_number, c2, value_partition, first_value(c2) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + c2, + sum(case when c2 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.PTOBEN_PRF_varying_load_std_pto_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + +update staging2.PTOBEN_PRF_varying_load_std_pto_block +set trx_record = 0 +where c4 is null or block_row_number=3; + +update staging2.PTOBEN_PRF_varying_load_std_pto_block set trx_record=0 where +block_row_number in (1,2,3,4); + + execute 'update staging2.PTOBEN_PRF_varying_load_std_pto_block set client_id='||p_client_id||''; + execute 'update staging2.PTOBEN_PRF_varying_load_std_pto_block set function_id='||p_function_id||''; + execute 'update staging2.PTOBEN_PRF_varying_load_std_pto_block set file_mnemonic='''||p_file_mnemonic||''''; + execute 'update staging2.PTOBEN_PRF_varying_load_std_pto_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.PTOBEN_PRF_varying_load_std_pto_block set file_syspk='||p_file_syspk||''; + + update staging2.PTOBEN_PRF_varying_load_std_pto_block set make=__make; + update staging2.PTOBEN_PRF_varying_load_std_pto_block set model=__model; + + +perform fw_core.fn_jobctl_block_end(__file_syspk,'PTOBEN_PRF_varying_load_std_pto_block'); + +/* blocks data loading start - PTOBEN_PRF_smoke_test_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'PTOBEN_PRF_smoke_test_block',__file_mnemonic,__file_sheet_mnemonic,7); +err_block := 'PTOBEN_PRF_smoke_test_block'; + + insert into staging2.PTOBEN_PRF_smoke_test_block +( +c2, +c3, +c4, +c5, +c6, +c7, +c8, +block_row_number +) +select +column2, +column3,column4,column5, +column6,column7,column8,block_row_number +from staging2.stg_process_table_PTOBEN_PRF where block_tag='PTOBEN_PRF_smoke_test'; + + +update staging2.PTOBEN_PRF_smoke_test_block +set test_condition=c2 where block_row_number=1; + +update staging2.PTOBEN_PRF_smoke_test_block a +set test_condition= b.first_value from (SELECT + block_row_number, test_condition, value_partition, first_value(test_condition) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + test_condition, + sum(case when test_condition is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.PTOBEN_PRF_smoke_test_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + +update staging2.PTOBEN_PRF_smoke_test_block +set trx_record=0 where block_row_number in (1,2,3) or c4 is null; + + execute 'update staging2.PTOBEN_PRF_smoke_test_block set client_id='||p_client_id||''; + execute 'update staging2.PTOBEN_PRF_smoke_test_block set function_id='||p_function_id||''; + execute 'update staging2.PTOBEN_PRF_smoke_test_block set file_mnemonic='''||p_file_mnemonic||''''; + execute 'update staging2.PTOBEN_PRF_smoke_test_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.PTOBEN_PRF_smoke_test_block set file_syspk='||p_file_syspk||''; + + update staging2.PTOBEN_PRF_smoke_test_block set make=__make; + update staging2.PTOBEN_PRF_smoke_test_block set model=__model; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'PTOBEN_PRF_smoke_test_block'); + +/* blocks data loading start - PTOBEN_PRF_varying_speed_test_high_ambient_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'PTOBEN_PRF_varying_speed_test_high_ambient_block',__file_mnemonic,__file_sheet_mnemonic,8); +err_block := 'PTOBEN_PRF_varying_speed_test_high_ambient_block'; + + insert into staging2.PTOBEN_PRF_varying_speed_test_high_ambient_block +( +c2, +c3, +c4, +c5, +c6, +c7, +c8, +c9, +c10, +c11, +c12, +c13, +c14, +c15, +c16, +c17, +c18, +c19, +c20, +c21, +c22, +c23, +c24, +c25, +c26, +c27, +c28, +block_row_number +) +select column2, +column3, +column4, +column5, +column6, +column7, +column8, +column9, +column10, +column11, +column12, +column13, +column14, +column15, +column16, +column17, +column18, +column19, +column20, +column21, +column22, +column23, +column24, +column25, +column26, +column27, +column28, +block_row_number +from staging2.stg_process_table_PTOBEN_PRF +where block_tag='PTOBEN_PRF_varying_speed_test_high_ambient'; + +update staging2.PTOBEN_PRF_varying_speed_test_high_ambient_block set trx_record=0 where +block_row_number in (1,2,3,4) or c4 is null; + +update staging2.PTOBEN_PRF_varying_speed_test_high_ambient_block +set test_condition=c2 where block_row_number=1; + +update staging2.PTOBEN_PRF_varying_speed_test_high_ambient_block a +set test_condition= b.first_value from (SELECT + block_row_number, test_condition, value_partition, first_value(test_condition) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + test_condition, + sum(case when test_condition is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.PTOBEN_PRF_varying_speed_test_high_ambient_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + + execute 'update staging2.PTOBEN_PRF_varying_speed_test_high_ambient_block set client_id='||p_client_id||''; + execute 'update staging2.PTOBEN_PRF_varying_speed_test_high_ambient_block set function_id='||p_function_id||''; + execute 'update staging2.PTOBEN_PRF_varying_speed_test_high_ambient_block set file_mnemonic='''||p_file_mnemonic||''''; + execute 'update staging2.PTOBEN_PRF_varying_speed_test_high_ambient_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.PTOBEN_PRF_varying_speed_test_high_ambient_block set file_syspk='||p_file_syspk||''; + + update staging2.PTOBEN_PRF_varying_speed_test_high_ambient_block set make=__make; + update staging2.PTOBEN_PRF_varying_speed_test_high_ambient_block set model=__model; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'PTOBEN_PRF_varying_speed_test_high_ambient_block'); + +/* blocks data loading start - PTOBEN_PRF_2hrs_max_power_test_high_ambient_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'PTOBEN_PRF_2hrs_max_power_test_high_ambient_block',__file_mnemonic,__file_sheet_mnemonic,9); +err_block := 'PTOBEN_PRF_2hrs_max_power_test_high_ambient_block'; + + insert into staging2.PTOBEN_PRF_2hrs_max_power_test_high_ambient_block +( +c2, +c3, +c4, +c5, +c6, +c7, +c8, +c9, +c10, +c11, +c12, +c13, +c14, +c15, +c16, +c17, +c18, +c19, +c20, +c21, +c22, +c23, +c24, +c25, +c26, +c27, +c28, +block_row_number +) +select column2, +column3, +column4, +column5, +column6, +column7, +column8, +column9, +column10, +column11, +column12, +column13, +column14, +column15, +column16, +column17, +column18, +column19, +column20, +column21, +column22, +column23, +column24, +column25, +column26, +column27, +column28, +block_row_number +from staging2.stg_process_table_PTOBEN_PRF +where block_tag='PTOBEN_PRF_2hrs_max_power_high_ambient'; + +update staging2.PTOBEN_PRF_2hrs_max_power_test_high_ambient_block set trx_record=0 where +block_row_number in (1,2,3,4) or c4 is null; + +update staging2.PTOBEN_PRF_2hrs_max_power_test_high_ambient_block set trx_record=0 where (c3 is null or c3::numeric <> 0) and c2 = 'Avg'; + +update staging2.PTOBEN_PRF_2hrs_max_power_test_high_ambient_block +set test_condition=c2 where block_row_number=1; + +update staging2.PTOBEN_PRF_2hrs_max_power_test_high_ambient_block a +set test_condition= b.first_value from (SELECT + block_row_number, test_condition, value_partition, first_value(test_condition) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + test_condition, + sum(case when test_condition is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.PTOBEN_PRF_2hrs_max_power_test_high_ambient_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + + execute 'update staging2.PTOBEN_PRF_2hrs_max_power_test_high_ambient_block set client_id='||p_client_id||''; + execute 'update staging2.PTOBEN_PRF_2hrs_max_power_test_high_ambient_block set function_id='||p_function_id||''; + execute 'update staging2.PTOBEN_PRF_2hrs_max_power_test_high_ambient_block set file_mnemonic='''||p_file_mnemonic||''''; + execute 'update staging2.PTOBEN_PRF_2hrs_max_power_test_high_ambient_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.PTOBEN_PRF_2hrs_max_power_test_high_ambient_block set file_syspk='||p_file_syspk||''; + + update staging2.PTOBEN_PRF_2hrs_max_power_test_high_ambient_block set make=__make; + update staging2.PTOBEN_PRF_2hrs_max_power_test_high_ambient_block set model=__model; + + +perform fw_core.fn_jobctl_block_end(__file_syspk,'PTOBEN_PRF_2hrs_max_power_test_high_ambient_block'); + +/* blocks data loading start - PTOBEN_PRF_engine_oil_consumption_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'PTOBEN_PRF_engine_oil_consumption_block',__file_mnemonic,__file_sheet_mnemonic,10); +err_block := 'PTOBEN_PRF_engine_oil_consumption_block'; + + insert into staging2.PTOBEN_PRF_engine_oil_consumption_block +( +c2, +c3,c5, +block_row_number +) +select column2,column3,column5 ,block_row_number from staging2.stg_process_table_PTOBEN_PRF +where block_tag='PTOBEN_PRF_engine_oil_consumption'; + +update staging2.PTOBEN_PRF_engine_oil_consumption_block set trx_record=0 where +block_row_number in (1,2) or c3 is null ; + + execute 'update staging2.PTOBEN_PRF_engine_oil_consumption_block set client_id='||p_client_id||''; + execute 'update staging2.PTOBEN_PRF_engine_oil_consumption_block set function_id='||p_function_id||''; + execute 'update staging2.PTOBEN_PRF_engine_oil_consumption_block set file_mnemonic='''||p_file_mnemonic||''''; + execute 'update staging2.PTOBEN_PRF_engine_oil_consumption_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + execute 'update staging2.PTOBEN_PRF_engine_oil_consumption_block set file_syspk='||p_file_syspk||''; + + update staging2.PTOBEN_PRF_engine_oil_consumption_block set make=__make; + update staging2.PTOBEN_PRF_engine_oil_consumption_block set model=__model; +perform fw_core.fn_jobctl_block_end(__file_syspk,'PTOBEN_PRF_engine_oil_consumption_block'); + + err_context := ''; +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_PTO_PRF_block', err_state, err_msg, err_detail, err_hint, err_context,'success'); +return err_context; + +EXCEPTION when OTHERS then + +GET STACKED DIAGNOSTICS + err_state = returned_sqlstate, + err_msg = message_text, + err_detail = pg_exception_detail, + err_hint = pg_exception_hint, + err_context = pg_exception_context; + + perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_PTO_PRF_block', err_state, err_msg, err_detail, err_hint, err_context,'error'); +return err_context; +end +$$ LANGUAGE plpgsql; diff --git a/onetime/dataloadfunctions/budni/BUDNI_ARC_ODS.sql b/onetime/dataloadfunctions/budni/BUDNI_ARC_ODS.sql new file mode 100755 index 0000000..239f501 --- /dev/null +++ b/onetime/dataloadfunctions/budni/BUDNI_ARC_ODS.sql @@ -0,0 +1,251 @@ +drop function if exists staging2.fn_BUDNI_ARC_TRX; +CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_ARC_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + declare __test_instance_tractor_id int; + begin +__file_syspk := p_file_syspk; +/************************************************************ +Function Name:fn_BUDNI_ARC_TRX +Function Desc: This function populates data into ODS +File Format: BUDNI +Sheet Format: BUDNI_ARC +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_BUDNI_ARC_TRX() +***************************************************************/ +insert into transactional.test_instance_tractor_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +tractor_engine_hp, +configuration, +transmission_type, +wheel_drive_type, +fip_type, +steering_type, +ballast_condition +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make, +model, +tractor_HP::int tractor_engine_hp, +configuration, +transmission_type, +wheel_drive_type, +FIP_type, +steering_type, +Ballast_Condition +from staging2.BUDNI_ARC_Spec_H1_block where trx_record=1; + +update transactional.test_instance_tractor_info +set mahindra_model_yn = ( +case when lower(tractor_make) like 'mahindra%' then 'Y' else 'N' end +) where file_syspk =__file_syspk; + +update transactional.test_instance_tractor_info a +set test_tractor_yn ='Y' where syspk in +(select min(syspk) from transactional.test_instance_tractor_info b +where b.file_syspk =a.file_syspk) +and a.file_syspk =__file_syspk; + +insert into transactional.test_instance +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +type_of_road +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +type_of_track +from + staging2.BUDNI_ARC_Spec_H1_block where trx_record=1; + + insert into transactional.test_instance_engine_info + ( + client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +rated_rpm, +engine_to_pto_ratio_540_pto +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +rated_rpm::int, +engine_to_pto_ratio engine_to_pto_ratio_540_pto +from staging2.BUDNI_ARC_Spec_H1_block where trx_record=1; + + +/*block */ + +insert into transactional.budni_air_cleaner_perf_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +atm_condtion_temperature_c, +atm_condition_pressure_kpa, +atm_condition_relative_humidity_pct, +atm_condtion_mass_of_oil_before_test, +position_of_tractor, +loss_of_oil_g, +oil_pull_over_pct, +engine_oil_pressure +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +Temperature_C, +Pressure_kPa, +Relative_humidity::numeric, +Mass_of_oil_before_test::numeric, +Position_of_tractor, +Loss_of_oil::numeric, +Oil_pull_Over::numeric, +Engine_oil_pressure +from staging2.budni_arc_perf_atmos_meas_test_block where trx_record=1 +order by block_row_number; + + + +insert into transactional.budni_test_observations +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +sequence_number, +characteristic, +category_evaluative_or_non_evaluative, +requirements_as_per_is_12207_2008, +values_declared_by_the_applicant_d_rqmt, +as_observed, +whether_meets_the_requirements_yn +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column3::int, +column4, +column5, +column6, +column7, +column8, +column9 +from staging2.BUDNI_ARC_test_obs_summary_block where trx_record=1; + + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk; +select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk; +select syspk from transactional.test_master into __test_master_id where test_type ='BUDNI'; +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk; + + +update transactional.test_instance +set test_master_id =__test_master_id, +test_tractor_id =__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.test_instance_engine_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.budni_air_cleaner_perf_results +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.budni_test_observations +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_BUDNI_ARC_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + + diff --git a/onetime/dataloadfunctions/budni/BUDNI_ARC_STG2.sql b/onetime/dataloadfunctions/budni/BUDNI_ARC_STG2.sql new file mode 100755 index 0000000..1aa27d9 --- /dev/null +++ b/onetime/dataloadfunctions/budni/BUDNI_ARC_STG2.sql @@ -0,0 +1,282 @@ +drop function if exists staging2.fn_BUDNI_ARC_Block ; +CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_ARC_Block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + + begin + + +/*********************************************************************************** +Function Name:fn_BUDNI_ARC_Block +Function Desc: This function populates data into staging2 blocks +File Format:BUDNI +Sheet Format: BUDNI_ARC +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_FTDRY_SUM_Block (20,1,'BUDNI','BUDNI_ARC',273); +************************************************************************************/ + +SET search_path TO staging2; + +truncate staging2.BUDNI_ARC_Spec_H1_Block; +truncate staging2.BUDNI_ARC_Perf_Atmos_Meas_Test_Block; +truncate staging2.BUDNI_ARC_Test_Obs_Summary_Block; +truncate staging2.stg_specific_table_BUDNI_ARC; +truncate staging2.stg_process_table_BUDNI_ARC; + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* transfer data from generic to specific for BUDNI*/ +execute 'insert into staging2.stg_specific_table_BUDNI_ARC +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_BUDNI_ARC; + +if err_query=0 then +err_context :='data not present'; + raise exception using + message = 'No Data for Budni ARC', + detail = 'No data in table stg_specific_table_BUDNI_ARC', + errcode = '42704', + hint = 'check sheet mnemonic or data exists in generic table, if it is null update it'; +end if; + +update transactional.source_config set F1_source=F1_modified; + + +/* update config files for row numbers start, end */ +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_BUDNI_ARC b +where upper(F1_source)= upper(column3) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update in process table for match*/ +execute 'update staging2.stg_specific_table_BUDNI_ARC a +set is_rownumber_fetched=1 +from transactional.source_config b +where upper(F1_source)= upper(column3) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/* update config files for row numbers start, end */ +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a +set row_read_end = null +where f1_modified =''AIR CLEANER OIL PULL OVER TEST Observations Summary'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/*inserting run_time in config*/ +execute 'update transactional.source_config a +set run_time=current_timestamp +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers for each block in process table*/ +execute 'insert into staging2.stg_process_table_BUDNI_ARC +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_BUDNI_ARC a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Tractor Specifiactions'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + +execute 'insert into staging2.stg_process_table_BUDNI_ARC +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_BUDNI_ARC a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Atmospheric conditions:'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + + +execute 'insert into staging2.stg_process_table_BUDNI_ARC +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_BUDNI_ARC a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''AIR CLEANER OIL PULL OVER TEST Observations Summary'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +/* fetching tractor model and make */ +select column3 into __make from staging2.stg_process_table_BUDNI_ARC a +where block_tag='BUDNI_ARC_Spec_H1' and block_row_number=3; + +select column4 into __model from staging2.stg_process_table_BUDNI_ARC a +where block_tag='BUDNI_ARC_Spec_H1' and block_row_number=3; + + + +/* blocks data loading start - BUDNI_ARC_Spec_H1_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_ARC_Spec_H1_Block',__file_mnemonic,__file_sheet_mnemonic,1); +err_block:='BUDNI_ARC_Spec_H1_Block'; + +insert into staging2.BUDNI_ARC_Spec_H1_block +( +make,model,tractor_HP,rated_rpm,configuration,transmission_type,wheel_drive_type,block_row_number) +select column3,column4,column5,column6,column7,column8,column9,block_row_number +from staging2.stg_process_table_BUDNI_ARC where block_tag='BUDNI_ARC_Spec_H1' +and block_row_number=3; + + +execute 'update staging2.BUDNI_ARC_Spec_H1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +update staging2.BUDNI_ARC_Spec_H1_block a +set FIP_type=column3,steering_type=column4,Engine_to_PTO_ratio= column5,Ballast_Condition=column6, +Test_Engine_Set_RPM=column7,Type_of_track=column8 +from staging2.stg_process_table_BUDNI_ARC b +where b.block_tag='BUDNI_ARC_Spec_H1' +and b.block_row_number=5 +and a.file_syspk=b.file_syspk; + + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_ARC_Spec_H1_Block'); + + + +/* blocks data loading start - BUDNI_ARC_Perf_Atmos_Meas_Test_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_ARC_Perf_Atmos_Meas_Test_Block',__file_mnemonic,__file_sheet_mnemonic,2); + +err_block:='BUDNI_ARC_Perf_Atmos_Meas_Test_Block'; + +insert into staging2.BUDNI_ARC_Perf_Atmos_Meas_Test_Block +( +Position_of_tractor, +Loss_of_oil, +Oil_pull_Over, +Engine_oil_pressure, +block_row_number +) +select +column3,column6,column7,column8,block_row_number +from staging2.stg_process_table_BUDNI_ARC a +where block_tag ='BUDNI_ARC_Perf_Atmos_Meas_Test' and block_row_number in (5,6,7,8,9) +order by block_row_number; + + + +update staging2.BUDNI_ARC_Perf_Atmos_Meas_Test_Block set make=__make,model=__model; +execute 'update staging2.BUDNI_ARC_Perf_Atmos_Meas_Test_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +update staging2.BUDNI_ARC_Perf_Atmos_Meas_Test_Block a +set +Temperature_C=column3, +Pressure_kPa=column4 , +Relative_humidity=column5, +Mass_of_oil_before_test=column6 +from staging2.stg_process_table_BUDNI_ARC b +where b.block_tag ='BUDNI_ARC_Perf_Atmos_Meas_Test' +and b.block_row_number =3 +and a.file_syspk=b.file_syspk; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_ARC_Perf_Atmos_Meas_Test_Block'); + + + +/* blocks data loading start - BUDNI_ARC_Test_Obs_Summary_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_ARC_Test_Obs_Summary_Block',__file_mnemonic,__file_sheet_mnemonic,3); + +err_block:='BUDNI_ARC_Test_Obs_Summary_Block'; + +insert into staging2.BUDNI_ARC_Test_Obs_Summary_Block +( +column3,column4,column5,column6,column7, +column8,column9,block_row_number +) +select +column3,column4,column5,column6,column7, +column8,column9,block_row_number +from staging2.stg_process_table_BUDNI_ARC a +where block_tag='BUDNI_ARC_Test_Obs_Summary' and block_row_number in (1,2,3) +order by block_row_number; + + +update staging2.BUDNI_ARC_Test_Obs_Summary_Block +set trx_record=0 where +block_row_number in(1,2); + + +update staging2.BUDNI_ARC_Test_Obs_Summary_Block set make=__make,model=__model; +execute 'update staging2.BUDNI_ARC_Test_Obs_Summary_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_ARC_Test_Obs_Summary_Block'); + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_BUDNI_ARC_Block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + + diff --git a/onetime/dataloadfunctions/budni/BUDNI_BRK_ODS.sql b/onetime/dataloadfunctions/budni/BUDNI_BRK_ODS.sql new file mode 100755 index 0000000..20d287f --- /dev/null +++ b/onetime/dataloadfunctions/budni/BUDNI_BRK_ODS.sql @@ -0,0 +1,505 @@ +drop function if exists staging2.fn_BUDNI_BRK_TRX; +CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_BRK_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + declare __test_instance_tractor_id int; + begin +__file_syspk := p_file_syspk; + +/************************************************************ +Function Name:fn_BUDNI_BRK_TRX +Function Desc: This function populates data into ODS +File Format: BUDNI +Sheet Format: BUDNI_BRK +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_BUDNI_BRK_TRX() +***************************************************************/ + + +insert into transactional.test_instance_tractor_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +tractor_engine_hp, +brake_type, +brake_free_play_lh, +brake_free_play_rh, +unballasted_max_speed_kmph, +road_ballasted_max_speed_kmph +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make, +model, +tractor_HP::numeric tractor_engine_hp, +Type_of_brake, +brake_free_play_lh::numeric , +brake_free_play_rh::numeric , +maximum_attainable_speed_kmph_unballasted::numeric , +maximum_attainable_speed_kmph_ballasted::numeric +from staging2.BUDNI_BRK_Spec_H1_block where trx_record =1; + + +update transactional.test_instance_tractor_info +set mahindra_model_yn = ( +case when tractor_make like 'Mahindra%' then 'Y' else 'N' end +) where file_syspk =__file_syspk; + +update transactional.test_instance_tractor_info a +set test_tractor_yn ='Y' where syspk in +(select min(syspk) from transactional.test_instance_tractor_info b +where b.file_syspk =a.file_syspk) +and a.file_syspk =__file_syspk; + + +insert into transactional.test_instance +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +type_of_road +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +type_of_track +from + staging2.BUDNI_BRK_Spec_H1_block where trx_record =1; + + insert into transactional.test_instance_engine_info + ( + client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +rated_rpm +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +rated_rpm::int +from staging2.BUDNI_BRK_Spec_H1_block where trx_record =1; + + +/*block */ + +insert into transactional.budni_brake_perf_service_brake_test_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +brake_test_type, +brake_test_name, +speed_condition, +ballast_condition, +braking_device_control_force_n, +mean_deceleration_msec2, +stopping_dist_m +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +brake_test_type, +brake_test_name, +speed_condition, +ballast_condition, +Braking_device_control_force_N::numeric , +Mean_deceleration_m_sec2::numeric , +Stopping_distance_m ::numeric +from staging2.budni_brk_service_cold_ballasted_25kmph_block where trx_record =1; + +insert into transactional.budni_brake_perf_service_brake_test_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +brake_test_type, +brake_test_name, +speed_condition, +ballast_condition, +braking_device_control_force_n, +mean_deceleration_msec2, +stopping_dist_m +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +brake_test_type, +brake_test_name, +speed_condition, +ballast_condition, +Braking_device_control_force_N::numeric , +Mean_deceleration_m_sec2::numeric , +Stopping_distance_m ::numeric +from staging2.budni_brk_service_cold_ballasted_maximum_block where trx_record =1; + +insert into transactional.budni_brake_perf_service_brake_test_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +brake_test_type, +brake_test_name, +speed_condition, +ballast_condition, +braking_device_control_force_n, +mean_deceleration_msec2, +stopping_dist_m +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +brake_test_type, +brake_test_name, +speed_condition, +ballast_condition, +Braking_device_control_force_N::numeric , +Mean_deceleration_m_sec2::numeric , +Stopping_distance_m ::numeric +from staging2.budni_brk_service_cold_standard_25kmph_block where trx_record =1; + +insert into transactional.budni_brake_perf_service_brake_test_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +brake_test_type, +brake_test_name, +speed_condition, +ballast_condition, +braking_device_control_force_n, +mean_deceleration_msec2, +stopping_dist_m +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +brake_test_type, +brake_test_name, +speed_condition, +ballast_condition, +Braking_device_control_force_N::numeric , +Mean_deceleration_m_sec2::numeric , +Stopping_distance_m ::numeric +from staging2.budni_brk_service_cold_standard_maximum_block where trx_record =1; + + +insert into transactional.budni_brake_perf_service_brake_test_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +brake_test_type, +brake_test_name, +speed_condition, +ballast_condition, +braking_device_control_force_n, +mean_deceleration_msec2, +stopping_dist_m +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +brake_test_type, +brake_test_name, +speed_condition, +ballast_condition, +Braking_device_control_force_N::numeric , +Mean_deceleration_m_sec2::numeric , +Stopping_distance_m ::numeric +from staging2.budni_brk_service_fade_standard_maximum_block where trx_record =1; + +insert into transactional.budni_brake_perf_service_brake_test_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +brake_test_type, +brake_test_name, +speed_condition, +ballast_condition, +braking_device_control_force_n, +mean_deceleration_msec2, +stopping_dist_m +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +brake_test_type, +brake_test_name, +speed_condition, +ballast_condition, +Braking_device_control_force_N::numeric , +Mean_deceleration_m_sec2::numeric , +Stopping_distance_m ::numeric +from staging2.budni_brk_service_fade_ballasted_25kmph_block; + + + +update transactional.budni_brake_perf_service_brake_test_results +set max_dev_of_tractor_from_its_org_course_m =column3, +abnormal_vibration=column5, +the_brakes_were_heated_by =column7 +from staging2.budni_brk_other_observations_Block where trx_record =1; + +insert into transactional.budni_brake_perf_parking_brake_test_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make, +model, +particulars +from staging2.budni_brk_parking_barke_test_block where trx_record =1; + +update transactional.budni_brake_perf_parking_brake_test_results a +set braking_device_control_force_n_facing_up = ( +select Braking_device_control_force::numeric +from staging2.budni_brk_parking_barke_test_block b +where facing='Facing up' and particulars='18 percent slope' and a.file_syspk=__file_syspk) +where test_condition='18 percent slope' and a.file_syspk =__file_syspk; + +update transactional.budni_brake_perf_parking_brake_test_results a +set braking_device_control_force_n_facing_down = ( +select Braking_device_control_force::numeric +from staging2.budni_brk_parking_barke_test_block b +where facing='Facing Down' and particulars='18 percent slope' and a.file_syspk=__file_syspk) +where test_condition='18 percent slope' and a.file_syspk =__file_syspk ; + +update transactional.budni_brake_perf_parking_brake_test_results a +set efficacy_of_parking_brake_facing_down = ( +select Efficacy_of_parking_brake +from staging2.budni_brk_parking_barke_test_block b +where facing='Facing Down' and particulars='18 percent slope' and a.file_syspk=__file_syspk) +where test_condition='18 percent slope' and a.file_syspk =__file_syspk; + +update transactional.budni_brake_perf_parking_brake_test_results a +set efficacy_of_parking_brake_facing_up = ( +select Efficacy_of_parking_brake +from staging2.budni_brk_parking_barke_test_block b +where facing='Facing up' and particulars='18 percent slope' and a.file_syspk=__file_syspk) +where test_condition='18 percent slope' and a.file_syspk =__file_syspk; + +update transactional.budni_brake_perf_parking_brake_test_results a +set braking_device_control_force_n_facing_up = ( +select Braking_device_control_force::numeric +from staging2.budni_brk_parking_barke_test_block b +where facing='Facing up' and particulars='12 percent slope with trailer of 2.55 tonnes.' and a.file_syspk=__file_syspk) +where test_condition='12 percent slope with trailer of 2.55 tonnes.' and a.file_syspk =__file_syspk; + +update transactional.budni_brake_perf_parking_brake_test_results a +set braking_device_control_force_n_facing_down = ( +select Braking_device_control_force::numeric +from staging2.budni_brk_parking_barke_test_block b +where facing='Facing Down' and particulars='12 percent slope with trailer of 2.55 tonnes.' and a.file_syspk=__file_syspk) +where test_condition='12 percent slope with trailer of 2.55 tonnes.' and a.file_syspk =__file_syspk; + +update transactional.budni_brake_perf_parking_brake_test_results a +set efficacy_of_parking_brake_facing_down = ( +select Efficacy_of_parking_brake +from staging2.budni_brk_parking_barke_test_block b +where facing='Facing Down' and particulars='12 percent slope with trailer of 2.55 tonnes.' and a.file_syspk=__file_syspk) +where test_condition='12 percent slope with trailer of 2.55 tonnes.' and a.file_syspk =__file_syspk ; + +update transactional.budni_brake_perf_parking_brake_test_results a +set efficacy_of_parking_brake_facing_up = ( +select Efficacy_of_parking_brake +from staging2.budni_brk_parking_barke_test_block +where facing='Facing up' and particulars='12 percent slope with trailer of 2.55 tonnes.' and a.file_syspk=__file_syspk) +where test_condition='12 percent slope with trailer of 2.55 tonnes.' and a.file_syspk =__file_syspk; + +delete from transactional.budni_brake_perf_parking_brake_test_results a +using transactional.budni_brake_perf_parking_brake_test_results b +where a.syspk < b.syspk and a.test_condition =b.test_condition and a.file_syspk =b.file_syspk; + + +insert into transactional.budni_test_observations +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +characteristic, +category_evaluative_or_non_evaluative, +requirements_as_per_is_12207_2008, +values_declared_by_the_applicant_d_rqmt, +as_observed, +whether_meets_the_requirements_yn +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column3, +column4, +column5, +column6, +column7, +column8 +from staging2.BUDNI_BRK_test_obs_summary_block where trx_record=1; + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk; +select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk; +select syspk from transactional.test_master into __test_master_id where test_type ='BUDNI'; +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk; + +update transactional.test_instance +set test_master_id =__test_master_id, +test_tractor_id =__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.test_instance_engine_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.budni_brake_perf_parking_brake_test_results +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.budni_brake_perf_service_brake_test_results +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.budni_test_observations +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_BUDNI_BRK_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + diff --git a/onetime/dataloadfunctions/budni/BUDNI_BRK_STG2.sql b/onetime/dataloadfunctions/budni/BUDNI_BRK_STG2.sql new file mode 100755 index 0000000..c909c41 --- /dev/null +++ b/onetime/dataloadfunctions/budni/BUDNI_BRK_STG2.sql @@ -0,0 +1,715 @@ +drop function if exists staging2.fn_BUDNI_BRK_Block; +CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_BRK_Block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + DECLARE __characteristic_1 text; + + begin + + +/*********************************************************************************** +Function Name:fn_BUDNI_BRK_Block +Function Desc: This function populates data into staging2 blocks +File Format: BUDNI +Sheet Format: BUDNI_BRK +Creation Date: March 21 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_BUDNI_BRK_Block(20,1,'BUDNI','BUDNI_BRK',273); +************************************************************************************/ + +SET search_path TO staging2; + +truncate table staging2.BUDNI_BRK_Spec_H1_Block; +truncate table staging2.BUDNI_BRK_Service_Barke_Test_Int; +truncate table staging2.budni_brk_service_cold_ballasted_maximum_block; +truncate table staging2.budni_brk_service_cold_standard_25kmph_block; +truncate table staging2.budni_brk_service_cold_standard_maximum_block; +truncate table staging2.BUDNI_BRK_service_cold_ballasted_25kmph_Block; +truncate table staging2.BUDNI_BRK_service_fade_standard_maximum_Block; +truncate table staging2.BUDNI_BRK_service_fade_ballasted_25kmph_Block; +truncate table staging2.BUDNI_BRK_other_observations_Block; +truncate table staging2.BUDNI_BRK_Parking_Barke_Test_Int; +truncate table staging2.BUDNI_BRK_Parking_Barke_Test_Block; +truncate table staging2.BUDNI_BRK_Test_Obs_Summary_Block; +truncate table staging2.stg_specific_table_BUDNI_BRK; +truncate table staging2.stg_process_table_BUDNI_BRK; + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* transfer data from generic to specific for BUDNI*/ +execute 'insert into staging2.stg_specific_table_BUDNI_BRK +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_BUDNI_BRK; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for Budni BRK', + detail = 'No data in table stg_specific_table_BUDNI_BRK', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + +update transactional.source_config set F1_source=F1_modified; + + +/* keyword match in config table*/ +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_BUDNI_BRK b +where upper(F1_source)= upper(column3) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update in process table for match*/ +execute 'update staging2.stg_specific_table_BUDNI_BRK a +set is_rownumber_fetched=1 +from transactional.source_config b +where upper(F1_source)=upper(column3) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* update config files for row numbers start, end */ +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a +set row_read_end = null +where f1_modified =''Brake Performance Test Observations Summary'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/*inserting run_time in config*/ +execute 'update transactional.source_config a +set run_time=current_timestamp +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers for each block in process table*/ +execute 'insert into staging2.stg_process_table_BUDNI_BRK +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_BUDNI_BRK a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Tractor Specifiactions'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + +execute 'insert into staging2.stg_process_table_BUDNI_BRK +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_BUDNI_BRK a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''1) Service Barke Testing'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +execute 'insert into staging2.stg_process_table_BUDNI_BRK +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_BUDNI_BRK a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''2) Parking Brake Test'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + +execute 'insert into staging2.stg_process_table_BUDNI_BRK +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_BUDNI_BRK a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Brake Performance Test Observations Summary'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +/* fetching tractor model and make */ +select column3 into __make from staging2.stg_process_table_BUDNI_BRK a +where block_tag='BUDNI_BRK_Spec_H1' and block_row_number=3; + +select column4 into __model from staging2.stg_process_table_BUDNI_BRK a +where block_tag='BUDNI_BRK_Spec_H1' and block_row_number=3; + + +/* blocks data loading start - BUDNI_BRK_Spec_H1_Block */ + +perform trx.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_BRK_Spec_H1_Block',__file_mnemonic,__file_sheet_mnemonic,1); +err_block:='BUDNI_BRK_Spec_H1_Block'; + +insert into staging2.BUDNI_BRK_Spec_H1_block +( +make,model,tractor_HP,rated_rpm,Type_of_brake , +Type_of_track,block_row_number) +select column3,column4,column5,column6,column7,column8,block_row_number +from staging2.stg_process_table_BUDNI_BRK where block_tag='BUDNI_BRK_Spec_H1' +and block_row_number=3; + + +execute 'update staging2.BUDNI_BRK_Spec_H1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +update staging2.BUDNI_BRK_Spec_H1_block a +set brake_free_play_lh=column3,brake_free_play_rh=column4, +maximum_attainable_speed_kmph_unballasted=column5, +maximum_attainable_speed_kmph_ballasted=column6 +from staging2.stg_process_table_BUDNI_BRK b +where b.block_tag='BUDNI_BRK_Spec_H1' +and b.block_row_number=6 +and a.file_syspk=b.file_syspk; + +perform trx.fn_jobctl_block_end(__file_syspk,'BUDNI_BRK_Spec_H1_block'); + +insert into staging2.BUDNI_BRK_Service_Barke_Test_Int +( +column3, +column4, +column5, +column6, +column7, +column8, +column9, +block_row_number +) +select +column3,column4,column5,column6,column7,column8,column9,block_row_number +from staging2.stg_process_table_BUDNI_BRK a +where block_tag ='BUDNI_BRK_Service_Barke_Test' +order by block_row_number; + +update staging2.BUDNI_BRK_Service_Barke_Test_Int +set column2=(select column3 from staging2.BUDNI_BRK_Service_Barke_Test_Int +where block_row_number=1) where block_row_number=3; + +update staging2.BUDNI_BRK_Service_Barke_Test_Int +set column3=(select column3 from staging2.BUDNI_BRK_Service_Barke_Test_Int +where block_row_number=2) where block_row_number=3; + +update staging2.BUDNI_BRK_Service_Barke_Test_Int +set column3=(select column3 from staging2.BUDNI_BRK_Service_Barke_Test_Int +where block_row_number=3)where block_row_number=10; + +update staging2.BUDNI_BRK_Service_Barke_Test_Int +set column5=(select column5 from staging2.BUDNI_BRK_Service_Barke_Test_Int +where block_row_number=18)where block_row_number=17; + +update staging2.BUDNI_BRK_Service_Barke_Test_Int +set column3=(select column3 from staging2.BUDNI_BRK_Service_Barke_Test_Int +where block_row_number=17)where block_row_number=22; + +update staging2.BUDNI_BRK_Service_Barke_Test_Int +set column3=null where block_row_number =1; + +update staging2.BUDNI_BRK_Service_Barke_Test_Int +set column3=null where block_row_number =2; + +update staging2.BUDNI_BRK_Service_Barke_Test_Int + set column5 =null where block_row_number=18; + + +update staging2.BUDNI_BRK_Service_Barke_Test_Int a +set column2= b.first_value from (SELECT + block_row_number, column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + column2, + sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.BUDNI_BRK_Service_Barke_Test_Int + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + +update staging2.budni_brk_service_barke_test_int set make=__make,model=__model; +execute 'update staging2.BUDNI_BRK_Service_Barke_Test_int set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/* blocks data loading start - BUDNI_BRK_service_cold_standard_maximum_Block */ + +perform trx.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_BRK_service_cold_standard_maximum_Block',__file_mnemonic,__file_sheet_mnemonic,2); +err_block:='BUDNI_BRK_service_cold_standard_maximum_Block'; + +insert into staging2.BUDNI_BRK_service_cold_standard_maximum_Block +( +dummy_f, +Braking_device_control_force_N, +Mean_deceleration_m_sec2, +Stopping_distance_m +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column5,column6,column7,column8}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column5::text,column6::text,column7::text,column8::text]) AS val + FROM staging2.BUDNI_BRK_Service_Barke_Test_Int where block_row_number in (4,5,6) + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text); + +update staging2.BUDNI_BRK_service_cold_standard_maximum_Block set make=__make,model=__model; +delete from staging2.BUDNI_BRK_service_cold_standard_maximum_Block where dummy_f is null; +execute 'update staging2.BUDNI_BRK_service_cold_standard_maximum_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + + +update staging2.BUDNI_BRK_service_cold_standard_maximum_Block a +set brake_test_type =column2, +brake_test_name =column3, +speed_condition =column5 +from staging2.BUDNI_BRK_Service_Barke_Test_Int b +where b.block_row_number=3 and a.file_syspk=b.file_syspk; + +update staging2.BUDNI_BRK_service_cold_standard_maximum_Block a +set ballast_condition =column3 +from staging2.BUDNI_BRK_Service_Barke_Test_Int b +where b.block_row_number=4 and a.file_syspk=b.file_syspk; + +perform trx.fn_jobctl_block_end(__file_syspk,'BUDNI_BRK_service_cold_standard_maximum_Block'); + + +/* blocks data loading start - BUDNI_BRK_service_cold_ballasted_maximum_Block */ + +perform trx.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_BRK_service_cold_ballasted_maximum_Block',__file_mnemonic,__file_sheet_mnemonic,3); +err_block:='BUDNI_BRK_service_cold_ballasted_maximum_Block'; +insert into staging2.BUDNI_BRK_service_cold_ballasted_maximum_Block +( +dummy_f, +Braking_device_control_force_N, +Mean_deceleration_m_sec2, +Stopping_distance_m +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column5,column6,column7,column8}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column5::text,column6::text,column7::text,column8::text]) AS val + FROM staging2.BUDNI_BRK_Service_Barke_Test_Int where block_row_number in (7,8,9) + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text); + + + +update staging2.BUDNI_BRK_service_cold_ballasted_maximum_Block set make=__make,model=__model; +delete from staging2.BUDNI_BRK_service_cold_ballasted_maximum_Block where dummy_f is null; +execute 'update staging2.BUDNI_BRK_service_cold_ballasted_maximum_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + + +update staging2.BUDNI_BRK_service_cold_ballasted_maximum_Block a +set brake_test_type =column2, +brake_test_name =column3, +speed_condition =column5 +from staging2.BUDNI_BRK_Service_Barke_Test_Int b +where b.block_row_number=3 and a.file_syspk=b.file_syspk; + +update staging2.BUDNI_BRK_service_cold_ballasted_maximum_Block a +set ballast_condition =column3 +from staging2.BUDNI_BRK_Service_Barke_Test_Int b +where b.block_row_number=7 and a.file_syspk=b.file_syspk; + +perform trx.fn_jobctl_block_end(__file_syspk,'BUDNI_BRK_service_cold_ballasted_maximum_Block'); + + +/* blocks data loading start - BUDNI_BRK_service_cold_standard_25kmph_Block */ + +perform trx.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_BRK_service_cold_standard_25kmph_Block',__file_mnemonic,__file_sheet_mnemonic,4); +err_block:='BUDNI_BRK_service_cold_standard_25kmph_Block'; + +insert into staging2.BUDNI_BRK_service_cold_standard_25kmph_Block +( +dummy_f, +Braking_device_control_force_N, +Mean_deceleration_m_sec2, +Stopping_distance_m +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column5,column6,column7,column8}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column5::text,column6::text,column7::text,column8::text]) AS val + FROM staging2.BUDNI_BRK_Service_Barke_Test_Int where block_row_number in (11,12,13) + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text); + + + update staging2.BUDNI_BRK_service_cold_standard_25kmph_Block set make=__make,model=__model; +delete from staging2.BUDNI_BRK_service_cold_standard_25kmph_Block where dummy_f is null; +execute 'update staging2.BUDNI_BRK_service_cold_standard_25kmph_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +update staging2.BUDNI_BRK_service_cold_standard_25kmph_Block a +set brake_test_type =column2, +brake_test_name =column3, +speed_condition =column5 +from staging2.BUDNI_BRK_Service_Barke_Test_Int b +where b.block_row_number=10 and a.file_syspk=b.file_syspk; + +update staging2.BUDNI_BRK_service_cold_standard_25kmph_Block a +set ballast_condition =column3 +from staging2.BUDNI_BRK_Service_Barke_Test_Int b +where b.block_row_number=11 and a.file_syspk=b.file_syspk; + +perform trx.fn_jobctl_block_end(__file_syspk,'BUDNI_BRK_service_cold_standard_25kmph_Block'); + + +/* blocks data loading start - BUDNI_BRK_service_cold_ballasted_25kmph_Block*/ + +perform trx.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_BRK_service_cold_ballasted_25kmph_Block',__file_mnemonic,__file_sheet_mnemonic,5); +err_block:='BUDNI_BRK_service_cold_ballasted_25kmph_Block'; + +insert into staging2.BUDNI_BRK_service_cold_ballasted_25kmph_Block +( +dummy_f, +Braking_device_control_force_N, +Mean_deceleration_m_sec2, +Stopping_distance_m +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column5,column6,column7,column8}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column5::text,column6::text,column7::text,column8::text]) AS val + FROM staging2.BUDNI_BRK_Service_Barke_Test_Int where block_row_number in (14,15,16) + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text); + +update staging2.BUDNI_BRK_service_cold_ballasted_25kmph_Block set make=__make,model=__model; +delete from staging2.BUDNI_BRK_service_cold_ballasted_25kmph_Block where dummy_f is null; +execute 'update staging2.BUDNI_BRK_service_cold_ballasted_25kmph_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +update staging2.BUDNI_BRK_service_cold_ballasted_25kmph_Block a +set brake_test_type =column2, +brake_test_name =column3, +speed_condition =column5 +from staging2.BUDNI_BRK_Service_Barke_Test_Int b +where b.block_row_number=10 and a.file_syspk=b.file_syspk; + +update staging2.BUDNI_BRK_service_cold_ballasted_25kmph_Block a +set ballast_condition =column3 +from staging2.BUDNI_BRK_Service_Barke_Test_Int b +where b.block_row_number=14 and a.file_syspk=b.file_syspk; + +perform trx.fn_jobctl_block_end(__file_syspk,'BUDNI_BRK_service_cold_ballasted_25kmph_Block'); + + +/* blocks data loading start - BUDNI_BRK_service_fade_standard_maximum_Block */ + +perform trx.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_BRK_service_fade_standard_maximum_Block',__file_mnemonic,__file_sheet_mnemonic,6); +err_block:='BUDNI_BRK_service_fade_standard_maximum_Block'; + + insert into staging2.BUDNI_BRK_service_fade_standard_maximum_Block +( +dummy_f, +Braking_device_control_force_N, +Mean_deceleration_m_sec2, +Stopping_distance_m +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column5,column6,column7,column8}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column5::text,column6::text,column7::text,column8::text]) AS val + FROM staging2.BUDNI_BRK_Service_Barke_Test_Int where block_row_number in (19,20,21) + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text); + +update staging2.BUDNI_BRK_service_fade_standard_maximum_Block set make=__make,model=__model; +delete from staging2.BUDNI_BRK_service_fade_standard_maximum_Block where dummy_f is null; +execute 'update staging2.BUDNI_BRK_service_fade_standard_maximum_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +update staging2.BUDNI_BRK_service_fade_standard_maximum_Block a +set brake_test_type =column2, +brake_test_name =column3, +speed_condition =column5 +from staging2.BUDNI_BRK_Service_Barke_Test_Int b +where b.block_row_number=17 and a.file_syspk=b.file_syspk; + +update staging2.BUDNI_BRK_service_fade_standard_maximum_Block a +set ballast_condition =column3 +from staging2.BUDNI_BRK_Service_Barke_Test_Int b +where b.block_row_number=19 and a.file_syspk=b.file_syspk; + +perform trx.fn_jobctl_block_end(__file_syspk,'BUDNI_BRK_service_fade_standard_maximum_Block'); + + +/* blocks data loading start - BUDNI_BRK_service_fade_ballasted_25kmph_Block */ + +perform trx.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_BRK_service_fade_ballasted_25kmph_Block',__file_mnemonic,__file_sheet_mnemonic,7); +err_block:='BUDNI_BRK_service_fade_ballasted_25kmph_Block'; + + insert into staging2.BUDNI_BRK_service_fade_ballasted_25kmph_Block +( +dummy_f, +Braking_device_control_force_N, +Mean_deceleration_m_sec2, +Stopping_distance_m +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column5,column6,column7,column8}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column5::text,column6::text,column7::text,column8::text]) AS val + FROM staging2.BUDNI_BRK_Service_Barke_Test_Int where block_row_number in (23,24,25) + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text); + +update staging2.BUDNI_BRK_service_fade_ballasted_25kmph_Block set make=__make,model=__model; +delete from staging2.BUDNI_BRK_service_fade_ballasted_25kmph_Block where dummy_f is null; +execute 'update staging2.BUDNI_BRK_service_fade_ballasted_25kmph_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +update staging2.BUDNI_BRK_service_fade_ballasted_25kmph_Block a +set brake_test_type =column2, +brake_test_name =column3, +speed_condition =column5 +from staging2.BUDNI_BRK_Service_Barke_Test_Int b +where b.block_row_number=22 and a.file_syspk=b.file_syspk; + +update staging2.BUDNI_BRK_service_fade_ballasted_25kmph_Block a +set ballast_condition =column3 +from staging2.BUDNI_BRK_Service_Barke_Test_Int b +where b.block_row_number=23 and a.file_syspk=b.file_syspk; + +perform trx.fn_jobctl_block_end(__file_syspk,'BUDNI_BRK_service_fade_ballasted_25kmph_Block'); + +/* blocks data loading start - BUDNI_BRK_other_observations_Block */ + +perform trx.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_BRK_other_observations_Block',__file_mnemonic,__file_sheet_mnemonic,8); +err_block:='BUDNI_BRK_other_observations_Block'; + +insert into staging2.BUDNI_BRK_other_observations_Block +( +column3, +column5, +column7, +block_row_number +) +select +column3, +column5, +column7, +block_row_number +from staging2.BUDNI_BRK_Service_Barke_Test_Int +where block_row_number in (26,27,28) order by block_row_number; + +update staging2.BUDNI_BRK_other_observations_Block +set trx_record=0 where block_row_number in (26,27); + +update staging2.BUDNI_BRK_other_observations_Block set make=__make,model=__model; +execute 'update staging2.BUDNI_BRK_other_observations_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform trx.fn_jobctl_block_end(__file_syspk,'BUDNI_BRK_other_observations_Block'); + + +insert into staging2.BUDNI_BRK_Parking_Barke_Test_Int +( +column3, +column5, +column6, +column7, +column8, +block_row_number +) +select +column3,column5,column6,column7,column8,block_row_number +from staging2.stg_process_table_BUDNI_BRK a +where block_tag ='BUDNI_BRK_Parking_Brake_Test' +order by block_row_number; + +update staging2.BUDNI_BRK_Parking_Barke_Test_Int +set column6=column5 where block_row_number=2; + +update staging2.BUDNI_BRK_Parking_Barke_Test_Int +set column8=column7 where block_row_number=2; + +update staging2.BUDNI_BRK_Parking_Barke_Test_Int +set column6=column5 where block_row_number=5; + +update staging2.BUDNI_BRK_Parking_Barke_Test_Int +set column8=column7 where block_row_number=5; + +update staging2.BUDNI_BRK_Parking_Barke_Test_Int set make=__make,model=__model; +execute 'update staging2.BUDNI_BRK_Parking_Barke_Test_Int set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/* blocks data loading start -BUDNI_BRK_Parking_Barke_Test_Block */ + +perform trx.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_BRK_Parking_Barke_Test_Block',__file_mnemonic,__file_sheet_mnemonic,9); +err_block:='BUDNI_BRK_Parking_Barke_Test_Block'; +insert into staging2.BUDNI_BRK_Parking_Barke_Test_Block +( +dummy_f, +particulars, +facing, +Braking_device_control_force, +Efficacy_of_parking_brake +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column5,column6,column7,column8}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column5::text,column6::text,column7::text,column8::text]) AS val + FROM staging2.BUDNI_BRK_Parking_Barke_Test_Int where block_row_number <> 1 + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text); + + update staging2.BUDNI_BRK_Parking_Barke_Test_Block set trx_record=0 where particulars is null; + +update staging2.BUDNI_BRK_Parking_Barke_Test_Block set make=__make,model=__model; +delete from staging2.BUDNI_BRK_Parking_Barke_Test_Block where dummy_f is null; +execute 'update staging2.BUDNI_BRK_Parking_Barke_Test_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform trx.fn_jobctl_block_end(__file_syspk,'BUDNI_BRK_Parking_Barke_Test_Block'); + +/* blocks data loading start - BUDNI_BRK_Test_Obs_Summary_Block */ + +perform trx.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_BRK_Test_Obs_Summary_Block',__file_mnemonic,__file_sheet_mnemonic,10); +err_block:='BUDNI_BRK_Test_Obs_Summary_Block'; + +insert into staging2.BUDNI_BRK_Test_Obs_Summary_Block +( +column3,column4,column5,column6,column7, +column8,column9,block_row_number +) +select +column3,column4,column5,column6,column7, +column8,column9,block_row_number +from staging2.stg_process_table_BUDNI_BRK a +where block_tag='BUDNI_BRK_Test_Obs_Summary' and block_row_number <=7 +order by block_row_number; + +select column3 into __characteristic_1 from staging2.BUDNI_BRK_Test_Obs_Summary_Block +where block_row_number=3; + +update staging2.BUDNI_BRK_Test_Obs_Summary_Block set +column3=concat(__characteristic_1,'-',column3) where block_row_number in (4,5); + + +update staging2.BUDNI_BRK_Test_Obs_Summary_Block +set trx_record=0 where +block_row_number in(1,2,3); + + + +update staging2.BUDNI_BRK_Test_Obs_Summary_Block set make=__make,model=__model; +execute 'update staging2.BUDNI_BRK_Test_Obs_Summary_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform trx.fn_jobctl_block_end(__file_syspk,'BUDNI_BRK_Test_Obs_Summary_Block'); + +perform trx.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_BUDNI_BRK_Block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + + + diff --git a/onetime/dataloadfunctions/budni/BUDNI_DBP_ODS.sql b/onetime/dataloadfunctions/budni/BUDNI_DBP_ODS.sql new file mode 100755 index 0000000..f97d2ed --- /dev/null +++ b/onetime/dataloadfunctions/budni/BUDNI_DBP_ODS.sql @@ -0,0 +1,207 @@ +drop function if exists staging2.fn_BUDNI_DBP_TRX ; +CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_DBP_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + declare __test_instance_tractor_id int; + begin +__file_syspk := p_file_syspk; +/************************************************************ +Function Name:fn_BUDNI_DBP_TRX +Function Desc: This function populates data into ODS +File Format: BUDNI +Sheet Format: BUDNI_DBP +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_BUDNI_DBP_TRX() +***************************************************************/ + + insert into transactional.test_instance_tractor_info + ( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +configuration, +Transmission_type, + Wheel_Drive_Type, + Steering_type, + hitch_height_mm, + Ballast_condition + ) + select + client_id, +function_id, +file_syspk , +file_mnemonic, +file_sheet_mnemonic, + column3, + column4, + column7, + column8, + column9, + column11, + column13::int, + column14 + from staging2.BUDNI_DBP_Spec_H1_Block where trx_record =1 ; + + +update transactional.test_instance_tractor_info +set mahindra_model_yn = ( +case when tractor_make like 'Mahindra%' then 'Y' else 'N' end +) where file_syspk =__file_syspk; + +update transactional.test_instance_tractor_info a +set test_tractor_yn ='Y' where syspk in +(select min(syspk) from transactional.test_instance_tractor_info b +where b.file_syspk =a.file_syspk) +and a.file_syspk =__file_syspk; + + insert into transactional.test_instance + ( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +type_of_road + ) + select + client_id, +function_id, +file_syspk , +file_mnemonic, +file_sheet_mnemonic, + column3, + column4, + column15 + from staging2.BUDNI_DBP_Spec_H1_Block where trx_record =1 ; + +insert into transactional.test_instance_engine_info + ( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +Rated_RPM, +engine_to_pto_ratio_540_pto + ) + select + client_id, +function_id, +file_syspk , +file_mnemonic, +file_sheet_mnemonic, + column3, + column4, + column6::int, + column12 + from staging2.BUDNI_DBP_Spec_H1_Block where trx_record =1 ; + + +insert into transactional.budni_drawbar_perf_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condtion, +gear_used, +travel_speed_km_per_hr, +drawbar_power_kw, +drawbar_pull_kn, +engine_speed_rpm, +wheel_slippage_pct , +fuel_consumption_kg_per_kwh, +fuel_consumption_ltr_per_hr , +specific_energy_kwh_per_ltr, +atmosp_conditions_temp_c, +atmosp_conditions_pressure_kpa, +atmosp_conditions_rh_pct, +temp_fuel_c, +temp_trans_oil_c, +temp_coolant_c, +temp_engine_oil_c +) +select +client_id,function_id,file_syspk,file_mnemonic,file_sheet_mnemonic,make,model, +column2,column3,column4::float,column5::float,column6::float,column7::float, +column8::float,column9::float,column10::float,column11::float,column12,column13, +column14,column15,column16,column17,column18 +from staging2.BUDNI_DBP_Drawbar_Perf_Block where trx_record = 1; + + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk; +select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk; +select syspk from transactional.test_master into __test_master_id where test_type ='BUDNI'; +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk; + + +update transactional.test_instance +set test_master_id =__test_master_id, +test_tractor_id =__test_instance_tractor_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_engine_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.budni_drawbar_perf_results +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_BUDNI_DBP_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + + + diff --git a/onetime/dataloadfunctions/budni/BUDNI_DBP_STG2.sql b/onetime/dataloadfunctions/budni/BUDNI_DBP_STG2.sql new file mode 100755 index 0000000..00df231 --- /dev/null +++ b/onetime/dataloadfunctions/budni/BUDNI_DBP_STG2.sql @@ -0,0 +1,257 @@ +drop function if exists staging2.fn_BUDNI_DBP_Block ; +CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_DBP_Block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + + begin + + +/*********************************************************************************** +Function Name:fn_BUDNI_DBP_Block +Function Desc: This function populates data into staging2 blocks +File Format: BUDNI +Sheet Format: BUDNI_DBP +Creation Date: March 21 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_BUDNI_DBP_Block(20,1,'BUDNI','BUDNI_DBP',261); +************************************************************************************/ + + +SET search_path TO staging2; + +/* rerunnability - delete block tables and update config tables to null */ +truncate table staging2.BUDNI_DBP_Spec_H1_Block; +truncate table staging2.BUDNI_DBP_Drawbar_Perf_Block; +truncate table staging2.stg_specific_table_budni_dbp; +truncate table staging2.stg_process_table_budni_dbp; + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/* transfer data from generic to specific for BUDNI */ +execute 'insert into staging2.stg_specific_table_budni_dbp +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_budni_dbp; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for Budni DBP', + detail = 'No data in table stg_specific_table_budni_dbp', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + +update transactional.source_config set F1_source=F1_modified ; + + +/* keyword match in config table*/ +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_budni_dbp b +where upper(F1_source)=upper(column3) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update in process table for match*/ +execute 'update staging2.stg_specific_table_budni_dbp a +set is_rownumber_fetched=1 +from transactional.source_config b +where upper(F1_source)= upper(column3) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* update config files for row numbers start, end */ +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a +set row_read_end = null +where f1_modified =''Tractor Drawbar Performance Report.'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set run_time=current_timestamp +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers for each block in process table*/ +execute 'insert into staging2.stg_process_table_budni_dbp +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_budni_dbp a +join transactional.source_config b +on a.row_number >row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Tractor Specifiactions'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + + +execute 'insert into staging2.stg_process_table_budni_dbp +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_budni_dbp a +join transactional.source_config b +on a.row_number >row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Tractor Drawbar Performance Report.'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + +/* fetching tractor model and make */ +select column3 into __make from staging2.stg_process_table_budni_dbp a +where block_tag='BUDNI_DBP_Spec_H1' and block_row_number=2; + +select column4 into __model from staging2.stg_process_table_budni_dbp a +where block_tag='BUDNI_DBP_Spec_H1' and block_row_number=2; + + +/* blocks data loading start - BUDNI_DBP_Spec_H1_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_DBP_Spec_H1_Block',__file_mnemonic,__file_sheet_mnemonic,1); +err_block:='BUDNI_DBP_Spec_H1_Block'; + +insert into staging2.BUDNI_DBP_Spec_H1_Block +( +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,column13, +column14,column15,block_row_number +) +select +column2,column3,column4,column5,column6,column7,column8,column9,column10, +column11,column12,column13,column14,column15,block_row_number +from staging2.stg_process_table_budni_dbp +where block_tag='BUDNI_DBP_Spec_H1'; + + +update staging2.BUDNI_DBP_Spec_H1_Block +set trx_record=0 where block_row_number in +(select distinct first_value(b.block_row_number) +over (partition by b.column2 order by b.syspk) from staging2.BUDNI_DBP_Spec_H1_Block b); + + +execute 'update staging2.BUDNI_DBP_Spec_H1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_DBP_Spec_H1_Block'); + + +/* blocks data loading start - BUDNI_DBP_Spec_H1_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_DBP_Drawbar_Perf_Block',__file_mnemonic,__file_sheet_mnemonic,2); +err_block:='BUDNI_DBP_Drawbar_Perf_Block'; + +insert into staging2.BUDNI_DBP_Drawbar_Perf_Block +( +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,column13, +column14,column15,column16,column17,column18,column19,block_row_number +) +select +column2,column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,column13,column14, +column15,column16,column17,column18,column19,block_row_number +from staging2.stg_process_table_budni_dbp a +where block_tag='BUDNI_DBP_Drawbar_Perf' +order by block_row_number; + + + +update staging2.BUDNI_DBP_Drawbar_Perf_Block set make=__make,model=__model; +execute 'update staging2.BUDNI_DBP_Drawbar_Perf_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + + +update staging2.BUDNI_DBP_Drawbar_Perf_Block +set column2= column3 where column3 like 'i%'; + +update staging2.BUDNI_DBP_Drawbar_Perf_Block +set column3=null +where column3 like 'i%'; + +update staging2.BUDNI_DBP_Drawbar_Perf_Block a + set column2= b.first_value from (SELECT +block_row_number, column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column2, +sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.BUDNI_DBP_Drawbar_Perf_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + + +update staging2.BUDNI_DBP_Drawbar_Perf_Block +set trx_record=0 where column4 is null or +block_row_number in +(select distinct first_value(b.block_row_number) +over (partition by b.column2 order by b.syspk) from staging2.BUDNI_DBP_Drawbar_Perf_Block b); + +delete from staging2.BUDNI_DBP_Drawbar_Perf_Block a +using staging2.BUDNI_DBP_Drawbar_Perf_Block b +where a.column2 like 'iV%' and b.column2 like 'iV%' +and a.column2 =b.column2 and a.syspk>=b.syspk + 2; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_DBP_Drawbar_Perf_Block'); + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_BUDNI_DBP_Block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + + + + diff --git a/onetime/dataloadfunctions/budni/BUDNI_FLD_ODS.sql b/onetime/dataloadfunctions/budni/BUDNI_FLD_ODS.sql new file mode 100755 index 0000000..a05278c --- /dev/null +++ b/onetime/dataloadfunctions/budni/BUDNI_FLD_ODS.sql @@ -0,0 +1,402 @@ +drop function if exists staging2.fn_budni_fld_TRX; +CREATE OR REPLACE FUNCTION staging2.fn_budni_fld_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + declare __test_instance_tractor_id int; + begin + __file_syspk := p_file_syspk; +/************************************************************ +Function Name:fn_BUDNI_FLD_TRX +Function Desc: This function populates data into ODS +File Format: BUDNI +Sheet Format: BUDNI_FLD +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_BUDNI_FLD_TRX() +***************************************************************/ + +insert into transactional.test_instance_tractor_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +tractor_engine_hp, +configuration, +transmission_type, +wheel_drive_type, +fip_type, +steering_type, +ballast_condition +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make, +model, +tractor_HP::int tractor_engine_hp, +configuration, +transmission_type, +wheel_drive_type, +FIP_type, +steering_type, +Ballast_Condition +from staging2.budni_fld_Spec_H1_block where trx_record=1; + + +insert into transactional.test_instance +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model +from + staging2.budni_fld_Spec_H1_block where trx_record=1; + +update transactional.test_instance_tractor_info +set mahindra_model_yn = ( +case when tractor_make like 'Mahindra%' then 'Y' else 'N' end +) where file_syspk =__file_syspk; + +update transactional.test_instance_tractor_info a +set test_tractor_yn ='Y' where syspk in +(select min(syspk) from transactional.test_instance_tractor_info b +where b.file_syspk =a.file_syspk) +and a.file_syspk =__file_syspk; + + insert into transactional.test_instance_engine_info + ( + client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +rated_rpm, +engine_to_pto_ratio_540_pto +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +rated_rpm::int, +engine_to_pto_ratio engine_to_pto_ratio_540_pto +from staging2.budni_fld_Spec_H1_block where trx_record=1; + +insert into transactional.test_instance_implement_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +name_of_implement, +make_of_implement, +type_of_implement, +no_of_disc_blades_bottoms, +type_of_disc_blades_bottoms, +size_of_bottoms_blades_mm, +size_of_bottoms_blades2_mm, +size_of_bottoms_blades3_mm, +spacing_of_bottoms_flanges_mm, +span_for_mounted_implement_mm, +mast_height_for_mounted_implement_mm, +length_mm, +width_mm, +height_mm, +gross_mass_kg +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +items, +Make, +type, +No_of_Disc_blades, +Type_of_Disc_blades, +Size_of_bottoms_blades_1_mm::numeric, +Size_of_bottoms_blades_2_mm::numeric, +Size_of_bottoms_blades_3_mm::numeric, +Spacing_of_bottoms_flanges_mm::numeric, +Lower_hitch_point_span_mm::numeric, +Mast_height_mm, +Overall_dimensions_mm_length::numeric, +Overall_dimensions_mm_Width::numeric, +Overall_dimensions_mm_Height::numeric, +Gross_mass_kg::numeric +from staging2.BUDNI_FLD_Impl_Test_Block where trx_record=1 +order by block_row_number; + + + +insert into transactional.test_instance_implement_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +name_of_implement, +type_of_implement, +cage_wheel_dia_mm, +cage_wheel_width_mm, +no_and_types_of_lugs, +size_of_angle_section_mm, +size_of_angle_section2_mm, +size_of_angle_section3_mm, +length_of_lugs_mm, +spacing_of_lugs_mm, +cage_wheel_weight_kg +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +Items, +type, +Dia_mm::numeric, +Width_mm::numeric, +No_and_types_of_lugs, +Size_of_angle_section_1_mm::numeric, +Size_of_angle_section_2_mm::numeric, +Size_of_angle_section_3_mm::numeric, +Length_of_lugs_mm::numeric, +Spacing_of_lugs_mm::numeric, +Weight_of_each_cage_wheels_kg::numeric +from staging2.BUDNI_FLD_Cage_Wheel_Block where trx_record=1 +order by block_row_number; + + + +insert into transactional.budni_field_perf_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +operation_type, +type_of_soil, +avg_soil_moisture_pct_, +bulk_density_of_soil_g_per_cc, +cone_index_kgf_per_sq_cm, +gear_used, +avg_speed_of_operation_kmph, +avg_wheel_slip_pct, +avg_depth_of_cut_cm, +avg_working_width_cm, +area_covered_ha_per_hr, +fuel_consumption_ltr_per_hr, +fuel_consumption_ltr_per_ha, +avg_draft_of_implement_kn +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make, +model, +Parameter_operation, +Type_of_soil, +Av_soil_moisture_Av_depth_of_standing_water_cm, +Bulk_density_of_soil_g_cc, +Cone_index_kgf_sq_cm_Puddling_index, +Gear_used, +Av_speed_of_operation_kmph, +Av_wheel_slip_Av_Travel_reduction, +Av_depth_of_cut_cm_Av_Depth_of_puddle_cm, +Av_working_width_cm, +Area_covered_ha_h, +Fuel_consumption_l_h, +Fuel_consumption_l_ha, +Av_draft_of_implement_kN +from staging2.BUDNI_FLD_Sum_Perf_Test_Block where parameter_operation <> 'Puddling' and trx_record=1; + +insert into transactional.budni_field_perf_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +operation_type, +type_of_soil, +avg_depth_of_standing_water_cm , +bulk_density_of_soil_g_per_cc, +puddling_index_pct, +gear_used, +avg_speed_of_operation_kmph, +avg_travel_reduction_pct, +avg_depth_of_puddle_cm, +avg_working_width_cm, +area_covered_ha_per_hr, +fuel_consumption_ltr_per_hr, +fuel_consumption_ltr_per_ha, +avg_draft_of_implement_kn +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make, +model, +Parameter_operation, +Type_of_soil, +Av_soil_moisture_Av_depth_of_standing_water_cm, +Bulk_density_of_soil_g_cc, +Cone_index_kgf_sq_cm_Puddling_index, +Gear_used, +Av_speed_of_operation_kmph, +Av_wheel_slip_Av_Travel_reduction, +Av_depth_of_cut_cm_Av_Depth_of_puddle_cm, +Av_working_width_cm, +Area_covered_ha_h, +Fuel_consumption_l_h, +Fuel_consumption_l_ha, +Av_draft_of_implement_kN +from staging2.BUDNI_FLD_Sum_Perf_Test_Block where parameter_operation ='Puddling' and trx_record=1; + + +insert into transactional.budni_test_observations +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +srl_no, +characteristic, +category_evaluative_or_non_evaluative, +requirements_as_per_is_12207_2008, +values_declared_by_the_applicant_d_rqmt, +as_observed, +whether_meets_the_requirements_yn +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column3, +column4, +column5, +column6, +column7, +column8, +column9 +from staging2.budni_fld_test_obs_summary_block where trx_record=1; + + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk; +select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk; +select syspk from transactional.test_master into __test_master_id where test_type ='BUDNI'; +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk; + + +update transactional.test_instance +set test_master_id =__test_master_id, +test_tractor_id =__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.test_instance_engine_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.test_instance_implement_info +set test_instance_id=__test_instance_id +--tractor_model =__model, +--tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.budni_field_perf_results +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.budni_test_observations +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_budni_fld_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + diff --git a/onetime/dataloadfunctions/budni/BUDNI_FLD_STG2.sql b/onetime/dataloadfunctions/budni/BUDNI_FLD_STG2.sql new file mode 100755 index 0000000..ee091d9 --- /dev/null +++ b/onetime/dataloadfunctions/budni/BUDNI_FLD_STG2.sql @@ -0,0 +1,586 @@ +drop function if exists staging2.fn_BUDNI_FLD_Block ; +CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_FLD_Block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + + begin + +/*********************************************************************************** +Function Name:fn_BUDNI_FLD_Block +Function Desc: This function populates data into staging2 blocks +File Format: BUDNI +Sheet Format: BUDNI_FLD +Creation Date: March 21 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_BUDNI_FLD_Block(20,1,'BUDNI','BUDNI_FLD',261) +************************************************************************************/ + +SET search_path TO staging2; + +/* rerunnability - delete block tables and update config tables to null */ + +truncate table staging2.BUDNI_FLD_Spec_H1_Block; +truncate table staging2.BUDNI_FLD_Impl_Test_Int; +truncate table staging2.BUDNI_FLD_Impl_Test_Block; +truncate table staging2.BUDNI_FLD_Cage_Wheel_Block; +truncate table staging2.BUDNI_FLD_Sum_Perf_Test_Int; +truncate table staging2.BUDNI_FLD_Sum_Perf_Test_Block; +truncate table staging2.BUDNI_FLD_Test_Obs_Summary_Block; +truncate table staging2.stg_specific_table_BUDNI_FLD; +truncate table staging2.stg_process_table_BUDNI_FLD; + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* transfer data from generic to specific for BUDNI */ +execute 'insert into staging2.stg_specific_table_BUDNI_FLD +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_BUDNI_FLD; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for Budni FLD', + detail = 'No data in table stg_specific_table_BUDNI_FLD', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + + +update transactional.source_config set F1_source=F1_modified ; + +/* keyword match in config table*/ +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_BUDNI_FLD b +where upper(F1_source)= upper(column3) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update in process table for match*/ +execute 'update staging2.stg_specific_table_BUDNI_FLD a +set is_rownumber_fetched=1 +from transactional.source_config b +where upper(F1_source)=upper(column3) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/* update config files for row numbers start, end */ +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a +set row_read_end = null +where f1_modified =''Field Performance Test Observations Summary'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set run_time=current_timestamp +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers for each block in process table*/ +execute 'insert into staging2.stg_process_table_BUDNI_FLD +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_BUDNI_FLD a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Tractor Specifiactions'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + +execute 'insert into staging2.stg_process_table_BUDNI_FLD +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_BUDNI_FLD a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''BRIEF SPECIFICATION OF IMPLEMENTS USED DURING FIELD TEST'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +execute 'insert into staging2.stg_process_table_BUDNI_FLD +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_BUDNI_FLD a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''SUMMARY OF FIELD PERFORMANCE TEST'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + +execute 'insert into staging2.stg_process_table_BUDNI_FLD +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_BUDNI_FLD a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Field Performance Test Observations Summary'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +/* fetching tractor model and make */ +select column3 into __make from staging2.stg_process_table_BUDNI_FLD a +where block_tag='BUDNI_FLD_Spec_H1' and block_row_number=3; + +select column4 into __model from staging2.stg_process_table_BUDNI_FLD a +where block_tag='BUDNI_FLD_Spec_H1' and block_row_number=3; + +/* blocks data loading start - BUDNI_FLD_Spec_H1_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_FLD_Spec_H1_block',__file_mnemonic,__file_sheet_mnemonic,1); +err_block:='BUDNI_FLD_Spec_H1_block'; + +insert into staging2.BUDNI_FLD_Spec_H1_block +( +make,model,tractor_HP,rated_rpm,configuration,transmission_type,wheel_drive_type,block_row_number) +select column3,column4,column5,column6,column7,column8,column9,block_row_number +from staging2.stg_process_table_BUDNI_FLD where block_tag='BUDNI_FLD_Spec_H1' +and block_row_number=3; + + +execute 'update staging2.BUDNI_FLD_Spec_H1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +update staging2.BUDNI_FLD_Spec_H1_block a +set FIP_type=column3,steering_type=column4,Engine_to_PTO_ratio= column5,Ballast_Condition=column6, +Test_Engine_Set_RPM=column7 +from staging2.stg_process_table_BUDNI_FLD b +where b.block_tag='BUDNI_FLD_Spec_H1' +and b.block_row_number=5 +and a.file_syspk=b.file_syspk; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_FLD_Spec_H1_block'); + + +insert into staging2.BUDNI_FLD_Impl_Test_Int +( +column3,column4,column5,column6,column7, +column8,column9,block_row_number +) +select +column3,column4,column5,column6,column7, +column8,column9,block_row_number +from staging2.stg_process_table_BUDNI_FLD a +where block_tag ='BUDNI_FLD_Impl_Test' and block_row_number <> 1 +order by block_row_number; + + +update staging2.BUDNI_FLD_Impl_Test_Int a +set column3= b.first_value from (SELECT + block_row_number, column3, value_partition, first_value(column3) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + column3, + sum(case when column3 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.BUDNI_FLD_Impl_Test_Int + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number and a.block_row_number <> 13 ; + +update staging2.BUDNI_FLD_Impl_Test_Int a +set column4= b.first_value from (SELECT + block_row_number, column4, value_partition, first_value(column4) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + column4, + sum(case when column4 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.BUDNI_FLD_Impl_Test_Int + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number and a.block_row_number <> 13 ; + + +update staging2.BUDNI_FLD_Impl_Test_Int a +set column5= b.first_value from (SELECT + block_row_number, column5, value_partition, first_value(column5) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + column5, + sum(case when column5 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.BUDNI_FLD_Impl_Test_Int + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number and a.block_row_number <> 13 ; + + +update staging2.BUDNI_FLD_Impl_Test_Int a +set column6= b.first_value from (SELECT + block_row_number, column6, value_partition, first_value(column6) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + column6, + sum(case when column6 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.BUDNI_FLD_Impl_Test_Int + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number and a.block_row_number <> 13; + + + +update staging2.BUDNI_FLD_Impl_Test_Int a +set column7= b.first_value from (SELECT + block_row_number, column7, value_partition, first_value(column7) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + column7, + sum(case when column7 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.BUDNI_FLD_Impl_Test_Int + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + + +update staging2.BUDNI_FLD_Impl_Test_Int a +set column8= b.first_value from (SELECT + block_row_number, column8, value_partition, first_value(column8) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + column8, + sum(case when column8 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.BUDNI_FLD_Impl_Test_Int + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + + + +execute 'update staging2.BUDNI_FLD_Impl_Test_Int set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/* blocks data loading - BUDNI_FLD_Impl_Test_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_FLD_Impl_Test_Block',__file_mnemonic,__file_sheet_mnemonic,2); +err_block:='BUDNI_FLD_Impl_Test_Block'; + +insert into staging2.BUDNI_FLD_Impl_Test_Block +( +dummy_f, +items, +Make, +type, +No_of_Disc_blades, +Type_of_Disc_blades, +Size_of_bottoms_blades_1_mm, +Size_of_bottoms_blades_2_mm, +Size_of_bottoms_blades_3_mm, +Spacing_of_bottoms_flanges_mm, +Lower_hitch_point_span_mm, +Mast_height_mm, +Overall_dimensions_mm, +Overall_dimensions_mm_length, +Overall_dimensions_mm_Width, +Overall_dimensions_mm_Height, +Gross_mass_kg +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column5,column6}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column5::text,column6::text]) AS val + FROM staging2.BUDNI_FLD_Impl_Test_Int where trx_record=1 + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text, + a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text); + + + delete from staging2.BUDNI_FLD_Impl_Test_Block where dummy_f is null; + +execute 'update staging2.BUDNI_FLD_Impl_Test_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_FLD_Impl_Test_Block'); + + +/* blocks data loading - BUDNI_FLD_Cage_Wheel_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_FLD_Cage_Wheel_Block',__file_mnemonic,__file_sheet_mnemonic,3); +err_block:='BUDNI_FLD_Cage_Wheel_Block'; + + insert into staging2.BUDNI_FLD_Cage_Wheel_Block +( +dummy_f, +Items, +type, +Dia_mm, +Width_mm, +No_and_types_of_lugs, +Size_of_angle_section_1_mm, +Size_of_angle_section_2_mm, +Size_of_angle_section_3_mm, +Length_of_lugs_mm, +Spacing_of_lugs_mm, +Weight_of_each_cage_wheels_kg +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column9}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column9::text]) AS val + FROM staging2.BUDNI_FLD_Impl_Test_Int where trx_record=1 + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text, + a_10 text,a_11 text); + + delete from staging2.BUDNI_FLD_Cage_Wheel_Block where dummy_f is null; + + +execute 'update staging2.BUDNI_FLD_Cage_Wheel_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_FLD_Cage_Wheel_Block'); + + + +insert into staging2.BUDNI_FLD_Sum_Perf_Test_Int +( +column3,column4,column5,column6,column7,block_row_number +) +select +column3,column4,column5,column6,column7,block_row_number +from staging2.stg_process_table_BUDNI_FLD a +where block_tag ='BUDNI_FLD_Sum_Perf_Test' and block_row_number <> 1 +order by block_row_number,column3 ; + +update staging2.BUDNI_FLD_Sum_Perf_Test_Int set make=__make,model=__model; +execute 'update staging2.BUDNI_FLD_Sum_Perf_Test_Int set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + + +/* blocks data loading - BUDNI_FLD_Sum_Perf_Test_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_FLD_Sum_Perf_Test_Block',__file_mnemonic,__file_sheet_mnemonic,4); +err_block:='BUDNI_FLD_Sum_Perf_Test_Block'; + + insert into staging2.BUDNI_FLD_Sum_Perf_Test_Block +( +dummy_f, +Parameter_operation, +Type_of_soil, +Av_soil_moisture_Av_depth_of_standing_water_cm, +Bulk_density_of_soil_g_cc, +Cone_index_kgf_sq_cm_Puddling_index, +Gear_used, +Av_speed_of_operation_kmph, +Av_wheel_slip_Av_Travel_reduction, +Av_depth_of_cut_cm_Av_Depth_of_puddle_cm, +Av_working_width_cm, +Area_covered_ha_h, +Fuel_consumption, +Fuel_consumption_l_h, +Fuel_consumption_l_ha, +Av_draft_of_implement_kN +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column5,column6,column7}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column5::text,column6::text,column7::text]) AS val + FROM staging2.BUDNI_FLD_Sum_Perf_Test_Int where trx_record=1 + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text, + a_11 text,a_12 text,a_13 text,a_14 text,a_15 text); + + + +delete from staging2.BUDNI_FLD_Sum_Perf_Test_Block where dummy_f is null; + +update staging2.BUDNI_FLD_Sum_Perf_Test_Block set make=__make,model=__model; +execute 'update staging2.BUDNI_FLD_Sum_Perf_Test_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_FLD_Sum_Perf_Test_Block'); + + + +/* blocks data loading - BUDNI_FLD_Test_Obs_Summary_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_FLD_Test_Obs_Summary_Block',__file_mnemonic,__file_sheet_mnemonic,5); +err_block:='BUDNI_FLD_Test_Obs_Summary_Block'; + +insert into staging2.BUDNI_FLD_Test_Obs_Summary_Block +( +column3,column4,column5,column6,column7, +column8,column9,block_row_number +) +select +column3,column4,column5,column6,column7, +column8,column9,block_row_number +from staging2.stg_process_table_BUDNI_FLD a +where block_tag='BUDNI_FLD_Test_Obs_Summary' and block_row_number <=6; + + +update staging2.BUDNI_FLD_Test_Obs_Summary_Block +set trx_record=0 +where block_row_number in (1,2); + + +update staging2.BUDNI_FLD_Test_Obs_Summary_Block a +set column4= b.first_value from (SELECT + block_row_number, column4, value_partition, first_value(column4) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + column4, + sum(case when column4 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.BUDNI_FLD_Test_Obs_Summary_Block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + +update staging2.BUDNI_FLD_Test_Obs_Summary_Block a +set column5= b.first_value from (SELECT + block_row_number, column5, value_partition, first_value(column5) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + column5, + sum(case when column5 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.BUDNI_FLD_Test_Obs_Summary_Block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + +update staging2.BUDNI_FLD_Test_Obs_Summary_Block a +set column6= b.first_value from (SELECT + block_row_number, column6, value_partition, first_value(column6) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + column6, + sum(case when column6 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.BUDNI_FLD_Test_Obs_Summary_Block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + + +update staging2.BUDNI_FLD_Test_Obs_Summary_Block a +set column7= b.first_value from (SELECT + block_row_number, column7, value_partition, first_value(column7) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + column7, + sum(case when column7 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.BUDNI_FLD_Test_Obs_Summary_Block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + + +update staging2.BUDNI_FLD_Test_Obs_Summary_Block a +set column8= b.first_value from (SELECT + block_row_number, column8, value_partition, first_value(column8) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + column8, + sum(case when column8 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.BUDNI_FLD_Test_Obs_Summary_Block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + +update staging2.BUDNI_FLD_Test_Obs_Summary_Block a +set column9= b.first_value from (SELECT + block_row_number, column9, value_partition, first_value(column9) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + column9, + sum(case when column9 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.BUDNI_FLD_Test_Obs_Summary_Block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + + + +update staging2.BUDNI_FLD_Test_Obs_Summary_Block set make=__make,model=__model; +execute 'update staging2.BUDNI_FLD_Test_Obs_Summary_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_FLD_Test_Obs_Summary_Block'); + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_BUDNI_FLD_Block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + + + diff --git a/onetime/dataloadfunctions/budni/BUDNI_HDL_ODS.sql b/onetime/dataloadfunctions/budni/BUDNI_HDL_ODS.sql new file mode 100755 index 0000000..ef9e3a9 --- /dev/null +++ b/onetime/dataloadfunctions/budni/BUDNI_HDL_ODS.sql @@ -0,0 +1,364 @@ +drop function if exists staging2.fn_BUDNI_HDL_TRX; +CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_HDL_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + declare __test_instance_tractor_id int; + begin + +__file_syspk := p_file_syspk; +/************************************************************ +Function Name:fn_BUDNI_HDL_TRX +Function Desc: This function populates data into ODS +File Format: BUDNI +Sheet Format: BUDNI_HDL +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_BUDNI_HDL_TRX() +***************************************************************/ + +insert into transactional.test_instance_tractor_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +tractor_engine_hp, +steering_type +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make, +model, +tractor_HP::int, +steering_type +from staging2.BUDNI_HDL_Spec_H1_block; + +update transactional.test_instance_tractor_info +set mahindra_model_yn = ( +case when tractor_make like 'Mahindra%' then 'Y' else 'N' end +) where file_syspk =__file_syspk; + +update transactional.test_instance_tractor_info a +set test_tractor_yn ='Y' where syspk in +(select min(syspk) from transactional.test_instance_tractor_info b +where b.file_syspk =a.file_syspk) +and a.file_syspk =__file_syspk; + +insert into transactional.test_instance +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make, +model +from + staging2.BUDNI_HDL_Spec_H1_block; + + insert into transactional.test_instance_engine_info + ( + client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +rated_rpm +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make, +model, +rated_rpm::int +from staging2.BUDNI_HDL_Spec_H1_block; + +insert into transactional.test_instance_tractor_info_misc + ( + client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +hydraulic_type, +pump_speed_at_rated_engine_speed_rpm, +oil, +lift_rod_type_lh, +lift_rod_type_rh, +lift_rod_length_lh, +lift_rod_length_rh, +lower_link_length_lh, +lower_link_length_rh, +pump_hp +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make, +model, +hydraulic_type, +Pump_speed_at_rated_engine_speed_rpm::numeric, +Oil, +Lift_Rod_type_LH, +Lift_Rod_type_RH, +Lift_Rod_Length_LH::numeric, +Lift_Rod_Length_RH::numeric, +Lower_link_Length_LH::numeric, +Lower_link_Length_RH::numeric, +Pump_HP::numeric +from staging2.BUDNI_HDL_Spec_H1_block; + + +/*block */ + +insert into transactional.budni_hydraulic_power_test_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +pump_dlvry_rate_at_min_pressure_engine_speed_l_per_min, +max_hydraulic_power_kw, +pump_dlvry_rate_at_max_hydraulic_power_lmin, +pressure_at_max_hydraulic_power_mpa, +sustained_pressure_of_the_open_relief_valve_mpa, +tapping_point_relief_valve_test, +tapping_point_pump_perf_test, +tapping_point_temperature_of_hydraulic_fluid_c +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +Pump_delivery_rate_at_min_pressure_and_rated_engine::numeric, +Maximum_hydraulic_power_kW::numeric, + Pump_delivery_rate_at_maximum_hydraulic_power_l_min::numeric, + Pressure_at_maximum_hydraulic_power_MPa::numeric, + Sustained_pressure_of_the_open_relief_valve_MPa::numeric, +tapping_point_relief_valve_test, +tapping_point_Pump_performance_test, +tapping_point_Temperature_of_hydraulic_fluid_C +from staging2.budni_hdl_power_test_block where trx_record=1 +order by block_row_number; + + +insert into transactional.budni_hydraulic_maint_of_lift_load_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +force_applied_at_the_frame_kn, +temp_of_hydraulic_fluid_at_the_start_of_test_c, +elapsed_time_min, +cumulative_drop_in_height_of_lift_mm +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make, +model, +Force_applied_at_the_frame_kN::numeric, +Temperature_of_hydraulic_fluid_at_the_start_of_test_C, +Elapsed_time_minute::numeric, +Cumulative_drop_in_height_of_lift_mm::numeric +from staging2.budni_hdl_maintenance_of_lift_load_block; + +/*block */ +insert into transactional.budni_hydraulic_lifting_capacity_test_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +test_condition, +height_of_lower_hitch_pt_above_ground_in_down_position_mm, +vertical_move_ment_with_lifting_forces_mm, +max_force_exerted_through_full_range_kn, +corresponding_pressure_mpa, +moment_about_rear_axle_kn_m, +max_tilt_angle_of_mast_from_vertical_degrees +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make, +model, +column5, +column6::numeric, +column7::numeric, +column8::numeric, +column9::numeric, +column10::numeric, +column11::numeric +from staging2.budni_hdl_Lifting_Capacity_Test_Block +where trx_record=1; + + +/* block */ + + +insert into transactional.budni_test_observations +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +srl_no, +characteristic, +category_evaluative_or_non_evaluative, +requirements_as_per_is_12207_2008, +values_declared_by_the_applicant_d_rqmt, +as_observed, +whether_meets_the_requirements_yn +) +select client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column3,column4,column7,column8,column10,column11,column12 +from staging2.budni_hdl_test_obs_summary_block +where trx_record=1 +; + + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk; +select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk; +select syspk from transactional.test_master into __test_master_id where test_type ='BUDNI'; +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk; + + +update transactional.test_instance +set test_master_id =__test_master_id, +test_tractor_id =__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.test_instance_engine_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.test_instance_tractor_info_misc +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.budni_hydraulic_maint_of_lift_load_results +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.budni_hydraulic_power_test_results +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.budni_hydraulic_lifting_capacity_test_results +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.budni_test_observations +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_BUDNI_HDL_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + + diff --git a/onetime/dataloadfunctions/budni/BUDNI_HDL_STG2.sql b/onetime/dataloadfunctions/budni/BUDNI_HDL_STG2.sql new file mode 100755 index 0000000..644a1e7 --- /dev/null +++ b/onetime/dataloadfunctions/budni/BUDNI_HDL_STG2.sql @@ -0,0 +1,547 @@ +drop function if exists staging2.fn_budni_hdl_Block ; +CREATE OR REPLACE FUNCTION staging2.fn_budni_hdl_Block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + DECLARE __characteristic_A text; + begin + + +/*********************************************************************************** +Function Name:fn_budni_hdl_Block +Function Desc: This function populates data into staging2 blocks +File Format: BUDNI +Sheet Format: BUDNI_HDL +Creation Date: March 21 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_BUDNI_HDL_Block(20,1,'BUDNI','BUDNI_HDL',261); +************************************************************************************/ + +SET search_path TO staging2; + +/* rerunnability - delete block tables and update config tables to null */ +truncate table staging2.stg_specific_table_budni_hdl; +truncate table staging2.stg_process_table_budni_hdl; +truncate table staging2.budni_hdl_Spec_H1_Block; +truncate table staging2.budni_hdl_power_test_Block; +truncate table staging2.budni_hdl_Lifting_Capacity_Test_Block; +truncate table staging2.budni_hdl_Maintenance_of_lift_load_int; +truncate table staging2.budni_hdl_Maintenance_of_lift_load_Block; +truncate table staging2.budni_hdl_Test_Obs_Summary_Block; + + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/* transfer data from generic to specific for BUDNI */ +execute 'insert into staging2.stg_specific_table_budni_hdl +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_budni_hdl; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for Budni_HDL', + detail = 'No data in table stg_specific_table_budni_hdl', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + + + +update transactional.source_config set F1_source=F1_modified ; + + +/* keyword match in config table*/ +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_budni_hdl b +where upper(F1_source)= upper(column3) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update in process table for match*/ +execute 'update staging2.stg_specific_table_budni_hdl a +set is_rownumber_fetched=1 +from transactional.source_config b +where upper(F1_source)= upper(column3) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* update config files for row numbers start, end */ +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a +set row_read_end = null +where f1_modified =''Power Lift and Hydraulic Pump Performance Test Observations Summary'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers for each block in process table*/ +execute 'update transactional.source_config a +set run_time=current_timestamp +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'insert into staging2.stg_process_table_budni_hdl +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_budni_hdl a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Tractor Specifiactions'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + +execute 'insert into staging2.stg_process_table_budni_hdl +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_budni_hdl a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''A) Hydraulic power test:'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + + +execute 'insert into staging2.stg_process_table_budni_hdl +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_budni_hdl a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Tapping Point'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + +execute 'insert into staging2.stg_process_table_budni_hdl +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_budni_hdl a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''C) Maintenance of lift load:'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + +execute 'insert into staging2.stg_process_table_budni_hdl +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_budni_hdl a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Power Lift and Hydraulic Pump Performance Test Observations Summary'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + +/* fetching tractor model and make */ +select column3 into __make from staging2.stg_process_table_budni_hdl a +where block_tag='BUDNI_HDL_Spec_H1' and block_row_number=3; + +select column4 into __model from staging2.stg_process_table_budni_hdl a +where block_tag='BUDNI_HDL_Spec_H1' and block_row_number=3; + + + +/* blocks data loading start - budni_hdl_Spec_H1_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_HDL_Spec_H1_block',__file_mnemonic,__file_sheet_mnemonic,1); +err_block:='BUDNI_HDL_Spec_H1_block'; +insert into staging2.budni_hdl_Spec_H1_Block +( +make, +model, +tractor_HP, +rated_rpm, +hydraulic_type, +Pump_speed_at_rated_engine_speed_rpm, +Steering_Type, +Oil,block_row_number +) +select +column3,column4,column5,column6,column7,column8,column9,column10,block_row_number +from staging2.stg_process_table_budni_hdl +where block_tag='BUDNI_HDL_Spec_H1' and block_row_number=3; + + +execute 'update staging2.budni_hdl_Spec_H1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + + +update staging2.BUDNI_HDL_Spec_H1_block a +set Lift_Rod_type_LH =column3, +Lift_Rod_type_RH= column4, +Lift_Rod_Length_LH=column5, +Lift_Rod_Length_RH=column6, +Lower_link_Length_LH=column7, +Lower_link_Length_RH=column8, +Pump_HP=column9 +from staging2.stg_process_table_budni_hdl b +where b.block_tag='BUDNI_HDL_Spec_H1' +and b.block_row_number=6 +and a.file_syspk=b.file_syspk; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_HDL_Spec_H1_block'); + + +/* blocks data loading - budni_hdl_power_test_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'budni_hdl_power_test_block',__file_mnemonic,__file_sheet_mnemonic,2); +err_block:='budni_hdl_power_test_block'; +insert into staging2.budni_hdl_power_test_block (dummy_f) values('dummy'); + +update staging2.budni_hdl_power_test_block +set Pump_delivery_rate_at_min_pressure_and_rated_engine= (select column3 +from staging2.stg_process_table_budni_hdl +where block_tag ='BUDNI_HDL_Power_Test' and block_row_number=3) +where dummy_f='dummy'; + + +update staging2.budni_hdl_power_test_block +set Maximum_hydraulic_power_kW= (select column5 +from staging2.stg_process_table_budni_hdl +where block_tag ='BUDNI_HDL_Power_Test' and block_row_number=3) +where dummy_f='dummy'; + + +update staging2.budni_hdl_power_test_block +set Pump_delivery_rate_at_maximum_hydraulic_power_l_min= (select column7 +from staging2.stg_process_table_budni_hdl +where block_tag ='BUDNI_HDL_Power_Test' and block_row_number=3) +where dummy_f='dummy'; + + +update staging2.budni_hdl_power_test_block +set Pressure_at_maximum_hydraulic_power_MPa= (select column9 +from staging2.stg_process_table_budni_hdl +where block_tag ='BUDNI_HDL_Power_Test' and block_row_number=3) +where dummy_f='dummy'; + + +update staging2.budni_hdl_power_test_block +set Sustained_pressure_of_the_open_relief_valve_MPa= (select column11 +from staging2.stg_process_table_budni_hdl +where block_tag ='BUDNI_HDL_Power_Test' and block_row_number=3) +where dummy_f='dummy'; + + + +update staging2.budni_hdl_power_test_block +set tapping_point_relief_valve_test = (select column4 +from staging2.stg_process_table_budni_hdl +where block_tag ='BUDNI_HDL_Lifting_Capacity_Test' and block_row_number=2) +where dummy_f='dummy'; + + +update staging2.budni_hdl_power_test_block +set tapping_point_Pump_performance_test= (select column4 +from staging2.stg_process_table_budni_hdl +where block_tag ='BUDNI_HDL_Lifting_Capacity_Test' and block_row_number=3) +where dummy_f='dummy'; + + +update staging2.budni_hdl_power_test_block +set tapping_point_Temperature_of_hydraulic_fluid_C= (select column4 +from staging2.stg_process_table_budni_hdl +where block_tag ='BUDNI_HDL_Lifting_Capacity_Test' and block_row_number=4) +where dummy_f='dummy'; + + +update staging2.BUDNI_HDL_Power_Test_Block set make=__make,model=__model; +execute 'update staging2.BUDNI_HDL_Power_Test_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +update staging2.BUDNI_HDL_Power_Test_Block +set trx_record=0 where +block_row_number in (1,2); + +perform fw_core.fn_jobctl_block_end(__file_syspk,'budni_hdl_power_test_block'); + +/* blocks data loading - budni_hdl_Lifting_Capacity_Test_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'budni_hdl_Lifting_Capacity_Test_Block',__file_mnemonic,__file_sheet_mnemonic,3); +err_block:='budni_hdl_Lifting_Capacity_Test_Block'; +insert into staging2.budni_hdl_Lifting_Capacity_Test_Block +( +column5,column6,column7, +column8,column9,column10,column11,block_row_number +) +select +column5,column6,column7, +column8,column9,column10,column11,block_row_number +from staging2.stg_process_table_budni_hdl a +where block_tag='BUDNI_HDL_Lifting_Capacity_Test'; + + +update staging2.budni_hdl_Lifting_Capacity_Test_Block set make=__make,model=__model; +execute 'update staging2.budni_hdl_Lifting_Capacity_Test_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +update staging2.budni_hdl_Lifting_Capacity_Test_Block +set trx_record=0 where +block_row_number in (1,2); + + +perform fw_core.fn_jobctl_block_end(__file_syspk,'budni_hdl_Lifting_Capacity_Test_Block'); + + + +insert into staging2.budni_hdl_Maintenance_of_lift_load_int +( +column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +) +select +column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_budni_hdl a +where block_tag='BUDNI_HDL_Maintenance_Of_Lift_Load'; + +update staging2.budni_hdl_Maintenance_of_lift_load_int +set trx_record=0 where +block_row_number=1; + + + +/* blocks data loading - PTOBST_RPT_PTO_performance_report_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'budni_hdl_Maintenance_of_lift_load_Block',__file_mnemonic,__file_sheet_mnemonic,4); +err_block:='budni_hdl_Maintenance_of_lift_load_Block'; +insert into staging2.budni_hdl_Maintenance_of_lift_load_Block +( +dummy_f, +Elapsed_time_minute, +Cumulative_drop_in_height_of_lift_mm +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column7,column8,column9,column10,column11,column12}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column7::text,column8::text,column9::text, +column10::text,column11::text,column12::text]) AS val + FROM staging2.budni_hdl_Maintenance_of_lift_load_int where block_row_number in (2,3) + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text); + + + +update staging2.budni_hdl_Maintenance_of_lift_load_block +set Force_applied_at_the_frame_kN =(select column5 +from staging2.budni_hdl_Maintenance_of_lift_load_int +where column3 ='Force applied at the frame, (kN)') +where Force_applied_at_the_frame_kN is null; + +update staging2.budni_hdl_Maintenance_of_lift_load_block +set Temperature_of_hydraulic_fluid_at_the_start_of_test_C =(select column5 +from staging2.budni_hdl_Maintenance_of_lift_load_int +where column3 ='Temperature of hydraulic fluid at the start of test, (â °C)') +where Temperature_of_hydraulic_fluid_at_the_start_of_test_C is null; + + +delete from staging2.budni_hdl_Maintenance_of_lift_load_block where dummy_f is null; +update staging2.budni_hdl_Maintenance_of_lift_load_block set make=__make,model=__model; +execute 'update staging2.budni_hdl_Maintenance_of_lift_load_block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'budni_hdl_Maintenance_of_lift_load_Block'); + + +/* blocks data loading - budni_hdl_Test_Obs_Summary_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'budni_hdl_Test_Obs_Summary_Block',__file_mnemonic,__file_sheet_mnemonic,5); +err_block:='budni_hdl_Test_Obs_Summary_Block'; + +insert into staging2.budni_hdl_Test_Obs_Summary_Block +( +column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +) +select +column3,column4,column5,column6,column7, +column8,column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_budni_hdl a +where block_tag='BUDNI_HDL_Test_Obs_Summary' and block_row_number not in (8,9); + +update staging2.budni_hdl_Test_Obs_Summary_Block a + set column3= b.first_value from (SELECT +block_row_number, column3, value_partition, first_value(column3) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column3, +sum(case when column3 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.budni_hdl_Test_Obs_Summary_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + +update staging2.budni_hdl_Test_Obs_Summary_Block a + set column4= b.first_value from (SELECT +block_row_number, column4, value_partition, first_value(column4) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column4, +sum(case when column4 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.budni_hdl_Test_Obs_Summary_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + +update staging2.budni_hdl_Test_Obs_Summary_Block a + set column5= b.first_value from (SELECT +block_row_number, column5, value_partition, first_value(column5) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column5, +sum(case when column5 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.budni_hdl_Test_Obs_Summary_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + +update staging2.budni_hdl_Test_Obs_Summary_Block a + set column7= b.first_value from (SELECT +block_row_number, column7, value_partition, first_value(column7) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column7, +sum(case when column7 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.budni_hdl_Test_Obs_Summary_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + +update staging2.budni_hdl_Test_Obs_Summary_Block a + set column8= b.first_value from (SELECT +block_row_number, column8, value_partition, first_value(column8) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column8, +sum(case when column8 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.budni_hdl_Test_Obs_Summary_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + +update staging2.budni_hdl_Test_Obs_Summary_Block a + set column11= b.first_value from (SELECT +block_row_number, column11, value_partition, first_value(column11) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column11, +sum(case when column11 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.budni_hdl_Test_Obs_Summary_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + + +update staging2.budni_hdl_Test_Obs_Summary_Block a + set column12= b.first_value from (SELECT +block_row_number, column12, value_partition, first_value(column12) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +column12, +sum(case when column12 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.budni_hdl_Test_Obs_Summary_Block +ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + + + +select column4 into __characteristic_A +from staging2.budni_hdl_Test_Obs_Summary_Block where block_row_number=3; + +update staging2.budni_hdl_Test_Obs_Summary_Block +set column4=concat(column4,'. ',__characteristic_A,' -',column5) where trx_record =1; + + + +update staging2.budni_hdl_Test_Obs_Summary_Block set make=__make,model=__model; +execute 'update staging2.budni_hdl_Test_Obs_Summary_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +update staging2.budni_hdl_Test_Obs_Summary_Block +set trx_record=0 where +block_row_number in (1,2,3); + +perform fw_core.fn_jobctl_block_end(__file_syspk,'budni_hdl_Test_Obs_Summary_Block'); + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_budni_hdl_Block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + + + diff --git a/onetime/dataloadfunctions/budni/BUDNI_HLG_ODS.sql b/onetime/dataloadfunctions/budni/BUDNI_HLG_ODS.sql new file mode 100755 index 0000000..04387f9 --- /dev/null +++ b/onetime/dataloadfunctions/budni/BUDNI_HLG_ODS.sql @@ -0,0 +1,259 @@ +drop function if exists staging2.fn_budni_hlg_TRX; +CREATE OR REPLACE FUNCTION staging2.fn_budni_hlg_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + declare __test_instance_tractor_id int; + begin +__file_syspk := p_file_syspk; + +/************************************************************ +Function Name:fn_BUDNI_HLG_TRX +Function Desc: This function populates data into ODS +File Format: BUDNI +Sheet Format: BUDNI_HLG +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_BUDNI_HLG_TRX() +***************************************************************/ + +/*select file_syspk into __file_syspk from staging2.BUDNI_HLG_Spec_H1_block; */ + +insert into transactional.test_instance_tractor_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +tractor_engine_hp, +configuration, +transmission_type, +wheel_drive_type, +fip_type, +steering_type, +ballast_condition +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make, +model, +tractor_HP::int tractor_engine_hp, +configuration, +transmission_type, +wheel_drive_type, +FIP_type, +steering_type, +Ballast_Condition +from staging2.budni_hlg_Spec_H1_block; + +update transactional.test_instance_tractor_info +set mahindra_model_yn = ( +case when tractor_make like 'Mahindra%' then 'Y' else 'N' end +) where file_syspk =__file_syspk; + +update transactional.test_instance_tractor_info a +set test_tractor_yn ='Y' where syspk in +(select min(syspk) from transactional.test_instance_tractor_info b +where b.file_syspk =a.file_syspk) +and a.file_syspk =__file_syspk; + +insert into transactional.test_instance +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +type_of_road +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +type_of_track +from + staging2.budni_hlg_Spec_H1_block; + + insert into transactional.test_instance_engine_info + ( + client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +rated_rpm, +engine_to_pto_ratio_540_pto +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +rated_rpm::int, +engine_to_pto_ratio engine_to_pto_ratio_540_pto +from staging2.budni_hlg_Spec_H1_block; + + +/*block */ + +insert into transactional.budni_haulage_perf_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +trailer_type, +gross_mass_of_trailer_tonne, +height_of_trailer_hitch_above_ground_level_mm, +gear_used_negotiating_slopes_up_to_8pct, +avg_travel_speed_kmph, +avg_fuel_consumption_ltr_per_hr, +avg_fuel_consumption_ml_per_km_per_tonne, +avg_dist_traveled_per_litre_of_fuel_consumption_km, +effectiveness_of_brakes, +maneuverability_of_tractor_trailer_combination +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +type_of_trailer, +Gross_mass_of_trailer_tonne::numeric, +Height_of_trailer_hitch_above_ground_level_mm::numeric, +Gear_used_during_the_test_for_negotiating_slopes_up_to_8, +Average_travel_speed_kmph, +l_h, +ml_km_tonne, +Average_distance_traveled_per_litre_of_fuel_consumption_km, +Effectiveness_of_brakes, +Maneuverability_of_tractor_trailer_combination +from staging2.BUDNI_HLG_Perf_Test_block where trx_record=1 +order by block_row_number; + + + +insert into transactional.budni_test_observations +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +sequence_number , +characteristic, +category_evaluative_or_non_evaluative, +requirements_as_per_is_12207_2008, +values_declared_by_the_applicant_d_rqmt, +as_observed, +whether_meets_the_requirements_yn +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column3::numeric , +column4, +column5, +column6, +column7, +column8, +column9 +from staging2.budni_hlg_test_obs_summary_block where trx_record=1; + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk; +select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk; +select syspk from transactional.test_master into __test_master_id where test_type ='BUDNI'; +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk; + + +update transactional.test_instance +set test_master_id =__test_master_id, +test_tractor_id =__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.test_instance_engine_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + + +update transactional.budni_haulage_perf_results +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.budni_test_observations +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_budni_hlg_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + + diff --git a/onetime/dataloadfunctions/budni/BUDNI_HLG_STG2.sql b/onetime/dataloadfunctions/budni/BUDNI_HLG_STG2.sql new file mode 100755 index 0000000..11ed532 --- /dev/null +++ b/onetime/dataloadfunctions/budni/BUDNI_HLG_STG2.sql @@ -0,0 +1,407 @@ +drop function if exists staging2.fn_BUDNI_HLG_Block ; +CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_HLG_Block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + DECLARE __characteristic_1 text; + DECLARE __characteristic_2 text; + DECLARE __characteristic_3 text; + begin + + + +/*********************************************************************************** +Function Name:fn_BUDNI_HLG_Block +Function Desc: This function populates data into staging2 blocks +File Format: BUDNI +Sheet Format: BUDNI_HLG +Creation Date: March 21 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_BUDNI_HLG_Block(20,1,'BUDNI','BUDNI_HLG',261); +************************************************************************************/ + +SET search_path TO staging2; + +/* rerunnability - delete block tables and update config tables to null */ +truncate table staging2.BUDNI_HLG_Spec_H1_Block; +truncate table staging2.BUDNI_HLG_Perf_Test_int; +truncate table staging2.BUDNI_HLG_Perf_Test_block; +truncate table staging2.BUDNI_HLG_Test_Obs_Summary_Block; +truncate table staging2.stg_specific_table_BUDNI_HLG; +truncate table staging2.stg_process_table_BUDNI_HLG; + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* transfer data from generic to specific for BUDNI */ +execute 'insert into staging2.stg_specific_table_BUDNI_HLG +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_BUDNI_HLG; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for Budni HLG', + detail = 'No data in table stg_specific_table_BUDNI_HLG', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + +update transactional.source_config set F1_source=F1_modified; + + +/* reverese update in process table for match*/ +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_BUDNI_HLG b +where trim(upper(F1_source))= trim(upper(column3)) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* update config files for row numbers start, end */ +execute 'update staging2.stg_specific_table_BUDNI_HLG a +set is_rownumber_fetched=1 +from transactional.source_config b +where trim(upper(F1_source))= trim(upper(column3)) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a +set row_read_end = null +where f1_modified =''Haulage Performance Test Observations Summary'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set run_time=current_timestamp +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers for each block in process table*/ +execute 'insert into staging2.stg_process_table_BUDNI_HLG +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_BUDNI_HLG a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Tractor Specifiactions'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + + + +execute 'insert into staging2.stg_process_table_BUDNI_HLG +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_BUDNI_HLG a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Haulage performance Test'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + + +execute 'insert into staging2.stg_process_table_BUDNI_HLG +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_BUDNI_HLG a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Haulage Performance Test Observations Summary'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +/* fetching tractor model and make */ +select column3 into __make from staging2.stg_process_table_BUDNI_HLG a +where block_tag='BUDNI_HLG_Spec_H1' and block_row_number=3; + +select column4 into __model from staging2.stg_process_table_BUDNI_HLG a +where block_tag='BUDNI_HLG_Spec_H1' and block_row_number=3; + + +/* blocks data loading start - BUDNI_HLG_Spec_H1_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_HLG_Spec_H1_block',__file_mnemonic,__file_sheet_mnemonic,1); +err_block:='BUDNI_HLG_Spec_H1_block'; +insert into staging2.BUDNI_HLG_Spec_H1_block +( +make,model,tractor_HP,rated_rpm,configuration,transmission_type,wheel_drive_type,block_row_number) +select column3,column4,column5,column6,column7,column8,column9,block_row_number +from staging2.stg_process_table_BUDNI_HLG where block_tag='BUDNI_HLG_Spec_H1' +and block_row_number=3; + + +execute 'update staging2.BUDNI_HLG_Spec_H1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +update staging2.BUDNI_HLG_Spec_H1_block a +set FIP_type=column3,steering_type=column4,Engine_to_PTO_ratio= column5,Ballast_Condition=column6, +Test_Engine_Set_RPM=column7,Type_of_track=column8 +from staging2.stg_process_table_BUDNI_HLG b +where b.block_tag='BUDNI_HLG_Spec_H1' +and b.block_row_number=5 +and a.file_syspk=b.file_syspk; + + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_HLG_Spec_H1_block'); + +insert into staging2.BUDNI_HLG_Perf_Test_int +( +column3,column6,column8,block_row_number +) +select +column3,column6,column8,block_row_number +from staging2.stg_process_table_BUDNI_HLG a +where block_tag ='BUDNI_HLG_Perf_Test' +order by block_row_number,column3; + +update staging2.BUDNI_HLG_Perf_Test_int set trx_record=0 where block_row_number =1; + +update staging2.BUDNI_HLG_Perf_Test_int set make=__make,model=__model; +execute 'update staging2.BUDNI_HLG_Perf_Test_int set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* blocks data loading - BUDNI_HLG_perf_test_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_HLG_perf_test_block',__file_mnemonic,__file_sheet_mnemonic,2); + +err_block:='BUDNI_HLG_perf_test_block'; + +insert into staging2.BUDNI_HLG_perf_test_block +( +dummy_f, +type_of_trailer, +Gross_mass_of_trailer_tonne, +Height_of_trailer_hitch_above_ground_level_mm, +Gear_used_during_the_test_for_negotiating_slopes_up_to_8, +Average_travel_speed_kmph, +Average_fuel_consumption, +l_h, +ml_km_tonne, +Average_distance_traveled_per_litre_of_fuel_consumption_km, +General_observations, +Effectiveness_of_brakes, +Maneuverability_of_tractor_trailer_combination +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column6,column8}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column6::text,column8::text]) AS val + FROM staging2.BUDNI_HLG_Perf_Test_int where trx_record=1 + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text, + a_11 text,a_12 text); + +delete from staging2.BUDNI_HLG_Perf_Test_block where dummy_f is null; +update staging2.BUDNI_HLG_Perf_Test_block set make=__make,model=__model; +execute 'update staging2.BUDNI_HLG_Perf_Test_block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_HLG_perf_test_block'); + + +/* blocks data loading -BUDNI_HLG_Test_Obs_Summary_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_HLG_Test_Obs_Summary_Block',__file_mnemonic,__file_sheet_mnemonic,3); + +err_block:='BUDNI_HLG_Test_Obs_Summary_Block'; + +insert into staging2.BUDNI_HLG_Test_Obs_Summary_Block +( +column3,column4,column5,column6,column7, +column8,column9,block_row_number +) +select +column3,column4,column5,column6,column7, +column8,column9,block_row_number +from staging2.stg_process_table_BUDNI_HLG a +where block_tag='BUDNI_HLG_Test_Obs_Summary' and block_row_number <=11 +order by block_row_number; + + +update staging2.BUDNI_HLG_Test_Obs_Summary_Block a +set column3= b.first_value from (SELECT + block_row_number, column3, value_partition, first_value(column3) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + column3, + sum(case when column3 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.BUDNI_HLG_Test_Obs_Summary_Block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + + +update staging2.BUDNI_HLG_Test_Obs_Summary_Block a +set column5= b.first_value from (SELECT + block_row_number, column5, value_partition, first_value(column5) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + column5, + sum(case when column5 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.BUDNI_HLG_Test_Obs_Summary_Block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + + + +--update staging2.BUDNI_HLG_Test_Obs_Summary_Block a +--set column7= b.first_value from (SELECT +-- block_row_number, column7, value_partition, first_value(column7) over (partition by value_partition order by block_row_number) +--FROM ( +-- SELECT +-- block_row_number, +-- column7, +-- sum(case when column7 is null then 0 else 1 end) over (order by block_row_number) as value_partition +-- FROM staging2.BUDNI_HLG_Test_Obs_Summary_Block +-- ORDER BY block_row_number ASC +--) as q) b where a.block_row_number = b.block_row_number ; +-- +-- +--update staging2.BUDNI_HLG_Test_Obs_Summary_Block a +--set column8= b.first_value from (SELECT +-- block_row_number, column8, value_partition, first_value(column8) over (partition by value_partition order by block_row_number) +--FROM ( +-- SELECT +-- block_row_number, +-- column8, +-- sum(case when column8 is null then 0 else 1 end) over (order by block_row_number) as value_partition +-- FROM staging2.BUDNI_HLG_Test_Obs_Summary_Block +-- ORDER BY block_row_number ASC +--) as q) b where a.block_row_number = b.block_row_number ; + + +--update staging2.BUDNI_HLG_Test_Obs_Summary_Block a +--set column9= b.first_value from (SELECT +-- block_row_number, column9, value_partition, first_value(column9) over (partition by value_partition order by block_row_number) +--FROM ( +-- SELECT +-- block_row_number, +-- column9, +-- sum(case when column9 is null then 0 else 1 end) over (order by block_row_number) as value_partition +-- FROM staging2.BUDNI_HLG_Test_Obs_Summary_Block +-- ORDER BY block_row_number ASC +--) as q) b where a.block_row_number = b.block_row_number ; + +update staging2.BUDNI_HLG_Test_Obs_Summary_Block +set trx_record=0 where +block_row_number in +(select distinct first_value(b.block_row_number) +over (partition by b.column3 order by b.syspk) from staging2.BUDNI_HLG_Test_Obs_Summary_Block b); + + + +select column4 into __characteristic_1 from staging2.BUDNI_HLG_Test_Obs_Summary_Block +where block_row_number=3; + + +select column4 into __characteristic_2 from staging2.BUDNI_HLG_Test_Obs_Summary_Block +where block_row_number=6; + + +select column4 into __characteristic_3 from staging2.BUDNI_HLG_Test_Obs_Summary_Block +where block_row_number=9; + + +update staging2.BUDNI_HLG_Test_Obs_Summary_Block +set column4=concat(__characteristic_1,'-',column4) where block_row_number=4; + + +update staging2.BUDNI_HLG_Test_Obs_Summary_Block +set column4=concat(__characteristic_1,'-',column4) where block_row_number=5; + + +update staging2.BUDNI_HLG_Test_Obs_Summary_Block +set column4=concat(__characteristic_2,'-',column4) where block_row_number=7; + + +update staging2.BUDNI_HLG_Test_Obs_Summary_Block +set column4=concat(__characteristic_2,'-',column4) where block_row_number=8; + + +update staging2.BUDNI_HLG_Test_Obs_Summary_Block +set column4=concat(__characteristic_3,'-',column4) where block_row_number=10; + + +update staging2.BUDNI_HLG_Test_Obs_Summary_Block +set column4=concat(__characteristic_3,'-',column4) where block_row_number=11; + + +update staging2.BUDNI_HLG_Test_Obs_Summary_Block set make=__make,model=__model; +execute 'update staging2.BUDNI_HLG_Test_Obs_Summary_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_HLG_Test_Obs_Summary_Block'); + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_BUDNI_HLG_Block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + + + diff --git a/onetime/dataloadfunctions/budni/BUDNI_LCG_ODS.sql b/onetime/dataloadfunctions/budni/BUDNI_LCG_ODS.sql new file mode 100755 index 0000000..b03c96e --- /dev/null +++ b/onetime/dataloadfunctions/budni/BUDNI_LCG_ODS.sql @@ -0,0 +1,202 @@ +drop function if exists staging2.fn_BUDNI_LCG_TRX ; +CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_LCG_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + declare __test_instance_tractor_id int; + begin +__file_syspk := p_file_syspk; + +/************************************************************ +Function Name:fn_BUDNI_LCG_TRX +Function Desc: This function populates data into ODS +File Format: BUDNI +Sheet Format: BUDNI_LCG +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_BUDNI_LCG_TRX() +***************************************************************/ + + insert into transactional.test_instance_tractor_info + ( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +tractor_engine_hp, +configuration, +transmission_type, +wheel_drive_type, +wheel_base_mm, +wheel_track_mm, +overall_height_mm, +ballast_condition, +weight_reactions_front_kg, +weight_reactions_rear_kg + ) + select + client_id, +function_id, +file_syspk , +file_mnemonic, +file_sheet_mnemonic, +make, +model, +Tractor_HP::int tractor_engine_hp, +configuration, +Transmission_type, +Wheel_Drive_type, +Wheel_Base::int wheel_base_mm, +wheel_track::int wheel_track_mm, +overall_height::int, +Ballast_Condition, +Tractor_Weight_reactions_Front::int weight_reactions_front_kg , +Tractor_Weight_reactions_Rear::int weight_reactions_rear_kg +from staging2.BUDNI_LCG_Spec_H1_Block where trx_record =1 ; + +update transactional.test_instance_tractor_info +set mahindra_model_yn = ( +case when tractor_make like 'Mahindra%' then 'Y' else 'N' end +) where file_syspk =__file_syspk; + +update transactional.test_instance_tractor_info a +set test_tractor_yn ='Y' where syspk in +(select min(syspk) from transactional.test_instance_tractor_info b +where b.file_syspk =a.file_syspk) +and a.file_syspk =__file_syspk; + + insert into transactional.test_instance + ( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model + ) + select + client_id, +function_id, +file_syspk , +file_mnemonic, +file_sheet_mnemonic, +make, +model + from staging2.BUDNI_LCG_Spec_H1_Block where trx_record =1 ; + +insert into transactional.test_instance_engine_info + ( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +Rated_RPM +) + select + client_id, +function_id, +file_syspk , +file_mnemonic, +file_sheet_mnemonic, +make, +model, +rated_rpm::int +from staging2.BUDNI_LCG_Spec_H1_Block where trx_record =1 ; + + +insert into transactional.budni_centre_of_gravity_location +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +condition, +particulars, +coordinates +) +select +client_id, +function_id, +file_syspk , +file_mnemonic, +file_sheet_mnemonic, +make, +model, +column3, +column6, +column8 +from staging2.budni_lcg_gravity_test_block where trx_record=1; + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk; +select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk; +select syspk from transactional.test_master into __test_master_id where test_type ='BUDNI'; +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk; + + +update transactional.test_instance +set test_master_id =__test_master_id, +test_tractor_id =__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.test_instance_engine_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.budni_centre_of_gravity_location +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_BUDNI_LCG_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + + + + diff --git a/onetime/dataloadfunctions/budni/BUDNI_LCG_STG2.sql b/onetime/dataloadfunctions/budni/BUDNI_LCG_STG2.sql new file mode 100755 index 0000000..60f21df --- /dev/null +++ b/onetime/dataloadfunctions/budni/BUDNI_LCG_STG2.sql @@ -0,0 +1,238 @@ +drop function if exists staging2.fn_BUDNI_LCG_Block ; +CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_LCG_Block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + + begin + +/*********************************************************************************** +Function Name:fn_BUDNI_LCG_Block +Function Desc: This function populates data into staging2 blocks +File Format: BUDNI +Sheet Format:BUDNI_LCG +Creation Date: March 21 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_BUDNI_LCG_Block(20,1,'BUDNI','BUDNI_LCG',261); +************************************************************************************/ + +SET search_path TO staging2; + +/* rerunnability - delete block tables and update config tables to null */ +truncate table staging2.BUDNI_LCG_Spec_H1_Block; +truncate table staging2.BUDNI_LCG_Gravity_Test_Block; +truncate table staging2.stg_specific_table_BUDNI_LCG; +truncate table staging2.stg_process_table_BUDNI_LCG; + + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/* transfer data from generic to specific for BUDNI */ +execute 'insert into staging2.stg_specific_table_BUDNI_LCG +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_BUDNI_LCG; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for Budni LCG', + detail = 'No data in table stg_specific_table_BUDNI_LCG', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + +update transactional.source_config set F1_source=F1_modified; + + +/* keyword match in config table*/ +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_BUDNI_LCG b +where upper(F1_source)= upper(column3) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update in process table for match*/ +execute 'update staging2.stg_specific_table_BUDNI_LCG a +set is_rownumber_fetched=1 +from transactional.source_config b +where upper(F1_source)= upper(column3) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* update config files for row numbers start, end */ +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a +set row_read_end = null +where f1_modified =''Location of centre of Gravity Test'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set run_time=current_timestamp +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers for each block in process table*/ +execute 'insert into staging2.stg_process_table_BUDNI_LCG +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_BUDNI_LCG a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Tractor Specifiactions'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + + +execute 'insert into staging2.stg_process_table_BUDNI_LCG +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_BUDNI_LCG a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Location of centre of Gravity Test'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + + +/* fetching tractor model and make */ +select column3 into __make from staging2.stg_process_table_BUDNI_LCG a +where block_tag='BUDNI_LCG_Spec_H1' and block_row_number=3; + +select column4 into __model from staging2.stg_process_table_BUDNI_LCG a +where block_tag='BUDNI_LCG_Spec_H1' and block_row_number=3; + + + +/* blocks data loading start - BUDNI_LCG_Spec_H1_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_LCG_Spec_H1_Block',__file_mnemonic,__file_sheet_mnemonic,1); +err_block:='BUDNI_LCG_Spec_H1_Block'; +insert into staging2.BUDNI_LCG_Spec_H1_Block +( +make,model,Tractor_HP, Rated_RPM,configuration,Transmission_type, +Wheel_Drive_type,block_row_number +) +select +column3,column4,column5,column6,column7,column8,column9,block_row_number +from staging2.stg_process_table_BUDNI_LCG +where block_tag='BUDNI_LCG_Spec_H1' and block_row_number=3; + + +execute 'update staging2.BUDNI_LCG_Spec_H1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +update staging2.BUDNI_LCG_Spec_H1_block a +set Wheel_Base=column3, +Wheel_track =column4, +Overall_height =column5, +Ballast_Condition =column6, +Tractor_Weight_reactions_Front =column7, +Tractor_Weight_reactions_Rear =column8 +from staging2.stg_process_table_budni_lcg b +where b.block_tag='BUDNI_LCG_Spec_H1' +and b.block_row_number=6 +and a.file_syspk=b.file_syspk; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_LCG_Spec_H1_Block'); + + +/* blocks data loading -BUDNI_LCG_Gravity_Test_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_LCG_Gravity_Test_Block',__file_mnemonic,__file_sheet_mnemonic,2); +err_block:='BUDNI_LCG_Gravity_Test_Block'; + +insert into staging2.BUDNI_LCG_Gravity_Test_Block +( +column2,column3,column4,column5,column6,column7, +column8,block_row_number +) +select +column2,column3,column4,column5,column6,column7, +column8,block_row_number +from staging2.stg_process_table_BUDNI_LCG a +where block_tag='BUDNI_LCG_Gravity_Test' and block_row_number <=5 +order by block_row_number; + + +update staging2.BUDNI_LCG_Gravity_Test_Block set make=__make,model=__model; +execute 'update staging2.BUDNI_LCG_Gravity_Test_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +update staging2.BUDNI_LCG_Gravity_Test_Block a +set column3= b.first_value from (SELECT + block_row_number, column3, value_partition, first_value(column3) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + column3, + sum(case when column3 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.BUDNI_LCG_Gravity_Test_Block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + +update staging2.BUDNI_LCG_Gravity_Test_Block +set trx_record=0 where +block_row_number in (1,2); + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_LCG_Gravity_Test_Block'); + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_BUDNI_LCG_Block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + diff --git a/onetime/dataloadfunctions/budni/BUDNI_NMT_ODS.sql b/onetime/dataloadfunctions/budni/BUDNI_NMT_ODS.sql new file mode 100755 index 0000000..5f0346a --- /dev/null +++ b/onetime/dataloadfunctions/budni/BUDNI_NMT_ODS.sql @@ -0,0 +1,351 @@ +drop function if exists staging2.fn_BUDNI_NMT_TRX; +CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_NMT_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + declare __test_instance_tractor_id int; + begin +__file_syspk := p_file_syspk; + +/************************************************************ +Function Name:fn_BUDNI_NMT_TRX +Function Desc: This function populates data into ODS +File Format: BUDNI +Sheet Format: BUDNI_NMT +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_BUDNI_NMT_TRX() +***************************************************************/ + + +insert into transactional.test_instance_tractor_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +tractor_engine_hp, +configuration, +transmission_type, +wheel_drive_type, +fip_type, +steering_type, +ballast_condition +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make, +model, +tractor_HP::int tractor_engine_hp, +configuration, +transmission_type, +wheel_drive_type, +FIP_type, +steering_type, +Ballast_Condition +from staging2.BUDNI_NMT_Spec_H1_block; + +insert into transactional.test_instance +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +type_of_road +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +type_of_track +from + staging2.BUDNI_NMT_Spec_H1_block; + +update transactional.test_instance_tractor_info +set mahindra_model_yn = ( +case when tractor_make like 'Mahindra%' then 'Y' else 'N' end +) where file_syspk =__file_syspk; + +update transactional.test_instance_tractor_info a +set test_tractor_yn ='Y' where syspk in +(select min(syspk) from transactional.test_instance_tractor_info b +where b.file_syspk =a.file_syspk) +and a.file_syspk =__file_syspk; + + + insert into transactional.test_instance_engine_info + ( + client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +rated_rpm, +engine_to_pto_ratio_540_pto +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +rated_rpm::int, +engine_to_pto_ratio engine_to_pto_ratio_540_pto +from staging2.BUDNI_NMT_Spec_H1_block; + + +/*block */ + +insert into transactional.budni_noise_atmospheric_conditions +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +noise_position, +background_noise_level_dba, +temperature_c, +pressure_kpa, +relative_humidity_pct, +wind_velocity_ms +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column2, +column3::numeric, +column4::numeric, +column5::numeric, +column6::numeric, +column7::numeric +from staging2.BUDNI_NMT_Atmos_Cond_1_Block where trx_record=1 +order by block_row_number; + + + +/*block */ +insert into transactional.budni_noise_measurement_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +noise_position, +gear, +travel_speed_km_per_hr, +noise_level_db_a +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column2, +column3, +column6, +column8::numeric +from staging2.BUDNI_NMT_Meas_Results_1_Block +where trx_record=1; + +insert into transactional.budni_noise_atmospheric_conditions +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +noise_position, +background_noise_level_dba, +temperature_c, +pressure_kpa, +relative_humidity_pct, +wind_velocity_ms +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column2, +column3::numeric, +column4::numeric, +column5::numeric , +column6::numeric, +column7::numeric +from staging2.BUDNI_NMT_Atmos_Cond_2_Block where trx_record=1 +order by block_row_number; + + + +/*block */ +insert into transactional.budni_noise_measurement_results +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +noise_position, +gear, +drawbar_pull_max_noise_kn, +travel_speed_km_per_hr, +noise_level_db_a +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column2, +column3, +column4, +column6, +column8::int +from staging2.BUDNI_NMT_Meas_Results_2_Block +where trx_record=1; + +insert into transactional.budni_test_observations +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +sequence_number, +characteristic, +category_evaluative_or_non_evaluative, +requirements_as_per_is_12207_2008, +values_declared_by_the_applicant_d_rqmt, +as_observed, +whether_meets_the_requirements_yn +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column3::numeric, +column4, +column5, +column6, +column7, +column8, +column9 +from staging2.budni_nmt_test_obs_summary_block where trx_record=1; + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk; +select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk; +select syspk from transactional.test_master into __test_master_id where test_type ='BUDNI'; +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk; + + +update transactional.test_instance +set test_master_id =__test_master_id, +test_tractor_id =__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.test_instance_engine_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.budni_noise_atmospheric_conditions +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.budni_noise_measurement_results +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.budni_test_observations +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_BUDNI_NMT_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + + diff --git a/onetime/dataloadfunctions/budni/BUDNI_NMT_STG2.sql b/onetime/dataloadfunctions/budni/BUDNI_NMT_STG2.sql new file mode 100755 index 0000000..e2b9a15 --- /dev/null +++ b/onetime/dataloadfunctions/budni/BUDNI_NMT_STG2.sql @@ -0,0 +1,469 @@ +drop function if exists staging2.fn_BUDNI_NMT_Block ; +CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_NMT_Block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + + begin + +SET search_path TO staging2; + +/*********************************************************************************** +Function Name:fn_BUDNI_NMT_Block +Function Desc: This function populates data into staging2 blocks +File Format: BUDNI +Sheet Format:BUDNI_NMT +Creation Date: March 21 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_BUDNI_NMT_Block(20,1,'BUDNI','BUDNI_NMT',261); +************************************************************************************/ + + +/* rerunnability - delete block tables and update config tables to null */ +truncate table staging2.BUDNI_NMT_Spec_H1_Block; +truncate table staging2.BUDNI_NMT_noise_at_bystander_position_block; +truncate table staging2.BUDNI_NMT_Atmos_Cond_1_Block; +truncate table staging2.BUDNI_NMT_Meas_Results_1_Block; +truncate table staging2.BUDNI_NMT_noise_at_operator_ear_level_block; +truncate table staging2.BUDNI_NMT_Atmos_Cond_2_Block; +truncate table staging2.BUDNI_NMT_Meas_Results_2_Block; +truncate table staging2.BUDNI_NMT_Test_Obs_Summary_Block; +truncate table staging2.stg_specific_table_BUDNI_NMT; +truncate table staging2.stg_process_table_BUDNI_NMT; + + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* transfer data from generic to specific for BUDNI */ +execute 'insert into staging2.stg_specific_table_BUDNI_NMT +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_BUDNI_NMT; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for budni nmt', + detail = 'No data in table stg_specific_table_BUDNI_NMT', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + +update transactional.source_config set F1_source=F1_modified; + +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_BUDNI_NMT b +where upper(F1_source)= upper(column3) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update in process table for match*/ +execute 'update staging2.stg_specific_table_BUDNI_NMT a +set is_rownumber_fetched=1 +from transactional.source_config b +where upper(F1_source)= upper(column3) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a +set row_read_end = null +where f1_modified =''Noise Measurement Test Observations Summary'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set run_time=current_timestamp +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers for each block in process table*/ +execute 'insert into staging2.stg_process_table_BUDNI_NMT +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_BUDNI_NMT a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Tractor Specifiactions'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + + + +execute 'insert into staging2.stg_process_table_BUDNI_NMT +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_BUDNI_NMT a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Noise at bystander’s position: Noise Measurement Test'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +execute 'insert into staging2.stg_process_table_BUDNI_NMT +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_BUDNI_NMT a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Noise at operator’s ear level: Noise Measurement Test'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + +execute 'insert into staging2.stg_process_table_BUDNI_NMT +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_BUDNI_NMT a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Noise Measurement Test Observations Summary'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +/* fetching tractor model and make */ +select column3 into __make from staging2.stg_process_table_BUDNI_NMT a +where block_tag='BUDNI_NMT_Spec_H1' and block_row_number=3; + +select column4 into __model from staging2.stg_process_table_BUDNI_NMT a +where block_tag='BUDNI_NMT_Spec_H1' and block_row_number=3; + + + +/* blocks data loading start - BUDNI_NMT_Spec_H1_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_NMT_Spec_H1_block',__file_mnemonic,__file_sheet_mnemonic,1); +err_block:='BUDNI_NMT_Spec_H1_block'; + +insert into staging2.BUDNI_NMT_Spec_H1_block +( +make,model,tractor_HP,rated_rpm,configuration,transmission_type,wheel_drive_type,block_row_number) +select column3,column4,column5,column6,column7,column8,column9,block_row_number +from staging2.stg_process_table_BUDNI_NMT where block_tag='BUDNI_NMT_Spec_H1' +and block_row_number=3; + + +execute 'update staging2.BUDNI_NMT_Spec_H1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +update staging2.BUDNI_NMT_Spec_H1_block a +set FIP_type=column3,steering_type=column4,Engine_to_PTO_ratio= column5,Ballast_Condition=column6, +Test_Engine_Set_RPM=column7,Type_of_track=column8 +from staging2.stg_process_table_BUDNI_NMT b +where b.block_tag='BUDNI_NMT_Spec_H1' +and b.block_row_number=5 +and a.file_syspk=b.file_syspk; + + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_NMT_Spec_H1_Block'); + + +/* blocks data loading - BUDNI_NMT_noise_at_bystander_position_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_NMT_noise_at_bystander_position_block',__file_mnemonic,__file_sheet_mnemonic,2); +err_block:='BUDNI_NMT_noise_at_bystander_position_block'; +insert into staging2.BUDNI_NMT_noise_at_bystander_position_block +( +column2,column3,column4,column5,column6,column7, +column8,column9,block_row_number +) +select +column2,column3,column4,column5,column6,column7, +column8,column9,block_row_number +from staging2.stg_process_table_BUDNI_NMT a +where block_tag ='BUDNI_NMT_Noise_at_bystander_position'; + + +update staging2.BUDNI_NMT_noise_at_bystander_position_block +set column2=column3 where block_row_number=1; + + +update staging2.BUDNI_NMT_noise_at_bystander_position_block a +set column2= b.first_value from (SELECT + block_row_number, column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + column2, + sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.BUDNI_NMT_noise_at_bystander_position_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + +update staging2.BUDNI_NMT_noise_at_bystander_position_Block +set trx_record=0 where block_row_number in(1,2); + + +update staging2.BUDNI_NMT_noise_at_bystander_position_block set make=__make,model=__model; +execute 'update staging2.BUDNI_NMT_noise_at_bystander_position_block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_NMT_noise_at_bystander_position_block'); + + +/* blocks data loading - BUDNI_NMT_Atmos_Cond_1_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_NMT_Atmos_Cond_1_Block',__file_mnemonic,__file_sheet_mnemonic,3); +err_block:='BUDNI_NMT_Atmos_Cond_1_Block'; +insert into staging2.BUDNI_NMT_Atmos_Cond_1_Block +( +column2,column3,column4,column5,column6,column7, +column8,column9,block_row_number +) +select +column2,column3,column4,column5,column6,column7, +column8,column9,block_row_number +from staging2.BUDNI_NMT_noise_at_bystander_position_block a +where block_row_number <=4; + + +update staging2.BUDNI_NMT_Atmos_Cond_1_Block set make=__make,model=__model; +execute 'update staging2.BUDNI_NMT_Atmos_Cond_1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +update staging2.BUDNI_NMT_Atmos_Cond_1_Block +set trx_record=0 where +block_row_number in (1,2,3); + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_NMT_Atmos_Cond_1_Block '); + + + +/* blocks data loading - BUDNI_NMT_Meas_Results_1_Block */ + + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_NMT_Meas_Results_1_Block',__file_mnemonic,__file_sheet_mnemonic,4); +err_block:='BUDNI_NMT_Meas_Results_1_Block'; +insert into staging2.BUDNI_NMT_Meas_Results_1_Block +( +column2,column3,column4,column5,column6,column7, +column8,block_row_number +) +select +column2,column3,column4,column5,column6,column7, +column8,block_row_number +from staging2.BUDNI_NMT_noise_at_bystander_position_block a +where block_row_number>4; + + +update staging2.BUDNI_NMT_Meas_Results_1_Block +set trx_record=0 where +block_row_number=5; + + +update staging2.BUDNI_NMT_Meas_Results_1_Block +set column3=column4 where column3 is null ; + +update staging2.BUDNI_NMT_Meas_Results_1_Block set make=__make,model=__model; +execute 'update staging2.BUDNI_NMT_Meas_Results_1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_NMT_Meas_Results_1_Block '); + + +/* blocks data loading - BUDNI_NMT_Noise_at_operator_ear_level_block */ + + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_NMT_Noise_at_operator_ear_level_block',__file_mnemonic,__file_sheet_mnemonic,5); +err_block:='BUDNI_NMT_Noise_at_operator_ear_level_block'; + +insert into staging2.BUDNI_NMT_Noise_at_operator_ear_level_block +( +column2,column3,column4,column5,column6,column7, +column8,column9,block_row_number +) +select +column2,column3,column4,column5,column6,column7, +column8,column9,block_row_number +from staging2.stg_process_table_BUDNI_NMT a +where block_tag ='BUDNI_NMT_Noise_at_operator_ear_level'; + +update staging2.BUDNI_NMT_Noise_at_operator_ear_level_block set make=__make,model=__model; +execute 'update staging2.BUDNI_NMT_Noise_at_operator_ear_level_block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +update staging2.BUDNI_NMT_Noise_at_operator_ear_level_block +set column2=column3 where block_row_number=1; + + +update staging2.BUDNI_NMT_Noise_at_operator_ear_level_block a +set column2= b.first_value from (SELECT + block_row_number, column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + column2, + sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.BUDNI_NMT_Noise_at_operator_ear_level_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_NMT_Noise_at_operator_ear_level_block'); + +/* blocks data loading -BUDNI_NMT_Atmos_Cond_2_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_NMT_Atmos_Cond_2_Block',__file_mnemonic,__file_sheet_mnemonic,6); +err_block:='BUDNI_NMT_Atmos_Cond_2_Block'; +insert into staging2.BUDNI_NMT_Atmos_Cond_2_Block +( +column2,column3,column4,column5,column6,column7, +column8,block_row_number +) +select +column2,column3,column4,column5,column6,column7, +column8,block_row_number +from staging2.BUDNI_NMT_Noise_at_operator_ear_level_block a +where block_row_number<=4; + +update staging2.BUDNI_NMT_Atmos_Cond_2_Block set make=__make,model=__model; +execute 'update staging2.BUDNI_NMT_Atmos_Cond_2_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +update staging2.BUDNI_NMT_Atmos_Cond_2_Block +set trx_record=0 where +block_row_number in (1,2,3); + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_NMT_Atmos_Cond_2_Block'); + + +/* blocks data loading -BUDNI_NMT_Meas_Results_2_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_NMT_Meas_Results_2_Block',__file_mnemonic,__file_sheet_mnemonic,7); +err_block:='BUDNI_NMT_Meas_Results_2_Block'; +insert into staging2.BUDNI_NMT_Meas_Results_2_Block +( +column2,column3,column4,column5,column6,column7, +column8,block_row_number +) +select +column2,column3,column4,column5,column6,column7, +column8,block_row_number +from staging2.BUDNI_NMT_Noise_at_operator_ear_level_block a +where block_row_number>4; + +update staging2.BUDNI_NMT_Meas_Results_2_Block +set trx_record=0 where +block_row_number =5; + +update BUDNI_NMT_Meas_Results_2_Block set column3=column4 where column3 is null; + +update staging2.BUDNI_NMT_Meas_Results_2_Block set make=__make,model=__model; +execute 'update staging2.BUDNI_NMT_Meas_Results_2_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_NMT_Meas_Results_2_Block'); + + +/* blocks data loading -BUDNI_NMT_Test_Obs_Summary_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_NMT_Test_Obs_Summary_Block',__file_mnemonic,__file_sheet_mnemonic,8); +err_block:='BUDNI_NMT_Test_Obs_Summary_Block'; + +insert into staging2.BUDNI_NMT_Test_Obs_Summary_Block +( +column2,column3,column4,column5,column6,column7, +column8,column9,block_row_number +) +select +column2,column3,column4,column5,column6,column7, +column8,column9,block_row_number +from staging2.stg_process_table_BUDNI_NMT a +where block_tag='BUDNI_NMT_Test_Obs_Summary' and block_row_number in (1,2,3,4); + +update staging2.BUDNI_NMT_Test_Obs_Summary_Block +set trx_record=0 where +block_row_number in (1,2); + +update staging2.BUDNI_NMT_Test_Obs_Summary_Block set make=__make,model=__model; +execute 'update staging2.BUDNI_NMT_Test_Obs_Summary_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_NMT_Test_Obs_Summary_Block'); + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_BUDNI_NMT_Block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + + + diff --git a/onetime/dataloadfunctions/budni/BUDNI_PTO_ODS.sql b/onetime/dataloadfunctions/budni/BUDNI_PTO_ODS.sql new file mode 100755 index 0000000..b38b741 --- /dev/null +++ b/onetime/dataloadfunctions/budni/BUDNI_PTO_ODS.sql @@ -0,0 +1,315 @@ +drop function if exists staging2.fn_BUDNI_PTO_TRX; +CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_PTO_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + declare __test_instance_tractor_id int; + begin +__file_syspk := p_file_syspk; + +/************************************************************ +Function Name:fn_BUDNI_PTO_TRX +Function Desc: This function populates data into ODS +File Format: BUDNI +Sheet Format: BUDNI_PTO +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_BUDNI_PTO_TRX() +***************************************************************/ + +insert into transactional.test_instance_tractor_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +tractor_engine_hp, +configuration, +fip_type, +steering_type, +transmission_type, +wheel_drive_type +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make, +model, +tractor_HP::int, +configuration,FIP_type,steering_type,transmission_type,wheel_drive_type +from staging2.BUDNI_PTO_Spec_H1_block; + +update transactional.test_instance_tractor_info +set mahindra_model_yn = ( +case when lower(tractor_make) like 'mahindra%' then 'Y' else 'N' end +) where file_syspk =__file_syspk; + +update transactional.test_instance_tractor_info a +set test_tractor_yn ='Y' where syspk in +(select min(syspk) from transactional.test_instance_tractor_info b +where b.file_syspk =a.file_syspk) +and a.file_syspk =__file_syspk; + +insert into transactional.test_instance +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +date_of_test +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +date +from + staging2.BUDNI_PTO_Spec_H1_block where trx_record=1; + + insert into transactional.test_instance_engine_info + ( + client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +rated_rpm, +engine_to_pto_ratio_540_pto +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +rated_rpm::int, +engine_to_pto_ratio +from staging2.BUDNI_PTO_Spec_H1_block where trx_record=1; + + +/*block */ + +insert into transactional.budni_pto_perf_results_summary +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +pto_category, +pto_sub_category , +power_kw, +speed_rpm_pto , +speed_rpm_engine , +fuel_consumption_ltr_per_hr, +fuel_consumption_kg_per_hr, +specific_kg_per_kwh, +specific_energy_kwhl +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column2, +column3, +column4::numeric,column5::numeric,column6::numeric,column7::numeric,column8::numeric, +column9::numeric,column10::numeric +from staging2.BUDNI_PTO_Perf_Report_block where trx_record=1 +order by block_row_number; + + +/*block */ +insert into transactional.budni_pto_perf_results_details +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +ambient_type, +no_load_max_engine_speed_rpm, +equi_crankshaft_torque_at_max_power_nm, +max_equi_crankshaft_torque_nm, +engine_speed_at_max_equi_crankshaft_torque_rpm, +backup_torque, +pct_smoke_level_max_light_absorption_coef_per_mtr, +range_of_atm_conditions_temp_c, +range_of_atm_conditions_pressure_kpa, +range_of_atm_conditions_rel_humidity_pct +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column3, +column4::int, +column5::numeric, +column6::numeric,column7::int,column8::numeric, +column9::numeric,column10,column11,column12 +from staging2.BUDNI_PTO_MMTKeyword1_block +where trx_record=1; + + +/* block */ + +insert into transactional.budni_pto_perf_results_details +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +ambient_type, +max_temp_engine_oil_c, +max_temp_coolant_water_c, +max_temp_fuel_c, +max_temp_air_intake_c, +max_temp_exhaust_gas_c, +pressure_at_max_power_intake_air_kpa, +pressure_at_max_power_exhst_gas_bfr_turbo_charger_kpa, +consumptions_lub_oil_gkwh, +consumptions_coolant_water_pct_of_total_coolant_capacity +) +select client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column3, +column4::numeric,column5::numeric,column6::numeric,column7::numeric,column8::numeric,column9, +column10,column11::numeric,column12::numeric +from staging2.BUDNI_PTO_MMTKeyword2_block +where trx_record=1 and column3='Natural Ambient'; + +insert into transactional.budni_test_observations +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +srl_no, +characteristic, +category_evaluative_or_non_evaluative, +requirements_as_per_is_12207_2008, +values_declared_by_the_applicant_d_rqmt, +as_observed, +whether_meets_the_requirements_yn +) +select client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model,column3,column4,column7,column8,column10,column11,column12 +from staging2.BUDNI_PTO_Summary_block +where block_row_number in (3,4) and trx_record=1 +; + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk; +select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk; +select syspk from transactional.test_master into __test_master_id where test_type ='BUDNI'; +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk; + + +update transactional.test_instance +set test_master_id =__test_master_id, +test_tractor_id =__test_instance_tractor_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_engine_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.budni_pto_perf_results_summary +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +update transactional.budni_pto_perf_results_details +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.budni_test_observations +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_BUDNI_PTO_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + + diff --git a/onetime/dataloadfunctions/budni/BUDNI_PTO_STG2.sql b/onetime/dataloadfunctions/budni/BUDNI_PTO_STG2.sql new file mode 100755 index 0000000..8cff4b6 --- /dev/null +++ b/onetime/dataloadfunctions/budni/BUDNI_PTO_STG2.sql @@ -0,0 +1,363 @@ +drop function if exists staging2.fn_BUDNI_PTO_block; +CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_PTO_block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + + begin + +SET search_path TO staging2; + + +/*********************************************************************************** +Function Name:fn_BUDNI_PTO_Block +Function Desc: This function populates data into staging2 blocks +File Format: BUDNI +Sheet Format:BUDNI_PTO +Creation Date: March 21 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_BUDNI_PTO_Block(20,1,'BUDNI','BUDNI_PTO',261); +************************************************************************************/ + + +/* rerunnability - delete block tables and update config tables to null */ +truncate table staging2.stg_specific_table_BUDNI_PTO; +truncate table staging2.stg_process_table_BUDNI_PTO; +truncate table staging2.BUDNI_PTO_Spec_H1_Block; +truncate table staging2.BUDNI_PTO_Perf_Report_block; +truncate table staging2.BUDNI_PTO_MMTKeyword1_Block; +truncate table staging2.BUDNI_PTO_MMTKeyword2_Block; +truncate table staging2.BUDNI_PTO_Summary_Block; + + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* transfer data from generic to specific for BUDNI */ +execute 'insert into staging2.stg_specific_table_budni_pto +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_budni_pto; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for Budni PTO', + detail = 'No data in table stg_specific_table_budni_pto', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + +/* trimming data */ +update staging2.stg_specific_table_budni_pto set column3 = TRIM (TRAILING FROM column3 ); +update staging2.stg_specific_table_budni_pto set column3 = TRIM (LEADING FROM column3 ); + +update transactional.source_config set F1_source=F1_modified ; + +/* keyword match */ +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_budni_pto b +where trim(upper(F1_modified))=trim(upper(column3)) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update */ +execute 'update staging2.stg_specific_table_budni_pto a +set is_rownumber_fetched=1 +from transactional.source_config b +where trim(upper(F1_modified))=trim(upper(column3)) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a +set row_read_end = null ,run_time=current_timestamp +where f1_modified =''PTO Performance Test Observations Summary'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers for each block in process table*/ +execute 'insert into staging2.stg_process_table_budni_pto +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_budni_pto a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Tractor Specifiactions'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_budni_pto +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_budni_pto a +join transactional.source_config b +on a.row_number >row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''PTO Performance Report'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_budni_pto +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag from staging2.stg_specific_table_budni_pto a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''MMTKeyword1'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_budni_pto +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag from staging2.stg_specific_table_budni_pto a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''MMTKeyword2'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'insert into staging2.stg_process_table_budni_pto +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_budni_pto a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''PTO Performance Test Observations Summary'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/* fetching tractor model and make */ +select column3 into __make from staging2.stg_process_table_budni_pto a +where block_tag='BUDNI_PTO_Spec_H1' and block_row_number=3 ; + +select column4 into __model from staging2.stg_process_table_budni_pto a +where block_tag='BUDNI_PTO_Spec_H1' and block_row_number=3; + +/* blocks data loading start - BUDNI_PTO_Spec_H1_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_PTO_Spec_H1_block',__file_mnemonic,__file_sheet_mnemonic,1); +err_block:='BUDNI_PTO_Spec_H1_block'; + +insert into staging2.BUDNI_PTO_Spec_H1_block +(make,model,tractor_HP,rated_rpm,configuration,transmission_type,wheel_drive_type,FIP_type,block_row_number) +select column3,column4,column5,column6,column7,column8,column9,column10,block_row_number +from staging2.stg_process_table_budni_pto where block_tag='BUDNI_PTO_Spec_H1' +and block_row_number=3; + + +execute 'update staging2.BUDNI_PTO_Spec_H1_block set file_syspk='||p_file_syspk||''; + +update staging2.BUDNI_PTO_Spec_H1_block a +set date= case + when column12 like '%-%' then column12::timestamptz + else date '1899-12-30' + column12::int * interval '1' day + end +from staging2.stg_process_table_budni_pto b +where b.block_tag='BUDNI_PTO_Spec_H1' +and b.block_row_number=1 +and a.file_syspk=b.file_syspk ; + +--update staging2.BUDNI_PTO_Spec_H1_block a +--set date= date '1899-12-30' + column12::int * interval '1' day +--from staging2.stg_process_table_budni_pto b +--where b.block_tag='BUDNI_PTO_Spec_H1' +--and b.block_row_number=1 +--and a.file_syspk=b.file_syspk ; + + +update staging2.BUDNI_PTO_Spec_H1_block a +set steering_type=column3,Engine_to_PTO_ratio= column4 +from staging2.stg_process_table_budni_pto b +where b.block_tag='BUDNI_PTO_Spec_H1' +and b.block_row_number=5 +and a.file_syspk=b.file_syspk; + + update staging2.BUDNI_PTO_Spec_H1_block set make=__make, model=__model; + execute 'update staging2.BUDNI_PTO_Spec_H1_block set +client_id='||p_client_id||', +function_id='||p_function_id||', + file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''', + file_syspk='||p_file_syspk||''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_PTO_Spec_H1_block'); + + +/* blocks data loading -BUDNI_PTO_Perf_Report_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_PTO_Perf_Report_block',__file_mnemonic,__file_sheet_mnemonic,2); +err_block:='BUDNI_PTO_Perf_Report_block'; + +insert into staging2.BUDNI_PTO_Perf_Report_block +( column2,column3,column4,column5,column6,column7,column8,column9,column10,block_row_number) +select column2,column3,column4,column5,column6,column7,column8,column9,column10,block_row_number +from staging2.stg_process_table_budni_pto +where block_tag='BUDNI_PTO_Perf_Report'; + + +update staging2.BUDNI_PTO_Perf_Report_block +set column2=column3 where column2 is null; + +update staging2.BUDNI_PTO_Perf_Report_block +set column2=null +where column2 like 'i%'; + +update staging2.BUDNI_PTO_Perf_Report_block +set column2=null +where column2 like 'v%'; + +update staging2.BUDNI_PTO_Perf_Report_block a +set column2= b.first_value from (SELECT + block_row_number, column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + column2, + sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.BUDNI_PTO_Perf_Report_block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number ; + +update staging2.BUDNI_PTO_Perf_Report_block +set column3 =null +where column2=column3; + +update staging2.BUDNI_PTO_Perf_Report_block +set trx_record=0 where block_row_number in (1,2); + + +update staging2.BUDNI_PTO_Perf_Report_block set trx_record=0 where column3 is null +and column2 in( +select column2 from staging2.BUDNI_PTO_Perf_Report_block group by column2 having count(*)>1 +); + + + update staging2.BUDNI_PTO_Perf_Report_block set make=__make,model=__model; + execute 'update staging2.BUDNI_PTO_Perf_Report_block set +client_id='||p_client_id||', +function_id='||p_function_id||', + file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''', + file_syspk='||p_file_syspk||''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_PTO_Perf_Report_block'); + + +/* blocks data loading - BUDNI_PTO_MMTKeyword1_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_PTO_MMTKeyword1_block',__file_mnemonic,__file_sheet_mnemonic,3); +err_block:='BUDNI_PTO_MMTKeyword1_block'; + + insert into staging2.BUDNI_PTO_MMTKeyword1_block +( column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,block_row_number) +select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_budni_pto +where block_tag='BUDNI_PTO_MMTKeyword1'; + + +update staging2.BUDNI_PTO_MMTKeyword1_block set trx_record=0 where block_row_number in (1,2); + +update staging2.BUDNI_PTO_MMTKeyword1_block set make=__make,model=__model; +execute 'update staging2.BUDNI_PTO_MMTKeyword1_block set +client_id='||p_client_id||', +function_id='||p_function_id||', + file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''', + file_syspk='||p_file_syspk||''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_PTO_MMTKeyword1_block'); + +/* blocks data loading - BUDNI_PTO_MMTKeyword2_block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_PTO_MMTKeyword2_block',__file_mnemonic,__file_sheet_mnemonic,4); +err_block:='BUDNI_PTO_MMTKeyword2_block'; + +insert into staging2.BUDNI_PTO_MMTKeyword2_block +( column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,block_row_number) +select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_budni_pto +where block_tag='BUDNI_PTO_MMTKeyword2'; + + +update staging2.BUDNI_PTO_MMTKeyword2_block set trx_record=0 where block_row_number in (1,2); + + + update staging2.BUDNI_PTO_MMTKeyword2_block set make=__make,model=__model; + execute 'update staging2.BUDNI_PTO_MMTKeyword2_block set + client_id='||p_client_id||', + function_id='||p_function_id||', + file_mnemonic='''||p_file_mnemonic||''', + file_sheet_mnemonic='''||p_file_sheet_mnemonic||''', + file_syspk='||p_file_syspk||''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_PTO_MMTKeyword2_block'); + +/* blocks data loading -BUDNI_PTO_Summary_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_PTO_Summary_Block',__file_mnemonic,__file_sheet_mnemonic,5); +err_block:='BUDNI_PTO_Summary_Block'; + +insert into staging2.BUDNI_PTO_Summary_Block +( column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,block_row_number) +select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_budni_pto +where block_tag='BUDNI_PTO_Summary'; + + +update staging2.BUDNI_PTO_Summary_block +set trx_record=0 where block_row_number in (1,2); + + update staging2.BUDNI_PTO_Summary_block set make=__make, model=__model; + execute 'update staging2.BUDNI_PTO_Summary_block set + client_id='||p_client_id||', +function_id='||p_function_id||', + file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''', + file_syspk='||p_file_syspk||''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_PTO_Summary_Block'); + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_BUDNI_PTO_block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + diff --git a/onetime/dataloadfunctions/budni/BUDNI_VMT_ODS.sql b/onetime/dataloadfunctions/budni/BUDNI_VMT_ODS.sql new file mode 100755 index 0000000..ec5f627 --- /dev/null +++ b/onetime/dataloadfunctions/budni/BUDNI_VMT_ODS.sql @@ -0,0 +1,239 @@ +drop function if exists staging2.fn_BUDNI_VMT_TRX; +CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_VMT_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + declare __test_instance_tractor_id int; + begin +__file_syspk := p_file_syspk; +/************************************************************ +Function Name:fn_BUDNI_VMT_TRX +Function Desc: This function populates data into ODS +File Format: BUDNI +Sheet Format: BUDNI_VMT +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_BUDNI_VMT_TRX() +***************************************************************/ + +insert into transactional.test_instance_tractor_info +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +tractor_engine_hp, +configuration, +transmission_type, +wheel_drive_type, +fip_type, +steering_type, +ballast_condition +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make, +model, +tractor_HP::int tractor_engine_hp, +configuration, +transmission_type, +wheel_drive_type, +FIP_type, +steering_type, +Ballast_Condition +from staging2.BUDNI_VMT_Spec_H1_block where trx_record=1; + +update transactional.test_instance_tractor_info +set mahindra_model_yn = ( +case when lower(tractor_make) like 'mahindra%' then 'Y' else 'N' end +) where file_syspk =__file_syspk; + +update transactional.test_instance_tractor_info a +set test_tractor_yn ='Y' where syspk in +(select min(syspk) from transactional.test_instance_tractor_info b +where b.file_syspk =a.file_syspk) +and a.file_syspk =__file_syspk; + +insert into transactional.test_instance +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model +from + staging2.BUDNI_VMT_Spec_H1_block where trx_record=1; + + insert into transactional.test_instance_engine_info + ( + client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +rated_rpm, +engine_to_pto_ratio_540_pto +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +rated_rpm::int, +engine_to_pto_ratio engine_to_pto_ratio_540_pto +from staging2.BUDNI_VMT_Spec_H1_block where trx_record=1; + +insert into transactional.budni_vibration_measurement +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +srl_no, +measuring_points, +vibration_at_no_load_vd_microns, +vibration_at_no_load_hd_microns, +vibration_at_load_85_pct_of_max_pto_power_vd_microns, +vibration_at_load_85_pct_of_max_pto_power_hd_microns +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +column3::numeric, +column4, +column6::numeric , +column7::numeric , +column8::numeric , +column9::numeric +from staging2.BUDNI_VMT_Perf_Meas_Test_Block +where trx_record =1 +order by block_row_number; + +insert into transactional.budni_test_observations +( +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_make, +tractor_model, +sequence_number, +characteristic, +category_evaluative_or_non_evaluative, +requirements_as_per_is_12207_2008, +values_declared_by_the_applicant_d_rqmt, +as_observed, +whether_meets_the_requirements_yn +) +select +client_id, +function_id, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +make,model, +column3::INT, +column4, +column5, +column6, +column7, +column8, +column9 +from staging2.BUDNI_VMT_test_obs_summary_block where trx_record=1; + + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk; +select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk; +select syspk from transactional.test_master into __test_master_id where test_type ='BUDNI'; +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk; + + +update transactional.test_instance +set test_master_id =__test_master_id, +test_tractor_id =__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.test_instance_engine_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.budni_vibration_measurement +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + + +update transactional.budni_test_observations +set test_instance_id=__test_instance_id, +test_instance_tractor_id = __test_instance_tractor_id, +tractor_model =__model, +tractor_make=__make +where file_syspk=__file_syspk; + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_BUDNI_VMT_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + + diff --git a/onetime/dataloadfunctions/budni/BUDNI_VMT_STG2.sql b/onetime/dataloadfunctions/budni/BUDNI_VMT_STG2.sql new file mode 100755 index 0000000..695c97a --- /dev/null +++ b/onetime/dataloadfunctions/budni/BUDNI_VMT_STG2.sql @@ -0,0 +1,337 @@ +drop function if exists staging2.fn_BUDNI_VMT_Block ; +CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_VMT_Block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + + begin + +SET search_path TO staging2; + + +/*********************************************************************************** +Function Name:fn_BUDNI_VMT_Block +Function Desc: This function populates data into staging2 blocks +File Format: BUDNI +Sheet Format:BUDNI_VMT +Creation Date: March 21 2021 +Updation Date: +Author: compegence team +Function Call: select staging2.fn_BUDNI_VMT_Block(20,1,'BUDNI','BUDNI_VMT',261); +************************************************************************************/ + + +/* rerunnability - delete block tables and update config tables to null */ +truncate table staging2.BUDNI_VMT_Spec_H1_Block; +truncate table staging2.BUDNI_VMT_Perf_Meas_Test_Block; +truncate table staging2.BUDNI_VMT_Test_Obs_Summary_Block; +truncate table staging2.stg_specific_table_BUDNI_VMT; +truncate table staging2.stg_process_table_BUDNI_VMT; + + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* transfer data from generic to specific for BUDNI */ +execute 'insert into staging2.stg_specific_table_BUDNI_VMT +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_BUDNI_VMT; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for Budni VMT', + detail = 'No data in table stg_specific_table_BUDNI_VMT', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + + +update transactional.source_config set F1_source=F1_modified; + + +/* keyword match in config table*/ + + +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_BUDNI_VMT b +where upper(F1_source)= upper(column3) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update in process table for match*/ +execute 'update staging2.stg_specific_table_BUDNI_VMT a +set is_rownumber_fetched=1 +from transactional.source_config b +where upper(F1_source)= upper(column3) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* update config files for row numbers start, end */ +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a +set row_read_end = null +where f1_modified =''AIR CLEANER OIL PULL OVER TEST Observations Summary'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set run_time=current_timestamp +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers for each block in process table*/ +execute 'insert into staging2.stg_process_table_BUDNI_VMT +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_BUDNI_VMT a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Tractor Specifiactions'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + +execute 'insert into staging2.stg_process_table_BUDNI_VMT +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_BUDNI_VMT a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Machanical Vibration Measurement Test'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + + +execute 'insert into staging2.stg_process_table_BUDNI_VMT +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_BUDNI_VMT a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Noise Measurement Test Observations Summary'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +/* fetching tractor model and make */ +select column3 into __make from staging2.stg_process_table_BUDNI_VMT a +where block_tag='BUDNI_VMT_Spec_H1' and block_row_number=3; + +select column4 into __model from staging2.stg_process_table_BUDNI_VMT a +where block_tag='BUDNI_VMT_Spec_H1' and block_row_number=3; + + +/* blocks data loading start - BUDNI_VMT_Spec_H1_block */ + + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_VMT_Spec_H1_Block',__file_mnemonic,__file_sheet_mnemonic,1); +err_block:='BUDNI_VMT_Spec_H1_Block'; +insert into staging2.BUDNI_VMT_Spec_H1_block +( +make,model,tractor_HP,rated_rpm,configuration,transmission_type,wheel_drive_type,block_row_number) +select column3,column4,column5,column6,column7,column8,column9,block_row_number +from staging2.stg_process_table_BUDNI_VMT where block_tag='BUDNI_VMT_Spec_H1' +and block_row_number=3; + + +execute 'update staging2.BUDNI_VMT_Spec_H1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +update staging2.BUDNI_VMT_Spec_H1_block a +set FIP_type=column3,steering_type=column4,Engine_to_PTO_ratio= column5,Ballast_Condition=column6, +Test_Engine_Set_RPM=column7,Type_of_track=column8 +from staging2.stg_process_table_BUDNI_VMT b +where b.block_tag='BUDNI_VMT_Spec_H1' +and b.block_row_number=5 +and a.file_syspk=b.file_syspk; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_VMT_Spec_H1_Block'); + + +/* blocks data loading -BUDNI_VMT_Perf_Meas_Test_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_VMT_Perf_Meas_Test_Block',__file_mnemonic,__file_sheet_mnemonic,2); +err_block:='BUDNI_VMT_Perf_Meas_Test_Block'; + +insert into staging2.BUDNI_VMT_Perf_Meas_Test_Block +( +column3, +column4, +column5, +column6, +column7, +column8, +column9, +block_row_number +) +select +column3,column4,column5,column6,column7,column8,column9,block_row_number +from staging2.stg_process_table_BUDNI_VMT a +where block_tag ='BUDNI_VMT_Perf_Meas_Test' +order by block_row_number; + + +update staging2.BUDNI_VMT_Perf_Meas_Test_Block a +set column3= b.first_value from (SELECT + block_row_number, column3, value_partition, first_value(column3) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + column3, + sum(case when column3 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.BUDNI_VMT_Perf_Meas_Test_Block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number and a.block_row_number not in(1,2,3,4); + +update staging2.BUDNI_VMT_Perf_Meas_Test_Block a +set column4= b.first_value from (SELECT + block_row_number, column4, value_partition, first_value(column4) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + column4, + sum(case when column4 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.BUDNI_VMT_Perf_Meas_Test_Block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number and a.block_row_number not in(1,2,3,4); + + +update staging2.BUDNI_VMT_Perf_Meas_Test_Block +set column4=concat(column4,'-',column5) where block_row_number not in(1,2,3,4) and column5 is not null; + +update staging2.BUDNI_VMT_Perf_Meas_Test_Block +set trx_record=0 where block_row_number in(1,2,3,4); + +update staging2.BUDNI_VMT_Perf_Meas_Test_Block set make=__make,model=__model; +execute 'update staging2.BUDNI_VMT_Perf_Meas_Test_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_VMT_Perf_Meas_Test_Block'); + + +/* blocks data loading -BUDNI_VMT_Test_Obs_Summary_Block */ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'BUDNI_VMT_Test_Obs_Summary_Block',__file_mnemonic,__file_sheet_mnemonic,3); +err_block:='BUDNI_VMT_Test_Obs_Summary_Block'; + +insert into staging2.BUDNI_VMT_Test_Obs_Summary_Block +( +column3,column4,column5,column6,column7, +column8,column9,block_row_number +) +select +column3,column4,column5,column6,column7, +column8,column9,block_row_number +from staging2.stg_process_table_BUDNI_VMT a +where block_tag='BUDNI_VMT_Test_Obs_Summary' and block_row_number <=6 +order by block_row_number; + +update staging2.BUDNI_VMT_Test_Obs_Summary_Block a +set column5= b.first_value from (SELECT + block_row_number, column5, value_partition, first_value(column5) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + column5, + sum(case when column5 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.BUDNI_VMT_Test_Obs_Summary_Block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + +update staging2.BUDNI_VMT_Test_Obs_Summary_Block a +set column6= b.first_value from (SELECT + block_row_number, column6, value_partition, first_value(column6) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + column6, + sum(case when column6 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.BUDNI_VMT_Test_Obs_Summary_Block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + +update staging2.BUDNI_VMT_Test_Obs_Summary_Block a +set column7= b.first_value from (SELECT + block_row_number, column7, value_partition, first_value(column7) over (partition by value_partition order by block_row_number) +FROM ( + SELECT + block_row_number, + column7, + sum(case when column7 is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.BUDNI_VMT_Test_Obs_Summary_Block + ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + +update staging2.BUDNI_VMT_Test_Obs_Summary_Block +set trx_record=0 where +block_row_number in(1,2); + + +update staging2.BUDNI_VMT_Test_Obs_Summary_Block set make=__make,model=__model; +execute 'update staging2.BUDNI_VMT_Test_Obs_Summary_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_VMT_Test_Obs_Summary_Block'); + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_BUDNI_VMT_Block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + + + diff --git a/onetime/dataloadfunctions/field/FTDRY_SUM_ODS.sql b/onetime/dataloadfunctions/field/FTDRY_SUM_ODS.sql new file mode 100755 index 0000000..3e371b8 --- /dev/null +++ b/onetime/dataloadfunctions/field/FTDRY_SUM_ODS.sql @@ -0,0 +1,403 @@ + + + + +drop function if exists staging2.fn_FTDRY_SUM_TRX ; +CREATE OR REPLACE FUNCTION staging2.fn_FTDRY_SUM_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_files_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __files_syspk int :=p_files_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + begin + +__files_syspk := p_files_syspk; + +/************************************************************ +Function Name:fn_FTDRY_SUM_TRX +Function Desc: This function populates data into ODS +File Format: FTDRY +Sheet Format: FTDRY_SUM +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_FTDRY_SUM_TRX() +***************************************************************/ + + + +insert into transactional.field_perf_summary_tractor_info +( +client_id, +function_id, +tractor_model, +tractor_make, +tractor_engine_hp, +rated_rpm, +transmission_type, +wheel_drive_type, +fip_type, +steering_type, +tractor_weight_front_kg, +tractor_weight_rear_kg, +tractor_weight_total_kg, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +tractor_model, +tractor_make, +tractor_engine_hp::numeric, +rated_rpm::numeric, +transmission_type, +wheel_drive_type, +fip_type, +steering_type, +tractor_weight_kg_front::numeric, +tractor_weight_kg_rear::numeric, +tractor_weight_kg_total::numeric, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +from staging2.ftdry_sum_trac_h1_block where trx_record=1; + + + + + +update transactional.field_perf_summary_tractor_info a +set test_instance_tractor_id = (select syspk +from transactional.test_instance_tractor_info b +where a.tractor_model=trim(b.tractor_model) and a.file_syspk =b.file_syspk +)where a.file_syspk =__files_syspk; + + +insert into transactional.field_perf_summary_implement_info +( +client_id, +function_id, +name_of_implement, +implement_type, +implement_size, +hitch_category, +implement_weight, +soil_type, +soil_moisture_content_pct, +soil_bulk_density_g_per_cc, +soil_cone_index, +field_condition, +season, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +make_of_implement, +implement_type, +implement_size, +hitch_category, +trim('kg' from implement_weight)::numeric, +soil_type, +moisture_content::numeric soil_moisture_content_pct, +bulk_density_g_cc::numeric soil_bulk_density_g_per_cc, +trim(' Kpa' from soil_cone_index)::numeric soil_cone_index, +field_condition, +season, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +from staging2.ftdry_sum_implement_block where trx_record=1; + +insert into transactional.field_perf_summary +( +client_id, +function_id, +test_iteration_number, +test_condition, +test_date, +tractor_model, +engine_rpm_set, +pto_rpm_set, +gear_used, +nominal_speed_kmph, +engine_rpm_drop_on_straight_1st_pass, +engine_rpm_drop_on_turn_1st_pass, +depth_of_cut_cm, +no_load_speed_kmph, +on_load_speed_kmph, +wheel_slippage_pct, +fuel_consumption_lit_per_hr, +area_covered_acr_per_hr, +fuel_consumption_lit_per_acr, +fuel_consumption_var_pct_lit_per_hr, +area_covered_var_pct_acr_per_hr, +fuel_consumption_var_pct_lit_per_acr, +engine_smoke_on_load, +engine_acceleration_smoke, +draft_response, +tractor_steer_ability, +tractor_braking_perf, +front_visibility, +implement_accessibility, +front_wheel_dragging_at_turning, +front_end_lifting_during_operation, +rpm_recovery_time, +engine_vibration, +engine_sound, +implement_lifting_per_lowering_response, +pulverization_index, +pulverization_quality, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +test_iterationnumber::numeric, +test_condition, +test_date::date, +tractor_model, +engine_rpm_set::numeric, +pto_rpm_set::numeric, +gear_used, +nominal_speed_kmph::numeric, +engine_rpm_drop_on_straight engine_rpm_drop_on_straight_1st_pass , +engine_rpm_drop_on_turn engine_rpm_drop_on_turn_1st_pass, +depth_of_cut_cm, +no_load_speed_kmph::numeric, +on_load_speed_kmph::numeric, +wheel_slippage_::numeric wheel_slippage_pct, +fuel_consumption_lit_hr::numeric fuel_consumption_lit_per_hr, +area_covered_acr_hr::numeric area_covered_acr_per_hr, +fuel_consumption_lit_acr::numeric fuel_consumption_lit_per_acr , +fuel_consumption_lit_hr_2::numeric , +area_covered_acr_hr_2::numeric , +fuel_consumption_lit_acr_2::numeric , +engine_smoke_on_load, +engine_acceleration_smoke , +draft_response, +tractor_steer_ability, +tractor_braking_performance, +front_visibility, +implement_accessibility, +front_wheel_dragging_at_turning, +front_end_lifting_during_operation, +rpm_recovery_time, +engine_vibration, +engine_sound, +implement_lifting_lowering_response implement_lifting_per_lowering_response, +pulverization_index, +pulverization_quality, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +from staging2.ftdry_sum_test_condition_1_block where trx_record=1; + + + +insert into transactional.field_perf_summary +( +client_id, +function_id, +test_iteration_number, +test_condition, +test_date, +tractor_model, +engine_rpm_set, +pto_rpm_set, +gear_used, +nominal_speed_kmph, +engine_rpm_drop_on_straight_1st_pass, +engine_rpm_drop_on_turn_1st_pass, +depth_of_cut_cm, +no_load_speed_kmph, +on_load_speed_kmph, +wheel_slippage_pct, +fuel_consumption_lit_per_hr, +area_covered_acr_per_hr, +fuel_consumption_lit_per_acr, +fuel_consumption_var_pct_lit_per_hr, +area_covered_var_pct_acr_per_hr, +fuel_consumption_var_pct_lit_per_acr, +engine_smoke_on_load, +engine_acceleration_smoke, +draft_response, +tractor_steer_ability, +tractor_braking_perf, +front_visibility, +implement_accessibility, +front_wheel_dragging_at_turning, +front_end_lifting_during_operation, +rpm_recovery_time, +engine_vibration, +engine_sound, +implement_lifting_per_lowering_response, +pulverization_index, +pulverization_quality, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +test_iterationnumber::numeric, +test_condition, +test_date::date, +tractor_model, +engine_rpm_set::numeric, +pto_rpm_set::numeric, +gear_used, +nominal_speed_kmph::numeric, +engine_rpm_drop_on_straight engine_rpm_drop_on_straight_1st_pass , +engine_rpm_drop_on_turn engine_rpm_drop_on_turn_1st_pass, +depth_of_cut_cm, +no_load_speed_kmph::numeric, +on_load_speed_kmph::numeric, +wheel_slippage_::numeric wheel_slippage_pct, +fuel_consumption_lit_hr::numeric fuel_consumption_lit_per_hr, +area_covered_acr_hr::numeric area_covered_acr_per_hr, +fuel_consumption_lit_acr::numeric fuel_consumption_lit_per_acr , +fuel_consumption_lit_hr_2::numeric , +area_covered_acr_hr_2::numeric , +fuel_consumption_lit_acr_2::numeric , +engine_smoke_on_load, +engine_acceleration_smoke , +draft_response, +tractor_steer_ability, +tractor_braking_performance, +front_visibility, +implement_accessibility, +front_wheel_dragging_at_turning, +front_end_lifting_during_operation, +rpm_recovery_time, +engine_vibration, +engine_sound, +implement_lifting_lowering_response implement_lifting_per_lowering_response, +pulverization_index, +pulverization_quality, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +from staging2.ftdry_sum_test_condition_2_block where trx_record=1; + + + + + +update transactional.field_perf_summary a +set test_engr_comments=b.test_engineer_comments_1, +test_mgr_comments =b.test_manager_comments_1 +from staging2.ftdry_sum_comments_by_block b +where a.file_syspk=b.file_syspk and a.test_iteration_number =1; + +update transactional.field_perf_summary a +set test_engr_comments=b.test_engineer_comments_2, +test_mgr_comments =b.test_manager_comments_2 +from staging2.ftdry_sum_comments_by_block b +where a.file_syspk=b.file_syspk and a.test_iteration_number =2; + +update transactional.field_perf_summary a +set test_engr_comments=b.test_engineer_comments_3, +test_mgr_comments =b.test_manager_comments_3 +from staging2.ftdry_sum_comments_by_block b +where a.file_syspk=b.file_syspk and a.test_iteration_number =3; + +update transactional.field_perf_summary a +set test_engr_comments=b.test_engineer_comments_4, +test_mgr_comments =b.test_manager_comments_4 +from staging2.ftdry_sum_comments_by_block b +where a.file_syspk=b.file_syspk and a.test_iteration_number =4; + + + + + +update transactional.field_perf_summary a +set test_instance_tractor_id = (select syspk +from transactional.test_instance_tractor_info b +where a.tractor_model=trim(b.tractor_model) and a.file_syspk =b.file_syspk +)where test_iteration_number =1 and a.file_syspk =__files_syspk; + +update transactional.field_perf_summary a +set test_instance_tractor_id = (select syspk +from transactional.test_instance_tractor_info b +where a.tractor_model=b.tractor_model and a.file_syspk =b.file_syspk +)where test_iteration_number =2 and a.file_syspk =__files_syspk; + +update transactional.field_perf_summary a +set test_instance_tractor_id = (select syspk +from transactional.test_instance_tractor_info b +where a.tractor_model=b.tractor_model and a.file_syspk =b.file_syspk +)where test_iteration_number =3 and a.file_syspk =__files_syspk; + + +update transactional.field_perf_summary a +set test_instance_tractor_id = (select syspk +from transactional.test_instance_tractor_info b +where a.tractor_model=b.tractor_model and a.file_syspk =b.file_syspk +)where test_iteration_number =4 and a.file_syspk =__files_syspk; + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__files_syspk; + +update transactional.field_perf_summary +set test_instance_id=__test_instance_id +where file_syspk=__files_syspk; + +update transactional.field_perf_summary +set engine_rpm_drop_on_straight_1st_pass =replace(engine_rpm_drop_on_straight_1st_pass,' to ','-'), +engine_rpm_drop_on_turn_1st_pass=replace(engine_rpm_drop_on_turn_1st_pass,' to ','-'), +depth_of_cut_cm=replace(depth_of_cut_cm,' to ','-') +where file_mnemonic = 'FTDRY'; + +update transactional.field_perf_summary_implement_info +set test_instance_id=__test_instance_id +where file_syspk=__files_syspk; + + UPDATE transactional.field_perf_summary + SET +--updating RPM drop straight 1st pass: + erpmdrop_straight_1stpass_low = trim(split_part(trim(engine_rpm_drop_on_straight_1st_pass), '-', 1))::numeric, + erpmdrop_straight_1stpass_high = case trim(split_part(trim(engine_rpm_drop_on_straight_1st_pass), '-', 2)) + when '' then null + else trim(split_part(trim(engine_rpm_drop_on_straight_1st_pass), '-', 2))::numeric end, +--updating RPM drop turn 1st pass: + erpmdrop_turn_1stpass_low = trim(split_part(trim(engine_rpm_drop_on_turn_1st_pass), '-', 1))::numeric, + erpmdrop_turn_1stpass_high = case trim(split_part(trim(engine_rpm_drop_on_turn_1st_pass), '-', 2)) + when '' then null + else trim(split_part(trim(engine_rpm_drop_on_turn_1st_pass), '-', 2))::numeric end, +--updating depth of cut: + depth_of_cut_cm_low = trim(split_part(trim(depth_of_cut_cm), '-', 1))::numeric, + depth_of_cut_cm_high= case trim(split_part(trim(depth_of_cut_cm), '-', 2)) + when '' then null + else trim('cm' from split_part(trim(depth_of_cut_cm), '-', 2))::numeric end + where file_mnemonic = 'FTDRY'; + +update transactional.field_perf_summary_tractor_info +set test_instance_id=__test_instance_id +where file_syspk=__files_syspk; +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __files_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_FTDRY_SUM_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; diff --git a/onetime/dataloadfunctions/field/FTDRY_SUM_STG2.sql b/onetime/dataloadfunctions/field/FTDRY_SUM_STG2.sql new file mode 100755 index 0000000..c4cac04 --- /dev/null +++ b/onetime/dataloadfunctions/field/FTDRY_SUM_STG2.sql @@ -0,0 +1,688 @@ +drop function if exists staging2.fn_FTDRY_SUM_Block ; +CREATE OR REPLACE FUNCTION staging2.fn_FTDRY_SUM_Block(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + begin + + +/*********************************************************************************** +Function Name:fn_FTDRY_SUM_Block +Function Desc: This function populates data into staging2 blocks +File Format: FTDRY +Sheet Format: FTDRY_SUM +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_FTDRY_SUM_Block (20,1,'FTDRY','FTDRY_SUM',258); +************************************************************************************/ + + +SET search_path TO staging2; + +truncate staging2.ftdry_sum_trac_h1_block; +truncate staging2.ftdry_sum_implement_block; +truncate staging2.ftdry_sum_test_condition_1_block; +truncate staging2.ftdry_sum_test_condition_2_block; +truncate staging2.ftdry_sum_comments_by_block; +truncate staging2.stg_specific_table_ftdry_sum; +truncate staging2.stg_process_table_ftdry_sum; + + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* transfer data from generic to specific for ftdry*/ +execute 'insert into staging2.stg_specific_table_ftdry_sum +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_ftdry_sum; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for FTDRY Summary', + detail = 'No data in table stg_specific_table_ftdry_sum', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; +/* trimming data */ +update staging2.stg_specific_table_ftdry_sum set column2 = TRIM (TRAILING FROM column2 ); +update staging2.stg_specific_table_ftdry_sum set column2 = TRIM (LEADING FROM column2 ); + +update transactional.source_config set F1_source=F1_modified ; + +/* keyword match in config table*/ + +execute 'update transactional.source_config a set f1_source = replace(f1_source,''_1'','''') +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* update config files for row numbers start, end */ +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_ftdry_sum b +where F1_source=column2 +and b.is_rownumber_fetched is null) +where a.row_number_start is null and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update in process table for match*/ +execute 'update staging2.stg_specific_table_ftdry_sum a +set is_rownumber_fetched=1 +from transactional.source_config b +where F1_source=column2 +and b.row_number_start=a.row_number +and is_rownumber_fetched is null and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a set f1_source = replace(f1_source,''_2'','''') + where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* update config files for row numbers start, end */ + +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_ftdry_sum b +where F1_source=column2 +and b.is_rownumber_fetched is null) +where a.row_number_start is null and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update staging2.stg_specific_table_ftdry_sum a +set is_rownumber_fetched=1 +from transactional.source_config b +where F1_source=column2 +and b.row_number_start=a.row_number +and is_rownumber_fetched is null and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a + set row_read_end = null where f1_modified =''Test Manager Comments_2'' and +a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/*inserting run_time in config*/ +execute 'update transactional.source_config a +set run_time=current_timestamp where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers for each block in process table*/ +execute 'insert into staging2.stg_process_table_ftdry_sum +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_ftdry_sum a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Tractor Model'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + +execute 'insert into staging2.stg_process_table_ftdry_sum +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_ftdry_sum a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Make of Implement'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +execute 'insert into staging2.stg_process_table_ftdry_sum +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_ftdry_sum a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Condition_1:'' + and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +execute 'insert into staging2.stg_process_table_ftdry_sum +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_ftdry_sum a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Engineer Comments_1'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +execute 'insert into staging2.stg_process_table_ftdry_sum +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_ftdry_sum a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Manager Comments_1'' + and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + +execute 'insert into staging2.stg_process_table_ftdry_sum +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_ftdry_sum a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Condition_2:'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +execute 'insert into staging2.stg_process_table_ftdry_sum +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_ftdry_sum a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Engineer Comments_2'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +execute 'insert into staging2.stg_process_table_ftdry_sum +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_ftdry_sum a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Manager Comments_2'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + +/* blocks data loading start - FTDRY_SUM_Trac_H1_Block*/ + + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTDRY_SUM_Trac_H1_Block',__file_mnemonic,__file_sheet_mnemonic,1); + +err_block:='FTDRY_SUM_Trac_H1_Block'; + +insert into staging2.FTDRY_SUM_Trac_H1_Block +( +Tractor_Model, +Tractor_Make, +Tractor_Engine_HP, +Rated_RPM, +Transmission_Type, +Wheel_Drive_Type, +FIP_Type, +Steering_Type, +Tractor_Weight_kg_Front, +Tractor_Weight_kg_Rear, +Tractor_Weight_kg_Total, +block_row_number +) +select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_ftdry_sum +where block_tag='FTDRY_SUM_Trac_H1' +order by block_row_number; + +update staging2.FTDRY_SUM_Trac_H1_Block set trx_record =0 +where tractor_model = '0'; + +update staging2.FTDRY_SUM_Trac_H1_Block +set trx_record=0 where block_row_number=1; + +execute 'update staging2.FTDRY_SUM_Trac_H1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTDRY_SUM_Trac_H1_Block'); + +/* blocks data loading start -FTDRY_SUM_Implement_Block*/ + + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTDRY_SUM_Implement_Block',__file_mnemonic,__file_sheet_mnemonic,2); +err_block:='FTDRY_SUM_Implement_Block'; +insert into staging2.FTDRY_SUM_Implement_Block +( +Make_of_Implement, +Implement_Type, +Implement_Size, +Hitch_Category, +Implement_Weight, +Soil_Type, +Moisture_Content , +Bulk_Density_g_cc , +Soil_Cone_index, +Field_Condition , +Season, +block_row_number +) +select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_ftdry_sum +where block_tag='FTDRY_SUM_Implement'; + +update staging2.FTDRY_SUM_Implement_Block +set trx_record=0 where block_row_number in(1,3); + + +execute 'update staging2.FTDRY_SUM_Implement_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTDRY_SUM_Implement_Block'); + +/* blocks data loading start -FTDRY_SUM_Test_Condition_1_Block*/ + + + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTDRY_SUM_Test_Condition_1_Block',__file_mnemonic,__file_sheet_mnemonic,3); +err_block:='FTDRY_SUM_Test_Condition_1_Block'; +insert into staging2.FTDRY_SUM_Test_Condition_1_Block +( +dummy_f, +Test_Condition, +Test_Date, +Tractor_Model, +Engine_RPM_set, +PTO_RPM_set, +Gear_Used, +Nominal_Speed_KMPH, +Engine_RPM_Drop_on_straight, +Engine_RPM_Drop_on_turn, +Depth_of_cut_cm, +No_load_speed_kmph, +On_load_speed_kmph, +wheel_slippage_, +Fuel_consumption_lit_hr, +Area_covered_acr_hr, +Fuel_consumption_lit_Acr, +M_M_Performance_in_compared_to_respective_competitor_tractors, +Fuel_consumption_lit_hr_2, +Area_covered_acr_hr_2, +Fuel_consumption_lit_Acr_2, +Trail_Observations, +Engine_Smoke_on_Load, +Engine_acceleration_smoke, +Draft_Response, +Tractor_Steer_ability, +Tractor_braking_performance, +Front_Visibility, +Implement_Accessibility, +Front_Wheel_dragging_at_turning, +Front_end_lifting_during_operation, +RPM_Recovery_Time, +Engine_Vibration, +Engine_Sound, +Implement_Lifting_Lowering_response, +Pulverization_Quality, +Pulverization_Index +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column3::text, +column4::text,column5::text,column6::text,column7::text]) AS val + FROM staging2.stg_process_table_ftdry_sum where block_tag=''FTDRY_SUM_Test_Condition_1'' + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text, + a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text + ,a_21 text,a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text, +a_31 text,a_32 text,a_33 text,a_34 text,a_35 text,a_36 text); + + +update staging2.FTDRY_SUM_Test_Condition_1_Block +set test_iterationnumber=1; + +insert into staging2.FTDRY_SUM_Test_Condition_1_Block +( +dummy_f, +Test_Condition, +Test_Date, +Tractor_Model, +Engine_RPM_set, +PTO_RPM_set, +Gear_Used, +Nominal_Speed_KMPH, +Engine_RPM_Drop_on_straight, +Engine_RPM_Drop_on_turn, +Depth_of_cut_cm, +No_load_speed_kmph, +On_load_speed_kmph, +wheel_slippage_, +Fuel_consumption_lit_hr, +Area_covered_acr_hr, +Fuel_consumption_lit_Acr, +M_M_Performance_in_compared_to_respective_competitor_tractors, +Fuel_consumption_lit_hr_2, +Area_covered_acr_hr_2, +Fuel_consumption_lit_Acr_2, +Trail_Observations, +Engine_Smoke_on_Load, +Engine_acceleration_smoke, +Draft_Response, +Tractor_Steer_ability, +Tractor_braking_performance, +Front_Visibility, +Implement_Accessibility, +Front_Wheel_dragging_at_turning, +Front_end_lifting_during_operation, +RPM_Recovery_Time, +Engine_Vibration, +Engine_Sound, +Implement_Lifting_Lowering_response, +Pulverization_Quality, +Pulverization_Index +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column8,column9,column10,column11,column12}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column8::text, +column9::text,column10::text,column11::text,column12::text]) AS val + FROM staging2.stg_process_table_ftdry_sum where block_tag=''FTDRY_SUM_Test_Condition_1'' + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text, + a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text + ,a_21 text,a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text, +a_31 text,a_32 text,a_33 text,a_34 text,a_35 text,a_36 text); + +update staging2.FTDRY_SUM_Test_Condition_1_Block +set test_iterationnumber=2 +where test_iterationnumber is null; + + update staging2.FTDRY_SUM_Test_Condition_1_Block a + set Test_Condition= b.first_value from (SELECT +test_iterationnumber,Test_Condition, value_partition, first_value(Test_Condition) over (partition by value_partition order by test_iterationnumber) +FROM ( +SELECT +test_iterationnumber, +Test_Condition, +sum(case when Test_Condition is null then 0 else 1 end) over (order by test_iterationnumber) as value_partition + FROM staging2.FTDRY_SUM_Test_Condition_1_Block +ORDER BY test_iterationnumber ASC +) as q) b where a.test_iterationnumber =b.test_iterationnumber; + +delete from staging2.FTDRY_SUM_Test_Condition_1_Block where tractor_model = '0' or engine_rpm_set = '0'; + +update staging2.FTDRY_SUM_Test_Condition_1_Block set fuel_consumption_lit_hr_2=null where fuel_consumption_lit_hr_2 like '%indicates%'; + +update staging2.FTDRY_SUM_Test_Condition_1_Block set fuel_consumption_lit_hr_2 = left(fuel_consumption_lit_hr_2,length(fuel_consumption_lit_hr_2)-3), +Area_covered_acr_hr_2 = left(Area_covered_acr_hr_2,length(Area_covered_acr_hr_2)-3) , +Fuel_consumption_lit_Acr_2 = left(Fuel_consumption_lit_Acr_2,length(Fuel_consumption_lit_Acr_2)-3) +where fuel_consumption_lit_hr_2 notnull; + + + +delete from staging2.FTDRY_SUM_Test_Condition_1_Block where dummy_f is null ; +execute 'update staging2.FTDRY_SUM_Test_Condition_1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTDRY_SUM_Test_Condition_1_Block'); + + +/* blocks data loading start -FTDRY_SUM_Test_Condition_2_Block*/ + + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTDRY_SUM_Test_Condition_2_Block',__file_mnemonic,__file_sheet_mnemonic,4); +err_block:='FTDRY_SUM_Test_Condition_2_Block'; +insert into staging2.FTDRY_SUM_Test_Condition_2_Block +( +dummy_f, +Test_Condition, +Test_Date, +Tractor_Model, +Engine_RPM_set, +PTO_RPM_set, +Gear_Used, +Nominal_Speed_KMPH, +Engine_RPM_Drop_on_straight, +Engine_RPM_Drop_on_turn, +Depth_of_cut_cm, +No_load_speed_kmph, +On_load_speed_kmph, +wheel_slippage_, +Fuel_consumption_lit_hr, +Area_covered_acr_hr, +Fuel_consumption_lit_Acr, +M_M_Performance_in_compared_to_respective_competitor_tractors, +Fuel_consumption_lit_hr_2, +Area_covered_acr_hr_2, +Fuel_consumption_lit_Acr_2, +Trail_Observations, +Engine_Smoke_on_Load, +Engine_acceleration_smoke, +Draft_Response, +Tractor_Steer_ability, +Tractor_braking_performance, +Front_Visibility, +Implement_Accessibility, +Front_Wheel_dragging_at_turning, +Front_end_lifting_during_operation, +RPM_Recovery_Time, +Engine_Vibration, +Engine_Sound, +Implement_Lifting_Lowering_response, +Pulverization_Quality, +Pulverization_Index +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val + FROM staging2.stg_process_table_ftdry_sum where block_tag=''FTDRY_SUM_Test_Condition_2'' + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text, + a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text,a_21 text, + a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text,a_31 text, + a_32 text,a_33 text,a_34 text,a_35 text,a_36 text); + +update staging2.FTDRY_SUM_Test_Condition_2_Block +set test_iterationnumber=3; + +insert into staging2.FTDRY_SUM_Test_Condition_2_Block +( +dummy_f, +Test_Condition, +Test_Date, +Tractor_Model, +Engine_RPM_set, +PTO_RPM_set, +Gear_Used, +Nominal_Speed_KMPH, +Engine_RPM_Drop_on_straight, +Engine_RPM_Drop_on_turn, +Depth_of_cut_cm, +No_load_speed_kmph, +On_load_speed_kmph, +wheel_slippage_, +Fuel_consumption_lit_hr, +Area_covered_acr_hr, +Fuel_consumption_lit_Acr, +M_M_Performance_in_compared_to_respective_competitor_tractors, +Fuel_consumption_lit_hr_2, +Area_covered_acr_hr_2, +Fuel_consumption_lit_Acr_2, +Trail_Observations, +Engine_Smoke_on_Load, +Engine_acceleration_smoke, +Draft_Response, +Tractor_Steer_ability, +Tractor_braking_performance, +Front_Visibility, +Implement_Accessibility, +Front_Wheel_dragging_at_turning, +Front_end_lifting_during_operation, +RPM_Recovery_Time, +Engine_Vibration, +Engine_Sound, +Implement_Lifting_Lowering_response, +Pulverization_Quality, +Pulverization_Index +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column8,column9,column10,column11,column12}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column8::text,column9::text,column10::text,column11::text,column12::text]) AS val + FROM staging2.stg_process_table_ftdry_sum where block_tag=''FTDRY_SUM_Test_Condition_2'' + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text, + a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text,a_21 text, + a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text,a_31 text, + a_32 text,a_33 text,a_34 text,a_35 text,a_36 text); + +update staging2.FTDRY_SUM_Test_Condition_2_Block +set test_iterationnumber=4 +where test_iterationnumber is null; + + update staging2.FTDRY_SUM_Test_Condition_2_Block a + set Test_Condition= b.first_value from (SELECT +test_iterationnumber,Test_Condition, value_partition, first_value(Test_Condition) over (partition by value_partition order by test_iterationnumber) +FROM ( +SELECT +test_iterationnumber, +Test_Condition, +sum(case when Test_Condition is null then 0 else 1 end) over (order by test_iterationnumber) as value_partition + FROM staging2.FTDRY_SUM_Test_Condition_2_Block +ORDER BY test_iterationnumber ASC +) as q) b where a.test_iterationnumber =b.test_iterationnumber; + +delete from staging2.FTDRY_SUM_Test_Condition_2_Block where tractor_model = '0' or engine_rpm_set = '0'; + +update staging2.FTDRY_SUM_Test_Condition_2_Block set fuel_consumption_lit_hr_2=null where fuel_consumption_lit_hr_2 like '%indicates%'; + +update staging2.FTDRY_SUM_Test_Condition_2_Block set fuel_consumption_lit_hr_2 = left(fuel_consumption_lit_hr_2,length(fuel_consumption_lit_hr_2)-3), +Area_covered_acr_hr_2 = left(Area_covered_acr_hr_2,length(Area_covered_acr_hr_2)-3) , +Fuel_consumption_lit_Acr_2 = left(Fuel_consumption_lit_Acr_2,length(Fuel_consumption_lit_Acr_2)-3) +where fuel_consumption_lit_hr_2 notnull; + + + + +delete from staging2.FTDRY_SUM_Test_Condition_2_Block where dummy_f is null ; +execute 'update staging2.FTDRY_SUM_Test_Condition_2_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTDRY_SUM_Test_Condition_2_Block'); + + +/* blocks data loading start -FTDRY_SUM_Comments_By_Block*/ + + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTDRY_SUM_Comments_By_Block',__file_mnemonic,__file_sheet_mnemonic,5); +err_block:='FTDRY_SUM_Comments_By_Block'; + +insert into staging2.FTDRY_SUM_Comments_By_Block (dummy_f) values ('dummy'); + + +execute 'update staging2.FTDRY_SUM_Comments_By_Block set test_engineer_comments_1= +(select column3 from staging2.stg_process_table_ftdry_sum a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.block_tag=''FTDRY_SUM_Engineer_Comments_1'' +and block_row_number=1 ) where dummy_f=''dummy''' ; + +execute 'update staging2.FTDRY_SUM_Comments_By_Block set test_engineer_comments_3= +(select column3 from staging2.stg_process_table_ftdry_sum a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.block_tag=''FTDRY_SUM_Engineer_Comments_2'' +and block_row_number=1 ) where dummy_f=''dummy'''; + +execute 'update staging2.FTDRY_SUM_Comments_By_Block set test_manager_comments_1= +(select column3 from staging2.stg_process_table_ftdry_sum a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.block_tag=''FTDRY_SUM_Manager_Comments_1'' +and block_row_number=1 ) where dummy_f=''dummy'''; + +execute 'update staging2.FTDRY_SUM_Comments_By_Block set test_manager_comments_3= +(select column3 from staging2.stg_process_table_ftdry_sum a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.block_tag=''FTDRY_SUM_Manager_Comments_2'' +and block_row_number=1 ) where dummy_f=''dummy'''; + + +execute 'update staging2.FTDRY_SUM_Comments_By_Block set test_engineer_comments_2= +(select column8 from staging2.stg_process_table_ftdry_sum a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.block_tag=''FTDRY_SUM_Egnineer_Comments_1'' +and block_row_number=1 ) where dummy_f=''dummy'''; + + +execute 'update staging2.FTDRY_SUM_Comments_By_Block set test_engineer_comments_4= +(select column8 from staging2.stg_process_table_ftdry_sum a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.block_tag=''FTDRY_SUM_Engineer_Comments_2'' +and block_row_number=1 ) where dummy_f=''dummy'''; + +execute 'update staging2.FTDRY_SUM_Comments_By_Block set test_manager_comments_2= +(select column8 from staging2.stg_process_table_ftdry_sum a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.block_tag=''FTDRY_SUM_Manager_Comments_1'' +and block_row_number=1 ) where dummy_f=''dummy'''; + +execute 'update staging2.FTDRY_SUM_Comments_By_Block set test_manager_comments_4= +(select column8 from staging2.stg_process_table_ftdry_sum a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.block_tag=''FTDRY_SUM_Manager_Comments_2'' +and block_row_number=1 ) where dummy_f=''dummy'''; + + + + +delete from staging2.FTDRY_SUM_Comments_By_Block where dummy_f is null ; +execute 'update staging2.FTDRY_SUM_Comments_By_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTDRY_SUM_Comments_By_Block'); + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_FTDRY_SUM_Block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; diff --git a/onetime/dataloadfunctions/field/FTDRY_TRS_ODS.sql b/onetime/dataloadfunctions/field/FTDRY_TRS_ODS.sql new file mode 100755 index 0000000..1789238 --- /dev/null +++ b/onetime/dataloadfunctions/field/FTDRY_TRS_ODS.sql @@ -0,0 +1,376 @@ +drop function if exists staging2.fn_FTDRY_TRS_TRX ; +CREATE OR REPLACE FUNCTION staging2.fn_FTDRY_TRS_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + declare __test_tractor_id int; + begin + +__file_syspk := p_file_syspk; +/************************************************************ +Function Name:fn_FTDRY_TRS_TRX +Function Desc: This function populates data into ODS +File Format: FTDRY +Sheet Format: FTDRY_TRS +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_FTDRY_TRS_TRX() +--***************************************************************/ +-- +--delete from transactional.test_instance where file_syspk =836; +-- +--delete from transactional.test_instance_engine_info where file_syspk =836; +-- +--delete from transactional.test_instance_implement_info where file_syspk =836; +-- +--delete from transactional.test_instance_tractor_info where file_syspk =836; +-- +-- +--delete from transactional.test_instance_trailer_info where file_syspk =836; +-- +--delete from transactional.test_instance_tyre_info where file_syspk =836; + +insert into transactional.test_instance +( +client_id, +function_id, +test_report_no, +objective_of_test, +background_of_test, +job_order_no, +test_location_name, +soil_moisture_content_pct, +soil_bulk_density_g_per_cc, +test_engineer, +test_operator, +date_of_test, +test_report_date, +season, +type_of_soil, +soil_cone_index, +field_condition, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +report_reference_no test_report_no, +objective_of_test, +background_of_test, +job_order_no, +test_location test_location_name, +soil_moisture_content_::numeric soil_moisture_content_pct , +soil_bulk_density_g_cc::int soil_bulk_density_g_per_cc, +test_engineer, +test_operator, +date_of_test::date, +report_date::date test_report_date, +season, +type_of_soil, +trim(' Kpa' from soil_cone_index_kpa)::int soil_cone_index, +field_condition, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +from staging2.ftdry_trs_h1_block where trx_record=1; + +insert into transactional.test_instance_tractor_info +( +client_id, +function_id, +tractor_model, +tractor_make, +tractor_sr_no, +tractor_engine_hp, +fip_type, +hour_Meter_Reading, +Steering_Type, +Transmission_Type, +wheel_drive_type, +egr_yn, +Brake_Type, +PTO_Type, +Standard_PTO_Speed_RPM, +EPTO_Speed_RPM, +tractor_weight_front_kg, +tractor_weight_rear_kg, +tractor_weight_total_kg, +Ballasted_Tractor_Accessories, +Mechanical_Ballast_Rear, +mechanical_ballast_rear_in_kg, +water_ballast_rear_75_pct , +Mechanical_Ballast_Front, +mechanical_ballast_front_kg , +Total_Ballast_Weight, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +Tractor_Model, +Tractor_Make, +Tractor_Sr_No, +Tractor_Engine_HP::float, +FIP_Type, +hour_Meter_Reading::numeric, +Steering_Type, +Transmission_Type, +Wheel_Drive_Type_WD wheel_drive_type , +EGR_Yes_No egr_yn, +Brake_Type , +PTO_Type , +Standard_PTO_Speed_RPM::numeric, +EPTO_Speed_RPM, +Tractor_Weight_kg_Front::numeric tractor_weight_front_kg , +Tractor_Weight_kg_Rear::numeric tractor_weight_rear_kg , +Tractor_Weight_kg_Total::numeric tractor_weight_total_kg , +Ballasted_Tractor_Accessories, +Mechanical_Ballast_Rear, +Mechanical_Ballast_Rear_in_KG::numeric mechanical_ballast_rear_in_kg , +Water_Ballast_Rear water_ballast_rear_75_pct , +Mechanical_Ballast_Front, +Mechanical_Ballast_Front_in_Kg::numeric mechanical_ballast_front_kg , +Total_Ballast_Weight::numeric, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +from staging2.ftdry_trs_spec_block where trx_record=1; + +update transactional.test_instance_tractor_info +set mahindra_model_yn = ( +case when tractor_make like 'Mahindra%' then 'Y' else 'N' end +) where file_syspk =__file_syspk; + +update transactional.test_instance_tractor_info a +set test_tractor_yn ='Y' where syspk in +(select min(syspk) from transactional.test_instance_tractor_info b +where b.file_syspk =a.file_syspk) +and a.file_syspk =__file_syspk; + +update transactional.test_instance_tractor_info +set test_tractor_yn ='N' +where test_tractor_yn is null and file_syspk =__file_syspk; + + +insert into transactional.test_instance_tyre_info +( +client_id, +function_id, +tractor_make, +tractor_model, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_sr_no, +tyre_type, +tyre_make, +tyre_size, +tyre_pressure_psi +) +select +client_id, +function_id, +tractor_make, +tractor_model, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_sr_no, +'front', +front_tyre_make tyre_make, +front_tyre_size tyre_size, +front_tyre_pressure_psi::int tyre_pressure_psi +from staging2.ftdry_trs_spec_block where trx_record=1; + +update transactional.test_instance_tyre_info a +set test_instance_tractor_id =(select syspk +from transactional.test_instance_tractor_info b +where a.file_syspk=b.file_syspk and +a.tractor_model=b.tractor_model and a.tractor_sr_no=b.tractor_sr_no) +where a.tyre_type ='front' and a.file_syspk =__file_syspk; + + +insert into transactional.test_instance_tyre_info +( +client_id, +function_id, +tractor_make, +tractor_model, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_sr_no, +tyre_type, +tyre_make, +tyre_size, +tyre_pressure_psi +) +select +client_id, +function_id, +tractor_make, +tractor_model, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_sr_no, +'rear', +rear_tyre_make tyre_make, +rear_tyre_size tyre_size, +rear_tyre_pressure_psi::int tyre_pressure_psi +from staging2.ftdry_trs_spec_block where trx_record=1; + +update transactional.test_instance_tyre_info a +set test_instance_tractor_id =(select syspk +from transactional.test_instance_tractor_info b +where a.file_syspk=b.file_syspk and +a.tractor_model=b.tractor_model and a.tractor_sr_no=b.tractor_sr_no) +where a.tyre_type ='rear' and a.file_syspk = __file_syspk; + +insert into transactional.test_instance_engine_info +( +client_id, +function_id, +low_idle_observed , +high_idle_observed , +rated_rpm , +engine_to_pto_ratio_540_pto, +engine_to_pto_ratio_540e_pto, +tractor_model, +tractor_make, +tractor_sr_no, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +low_idle::int low_idle_observed , +high_idle::int high_idle_observed , +rated_rpm::int, +engine_to_pto_ratio_540_pto, +engine_to_pto_ratio_540e_pto, +tractor_model, +tractor_make, +tractor_sr_no, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +from staging2.ftdry_trs_engine_rpm_block +where trx_record=1; + +update transactional.test_instance_engine_info a +set test_instance_tractor_id =(select syspk +from transactional.test_instance_tractor_info b +where a.file_syspk=b.file_syspk and +a.tractor_model=b.tractor_model and a.tractor_sr_no=b.tractor_sr_no) +where a.file_syspk = __file_syspk; + +insert into transactional.test_instance_implement_info +( +client_id, +function_id, +name_of_implement, +type_of_implement, +make_of_implement, +no_of_disc_blades_bottoms, +cutting_width_m, +implement_weight_kg, +hitch_category, +span_for_mounted_implement_mm , +mast_height_for_mounted_implement_mm, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +name_of_implement, +type_of_implement, +make_of_implement, +no_of_bottoms_tyne_disc_blade no_of_disc_blades_bottoms, +cutting_width_m, +trim('kg' from implement_weight_kg)::numeric, +hitch_category, +span_cm_for_mounted_implement::numeric span_for_mounted_implement_cm , +mast_height_cm_for_mounted_implement::numeric mast_height_for_mounted_implement_cm, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +from staging2.ftdry_trs_implement_block where trx_record=1; + +update transactional.test_instance a +set report_template_no=b.report_template_no, +report_template_rev_no=b.report_template_rev_no, +report_template_rev_date =b.report_template_rev_date +from staging2.ftdry_trs_implement_block b where trx_record=1 +and a.file_syspk=b.file_syspk; + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select syspk from transactional.test_master into __test_master_id where test_type ='Field'; +select syspk from transactional.test_instance_tractor_info into __test_tractor_id +where file_syspk =__file_syspk and test_tractor_yn ='Y'; + + +update transactional.test_instance +set test_master_id =__test_master_id, +test_tractor_id =__test_tractor_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_engine_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_tyre_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.test_instance_implement_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.test_instance +set test_file_name =(select a.file_name from staging1.staging_generic_table a where file_syspk = __file_syspk limit 1) +where file_syspk = __file_syspk; + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_FTDRY_TRS_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + + + diff --git a/onetime/dataloadfunctions/field/FTDRY_TRS_STG2.sql b/onetime/dataloadfunctions/field/FTDRY_TRS_STG2.sql new file mode 100755 index 0000000..d6f4832 --- /dev/null +++ b/onetime/dataloadfunctions/field/FTDRY_TRS_STG2.sql @@ -0,0 +1,413 @@ +/*FTDRY_starts*/ +drop function if exists staging2.fn_FTDRY_TRS_Block ; +CREATE OR REPLACE FUNCTION staging2.fn_FTDRY_TRS_Block(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + begin + + +/*********************************************************************************** +Function Name:fn_FTDRY_TRS_Block +Function Desc: This function populates data into staging2 blocks +File Format: FTDRY +Sheet Format: FTDRY_TRS +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_FTDRY_TRS_Block(20,1,'FTDRY','FTDRY_TRS',257); +************************************************************************************/ + +SET search_path TO staging2; + +truncate staging2.FTDRY_TRS_H1_INT; +truncate staging2.ftdry_trs_h1_block ; +truncate staging2.ftdry_trs_implement_block ; +truncate staging2.ftdry_trs_spec_block; +truncate staging2.ftdry_trs_engine_rpm_block; +truncate staging2.stg_specific_table_ftdry_trs; +truncate staging2.stg_process_table_ftdry_trs; + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/* transfer data from generic to specific for ftdry*/ + +execute 'insert into staging2.stg_specific_table_ftdry_trs +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_ftdry_trs; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for FTDRY Tractor Specifications', + detail = 'No data in table stg_specific_table_ftdry_trs', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; +/* trimming data */ + +update staging2.stg_specific_table_ftdry_trs set column2 = TRIM (TRAILING FROM column2 ); +update staging2.stg_specific_table_ftdry_trs set column2 = TRIM (LEADING FROM column2 ); +--update transactional.source_config set F1_modified = TRIM (TRAILING FROM F1_modified); +--update transactional.source_config set F1_modified = TRIM (LEADING FROM F1_modified); +--update transactional.source_config set F1_source = TRIM (TRAILING FROM F1_source) ; +--update transactional.source_config set F1_source = TRIM (LEADING FROM F1_source); + + +update transactional.source_config set F1_source=F1_modified; + +/* keyword match in config table*/ + +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_ftdry_trs b +where upper(F1_source)= upper(column2) +and b.is_rownumber_fetched is null) +where a.row_number_start is null and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update in process table for match*/ +execute 'update staging2.stg_specific_table_ftdry_trs a +set is_rownumber_fetched=1 +from transactional.source_config b +where upper(F1_source)= upper(column2) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* update config files for row numbers start, end */ + +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a set row_read_end = null +where f1_modified =''Implement Details'' and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/*inserting run_time in config*/ +execute 'update transactional.source_config a +set run_time=current_timestamp +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/* tagging block_row_numbers for each block in process table*/ + +execute 'insert into staging2.stg_process_table_ftdry_trs +select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag +from staging2.stg_specific_table_ftdry_trs a +join transactional.source_config b +on a.row_number >row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Tractor Specifications Sheet'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + + +execute 'insert into staging2.stg_process_table_ftdry_trs +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_ftdry_trs a +join transactional.source_config b +on a.row_number >row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Tractor Specifications'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +execute 'insert into staging2.stg_process_table_ftdry_trs +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_ftdry_trs a +join transactional.source_config b +on a.row_number >row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Engine RPM Data:'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + +execute 'insert into staging2.stg_process_table_ftdry_trs +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_ftdry_trs a +join transactional.source_config b +on a.row_number >row_number_start +and a.column2 <> '''' +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Implement Details'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +/*insert data into h1_int */ + +insert into staging2.FTDRY_TRS_H1_INT( +column2,column3,column4,column5,column6,column7,block_row_number) +select column2,column3,column4,column5,column6,column7,block_row_number +from staging2.stg_process_table_ftdry_trs a where block_tag='FTDRY_TRS_H1' +order by block_row_number; + +insert into staging2.FTDRY_TRS_H1_INT(column2,column3) +select 'Date of Test',column5 +from staging2.FTDRY_TRS_H1_INT +where block_row_number=1; + +insert into staging2.FTDRY_TRS_H1_INT(column2,column3) +select 'Report Date',column7 +from staging2.FTDRY_TRS_H1_INT +where block_row_number=1; + + +insert into staging2.FTDRY_TRS_H1_INT(column2,column3) +select column5,column6 +from staging2.FTDRY_TRS_H1_INT where block_row_number between 4 and 7; + + + +/*inserting data into block -FTDRY_TRS_H1_Block*/ + + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTDRY_TRS_H1_Block',__file_mnemonic,__file_sheet_mnemonic,1); + +err_block:='FTDRY_TRS_H1_Block'; +insert into staging2.FTDRY_TRS_H1_Block +( +dummy_f, +Report_Reference_No, +Objective_Of_Test, +Background_of_Test, +Job_Order_No, +Test_Location, +Soil_Moisture_Content_, +Soil_Bulk_Density_g_cc, +Test_Engineer, +Test_Operator, +Date_of_Test, +Report_Date, +Season, +Type_of_Soil, +Soil_Cone_Index_kPa, +Field_Condition +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column3}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column3::text]) AS val + FROM staging2.FTDRY_TRS_H1_INT + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text, + a_11 text,a_12 text,a_13 text,a_14 text,a_15 text); + + +delete from staging2.FTDRY_TRS_H1_Block where dummy_f is null ; +execute 'update staging2.FTDRY_TRS_H1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTDRY_TRS_H1_Block'); + + +/*inserting data into block -FTDRY_TRS_SPEC_Block*/ + + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTDRY_TRS_SPEC_Block',__file_mnemonic,__file_sheet_mnemonic,2); + +err_block:='FTDRY_TRS_SPEC_Block'; + +insert into staging2.FTDRY_TRS_SPEC_Block +( +dummy_f, +Tractor_Model, +Tractor_Make, +Tractor_Sr_No, +Tractor_Engine_HP, +FIP_Type, +hour_Meter_Reading, +Steering_Type, +Transmission_Type, +Wheel_Drive_Type_WD, +EGR_Yes_No, +Brake_Type, +PTO_Type, +Standard_PTO_Speed_RPM, +EPTO_Speed_RPM, +Front_Tyre_Make, +Front_Tyre_Size, +Front_Tyre_Pressure_psi, +Rear_Tyre_Make, +Rear_Tyre_Size, +Rear_Tyre_Pressure_psi , +Tractor_Weight_kg_Front , +Tractor_Weight_kg_Rear , +Tractor_Weight_kg_Total, +Ballasted_Tractor_Accessories, +Mechanical_Ballast_Rear, +Mechanical_Ballast_Rear_in_KG , +Water_Ballast_Rear, +Mechanical_Ballast_Front, +Mechanical_Ballast_Front_in_Kg, +Total_Ballast_Weight +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val + FROM staging2.stg_process_table_ftdry_trs where block_tag=''FTDRY_TRS_SPEC'' + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text, + a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text,a_21 text, + a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text); + +update staging2.FTDRY_TRS_SPEC_Block set trx_record=0 +where tractor_make is null and tractor_sr_no is null; + +update staging2.FTDRY_TRS_SPEC_Block set trx_record=0 +where (tractor_model is null and front_tyre_make is null) or (tractor_model is null and rear_tyre_make is null); + + +delete from staging2.FTDRY_TRS_SPEC_Block where dummy_f is null ; +execute 'update staging2.FTDRY_TRS_SPEC_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTDRY_TRS_SPEC_Block'); + + +/*inserting data into block -FTDRY_TRS_Engine_RPM_Block*/ + + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTDRY_TRS_Engine_RPM_Block',__file_mnemonic,__file_sheet_mnemonic,3); + +err_block:='FTDRY_TRS_Engine_RPM_Block'; +insert into staging2.FTDRY_TRS_Engine_RPM_Block +( +dummy_f, +tractor_model, +tractor_make, +tractor_sr_no, +Low_Idle, +High_Idle, +Rated_RPM, +Engine_to_PTO_Ratio_540_PTO, +Engine_to_PTO_Ratio_540E_PTO +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val + FROM staging2.stg_process_table_ftdry_trs where block_tag=''FTDRY_TRS_Engine_RPM'' + or (block_tag=''FTDRY_TRS_SPEC'' and block_row_number in (1,2,3)) + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text); + +update staging2.FTDRY_TRS_Engine_RPM_Block set trx_record=0 +where tractor_make is null and tractor_sr_no is null; + +delete from staging2.FTDRY_TRS_Engine_RPM_Block where dummy_f is null ; +execute 'update staging2.FTDRY_TRS_Engine_RPM_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTDRY_TRS_Engine_RPM_Block'); + + +/*inserting data into block -FTDRY_TRS_Implement_Block*/ + + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTDRY_TRS_Implement_Block',__file_mnemonic,__file_sheet_mnemonic,4); + +err_block:='FTDRY_TRS_Implement_Block'; +insert into staging2.FTDRY_TRS_Implement_Block +( +dummy_f, +Name_of_Implement, +Type_of_Implement, +Make_of_Implement, +No_of_bottoms_Tyne_Disc_Blade, +Cutting_Width_m, +Implement_Weight_Kg, +Hitch_Category, +Span_cm_For_Mounted_Implement, +Mast_Height_cm_For_Mounted_Implement +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column3,column4,column5,column6}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column3::text,column4::text,column5::text,column6::text]) AS val + FROM staging2.stg_process_table_ftdry_trs where block_tag=''FTDRY_TRS_Implement'' + ORDER BY generate_series(1,15),block_row_number,2' + ) t ( col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text); + +update staging2.FTDRY_TRS_Implement_Block set trx_record=0 +where name_of_implement is null; + +update staging2.FTDRY_TRS_Implement_Block set dummy_f='dummy' where dummy_f is null; + +update staging2.FTDRY_TRS_Implement_Block set report_template_no= (select column2 from staging2.stg_process_table_ftdry_trs where block_row_number=10 and block_tag='FTDRY_TRS_Implement'); + + +update staging2.FTDRY_TRS_Implement_Block set report_template_rev_no= (select column4 from staging2.stg_process_table_ftdry_trs where block_row_number=10 and block_tag='FTDRY_TRS_Implement'); + + +update staging2.FTDRY_TRS_Implement_Block set report_template_rev_date= (select column6 from staging2.stg_process_table_ftdry_trs where block_row_number=10 and block_tag='FTDRY_TRS_Implement'); + + +execute 'update staging2.FTDRY_TRS_Implement_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTDRY_TRS_Implement_Block'); + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_FTDRY_TRS_Block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + diff --git a/onetime/dataloadfunctions/field/FTHLG_SUM_ods.sql b/onetime/dataloadfunctions/field/FTHLG_SUM_ods.sql new file mode 100755 index 0000000..067ba2a --- /dev/null +++ b/onetime/dataloadfunctions/field/FTHLG_SUM_ods.sql @@ -0,0 +1,401 @@ +drop function if exists staging2.fn_FTHLG_SUM_TRX ; +CREATE OR REPLACE FUNCTION staging2.fn_FTHLG_SUM_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + begin + +__file_syspk := p_file_syspk; + +/************************************************************ +Function Name:fn_FTHLG_SUM_TRX +Function Desc: This function populates data into ODS +File Format: FTHLG +Sheet Format: FTHLG_SUM +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_FTHLG_SUM_TRX(); +***************************************************************/ + + +insert into transactional.field_perf_summary_tractor_info +( +client_id, +function_id, +tractor_model, +tractor_make, +tractor_engine_hp, +rated_rpm, +transmission_type, +wheel_drive_type, +fip_type, +steering_type, +tractor_weight_front_kg, +tractor_weight_rear_kg, +tractor_weight_total_kg, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +tractor_model, +tractor_make , +tractor_engine_hp::numeric, +rated_rpm::numeric, +transmission_type, +wheel_drive_type, +fip_type, +steering_type, +tractor_weight_kg_front::numeric tractor_weight_front_kg, +tractor_weight_kg_rear::numeric tractor_weight_rear_kg, +tractor_weight_kg_total::numeric tractor_weight_total_kg, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +from staging2.fthlg_sum_trac_h1_block where trx_record=1; + + +insert into transactional.field_perf_summary_trailer_info +( +client_id, +function_id, +trailer_type, +tire_size_and_inflation_pressure_psi, +no_of_axle, +no_of_wheels, +trailer_gross_weight_kg, +tractor_rwc_to_hitch_point_center_dist_mm, +tractor_hitch_ht_mm, +trailer_hitch_height_above_ground_level_mm, +gradient_slope_1_degree, +gradient_slope_2_degree, +tractor_hitch_type, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +Trailer_Type, +Tire_size_and_inflation_pressure_psi, +No_Of_Axle::numeric , +No_Of_Wheels::numeric, +Trailer_Gross_Weight_Kg::numeric, +Tractor_Rear_Wheel_Center_to_Hitch_Point_Center_Distance_mm::numeric, +Tractor_Hitch_Height_from_Ground_mm::numeric, +Trailer_hitch_Height_above_ground_level_mm::numeric, +Gradient_Slope_1_Degree::numeric, +Gradient_Slope_2_degree::numeric, +Tractor_Hitch_Type, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +from staging2.FTHLG_SUM_Trail_Type_Block where trx_record=1; + +insert into transactional.field_perf_summary +( +client_id, +function_id, +test_iteration_number, +test_condition, +test_date, +tractor_model, +fuel_consumption_lit_per_hr, +mileage_km_per_ltr, +avg_speed_of_travel_kmph, +total_dist_travelled_km, +gear_used_on_straight_road, +straight_road_rpm_drop, +gear_used_on_up_slope_1, +up_slope_rpm_drop_1, +gear_used_on_up_slope_2, +up_slope_rpm_drop_2, +gear_used_on_down_slope, +down_slope_rpm_shoot_up, +fuel_consumption_var_lit_per_hr, +mileage_var_km_per_ltr, +fuel_consumption_var_pct_lit_per_hr, +mileage_var_pct_km_per_ltr, +engine_smoke_on_load, +engine_acceleration_smoke, +range_gear_shifting, +speed_gear_shifting, +tractor_steer_ability, +tractor_braking_perf, +front_visibility, +implement_accessibility, +front_end_lifting_during_operation, +rpm_recovery_time, +engine_vibration, +engine_sound, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +test_iterationnumber::numeric, +Test_Condition, +Test_Date::date, +Tractor_Model, +Fuel_consumption_Ltr_hr::numeric fuel_consumption_lit_per_hr , +Mileage_Km_Ltr ::numeric mileage_km_per_ltr , +Average_speed_of_travel_kmph::numeric avg_speed_of_travel_kmph , +Total_distance_travelled_km::numeric total_dist_travelled_km , +Gear_used_on_Straight_Road, +Straight_road_RPM_Drop, +Gear_used_on_Up_Slope_1, +Up_Slope_RPM_Drop_1 , +Gear_used_on_Up_Slope_2, +Up_Slope_RPM_Drop_2, +Gear_used_on_Down_Slope, +Down_Slope_RPM_Shoot_up, +fuel_consumption_lit_hr_2::numeric , +Mileage_Km_Ltr_2::numeric , +fuel_consumption_lit_hr_3::numeric , +Mileage_Km_Ltr_3::numeric, +engine_smoke_on_load, +Engine_acceleration_smoke, +Range_Gear_Shifting, +Speed_Gear_Shifting, +Tractor_Steer_ability, +Tractor_braking_performance tractor_braking_perf , +Front_Visibility, +Implement_Accessibility, +Front_end_lifting_during_operation, +RPM_Recovery_Time, +Engine_Vibration, +Engine_Sound, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +from staging2.fthlg_sum_test_condition_1_block +where trx_record=1; + + + +insert into transactional.field_perf_summary +( +client_id, +function_id, +test_iteration_number, +test_condition, +test_date, +tractor_model, +fuel_consumption_lit_per_hr, +mileage_km_per_ltr, +avg_speed_of_travel_kmph, +total_dist_travelled_km, +gear_used_on_straight_road, +straight_road_rpm_drop, +gear_used_on_up_slope_1, +up_slope_rpm_drop_1, +gear_used_on_up_slope_2, +up_slope_rpm_drop_2, +gear_used_on_down_slope, +down_slope_rpm_shoot_up, +fuel_consumption_var_lit_per_hr, +mileage_var_km_per_ltr, +fuel_consumption_var_pct_lit_per_hr, +mileage_var_pct_km_per_ltr, +engine_smoke_on_load, +engine_acceleration_smoke, +range_gear_shifting, +speed_gear_shifting, +tractor_steer_ability, +tractor_braking_perf, +front_visibility, +implement_accessibility, +front_end_lifting_during_operation, +rpm_recovery_time, +engine_vibration, +engine_sound, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +test_iterationnumber::numeric, +Test_Condition, +Test_Date::date, +Tractor_Model, +Fuel_consumption_Ltr_hr::numeric fuel_consumption_lit_per_hr , +Mileage_Km_Ltr ::numeric mileage_km_per_ltr , +Average_speed_of_travel_kmph::numeric avg_speed_of_travel_kmph , +Total_distance_travelled_km::numeric total_dist_travelled_km , +Gear_used_on_Straight_Road, +Straight_road_RPM_Drop, +Gear_used_on_Up_Slope_1, +Up_Slope_RPM_Drop_1 , +Gear_used_on_Up_Slope_2, +Up_Slope_RPM_Drop_2, +Gear_used_on_Down_Slope, +Down_Slope_RPM_Shoot_up, +fuel_consumption_lit_hr_2::numeric , +Mileage_Km_Ltr_2::numeric, +fuel_consumption_lit_hr_3::numeric , +Mileage_Km_Ltr_3::numeric, +engine_smoke_on_load, +Engine_acceleration_smoke, +Range_Gear_Shifting, +Speed_Gear_Shifting, +Tractor_Steer_ability, +Tractor_braking_performance tractor_braking_perf , +Front_Visibility, +Implement_Accessibility, +Front_end_lifting_during_operation, +RPM_Recovery_Time, +Engine_Vibration, +Engine_Sound, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +from staging2.fthlg_sum_test_condition_2_block +where trx_record=1; + + + +update transactional.field_perf_summary_tractor_info a +set test_instance_tractor_id = (select syspk +from transactional.test_instance_tractor_info b +where a.tractor_model=trim(b.tractor_model) and a.file_syspk =b.file_syspk +)where a.file_syspk =__file_syspk; + + + + +update transactional.field_perf_summary a +set test_engr_comments=b.test_engineer_comments_1, +test_mgr_comments =b.test_manager_comments_1 +from staging2.fthlg_sum_comments_by_block b +where a.file_syspk=b.file_syspk and a.test_iteration_number =1; + +update transactional.field_perf_summary a +set test_engr_comments=b.test_engineer_comments_2, +test_mgr_comments =b.test_manager_comments_2 +from staging2.fthlg_sum_comments_by_block b +where a.file_syspk=b.file_syspk and a.test_iteration_number =2; + +update transactional.field_perf_summary a +set test_engr_comments=b.test_engineer_comments_3, +test_mgr_comments =b.test_manager_comments_3 +from staging2.fthlg_sum_comments_by_block b +where a.file_syspk=b.file_syspk and a.test_iteration_number =3; + +update transactional.field_perf_summary a +set test_engr_comments=b.test_engineer_comments_4, +test_mgr_comments =b.test_manager_comments_4 +from staging2.fthlg_sum_comments_by_block b +where a.file_syspk=b.file_syspk and a.test_iteration_number =4; + + + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; + +update transactional.field_perf_summary +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.field_perf_summary_implement_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.field_perf_summary_tractor_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.field_perf_summary_trailer_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.field_perf_summary a +set test_instance_tractor_id = (select syspk +from transactional.test_instance_tractor_info b +where a.tractor_model=b.tractor_model and a.file_syspk =b.file_syspk +)where test_iteration_number =1 and a.file_syspk =__file_syspk; + +update transactional.field_perf_summary a +set test_instance_tractor_id = (select syspk +from transactional.test_instance_tractor_info b +where a.tractor_model=b.tractor_model and a.file_syspk =b.file_syspk +)where test_iteration_number =2 and a.file_syspk =__file_syspk; + +update transactional.field_perf_summary a +set test_instance_tractor_id = (select syspk +from transactional.test_instance_tractor_info b +where a.tractor_model=b.tractor_model and a.file_syspk =b.file_syspk +)where test_iteration_number =3 and a.file_syspk =__file_syspk; + + +update transactional.field_perf_summary a +set test_instance_tractor_id = (select syspk +from transactional.test_instance_tractor_info b +where a.tractor_model=b.tractor_model and a.file_syspk =b.file_syspk +)where test_iteration_number =4 and a.file_syspk =__file_syspk; + + +update transactional.field_perf_summary +set straight_road_rpm_drop =replace(straight_road_rpm_drop,' to ','-'), +up_slope_rpm_drop_1 =replace(up_slope_rpm_drop_1,' to ','-'), +up_slope_rpm_drop_2 =replace(up_slope_rpm_drop_2,' to ','-'), +down_slope_rpm_shoot_up=replace(down_slope_rpm_shoot_up,' to ','-') +where file_mnemonic = 'FTHLG'; + + + +UPDATE transactional.field_perf_summary + SET +--updating RPM drop straight: + erpmdrop_straight_1stpass_low = trim(split_part(trim(straight_road_rpm_drop), '-', 1))::numeric, + erpmdrop_straight_1stpass_high = case trim(split_part(trim(straight_road_rpm_drop), '-', 2)) + when '' then null + else trim(split_part(trim(straight_road_rpm_drop), '-', 2))::numeric end, +--updating RPM drop up slop 1st pass: + erpmdrop_turn_1stpass_low = trim(split_part(trim(up_slope_rpm_drop_1), '-', 1))::numeric, + erpmdrop_turn_1stpass_high = case trim(split_part(trim(up_slope_rpm_drop_1), '-', 2)) + when '' then null + else trim(split_part(trim(up_slope_rpm_drop_1), '-', 2))::numeric end, +--updating RPM drop up slop 2nd pass: + erpmdrop_turn_2ndpass_low = trim(split_part(trim(up_slope_rpm_drop_2), '-', 1))::numeric, + erpmdrop_turn_2ndpass_high = case trim(split_part(trim(up_slope_rpm_drop_2), '-', 2)) + when '' then null + else trim(split_part(trim(up_slope_rpm_drop_2), '-', 2))::numeric end, +--updating down slope rpm shoot up : + erpmdrop_turn_3rdpass_low = trim(split_part(trim(down_slope_rpm_shoot_up), '-', 1))::numeric, + erpmdrop_turn_3rdpass_high = case trim(split_part(trim(down_slope_rpm_shoot_up), '-', 2)) + when '' then null + else trim(split_part(trim(down_slope_rpm_shoot_up), '-', 2))::numeric end + where file_mnemonic = 'FTHLG'; + + + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_FTHLG_SUM_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + diff --git a/onetime/dataloadfunctions/field/FTHLG_SUM_stg2.sql b/onetime/dataloadfunctions/field/FTHLG_SUM_stg2.sql new file mode 100755 index 0000000..27b90f3 --- /dev/null +++ b/onetime/dataloadfunctions/field/FTHLG_SUM_stg2.sql @@ -0,0 +1,792 @@ +drop function if exists staging2.fn_FTHLG_SUM_Block ; +CREATE OR REPLACE FUNCTION staging2.fn_FTHLG_SUM_Block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + + begin + + + +/*********************************************************************************** +Function Name:fn_FTHLG_SUM_Block +Function Desc: This function populates data into staging2 blocks +File Format: FTHLG +Sheet Format: FTHLG_SUM +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_fthlg_sum_block(20,1,'FTHLG','FTHLG_SUM',259); +************************************************************************************/ + + +SET search_path TO staging2; +truncate staging2.FTHLG_SUM_Trac_H1_Block; +truncate staging2.FTHLG_SUM_Trail_Type_Block; +truncate staging2.FTHLG_SUM_Test_Condition_1_Block; +truncate staging2.FTHLG_SUM_Test_Condition_2_Block; +truncate staging2.FTHLG_SUM_Comments_By_Block; +truncate staging2.stg_specific_table_fthlg_sum; +truncate staging2.stg_process_table_fthlg_sum; + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/* transfer data from generic to specific for fthlg*/ + +execute 'insert into staging2.stg_specific_table_fthlg_sum +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_fthlg_sum; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for FTHLG Summary', + detail = 'No data in table stg_specific_table_fthlg_sum', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + +/* trimming data */ + +update staging2.stg_specific_table_fthlg_sum set column2 = TRIM (TRAILING FROM column2 ); +update staging2.stg_specific_table_fthlg_sum set column2 = TRIM (LEADING FROM column2 ); +--update transactional.source_config set F1_modified = TRIM (TRAILING FROM F1_modified); +--update transactional.source_config set F1_modified = TRIM (LEADING FROM F1_modified) ; +--update transactional.source_config set F1_source = TRIM (TRAILING FROM F1_source) ; +--update transactional.source_config set F1_source = TRIM (LEADING FROM F1_source) ; + + +update transactional.source_config set F1_source=F1_modified ; +/* keyword match in config table*/ +execute 'update transactional.source_config a set f1_source = replace(f1_source,''_1'','''') +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_fthlg_sum b +where F1_source=column2 +and b.is_rownumber_fetched is null) +where a.row_number_start is null + and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update in process table for match*/ +execute 'update staging2.stg_specific_table_fthlg_sum a +set is_rownumber_fetched=1 +from transactional.source_config b +where F1_source=column2 +and b.row_number_start=a.row_number +and is_rownumber_fetched is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* keyword match in config table*/ +execute 'update transactional.source_config a set f1_source = replace(f1_source,''_2'','''') + where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_fthlg_sum b +where F1_source=column2 +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update in process table for match*/ +execute 'update staging2.stg_specific_table_fthlg_sum a +set is_rownumber_fetched=1 +from transactional.source_config b +where F1_source=column2 +and b.row_number_start=a.row_number +and is_rownumber_fetched is null and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* update config files for row numbers start, end */ + +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a set row_read_end = null where f1_modified =''Test Manager Comments_2'' and + a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/*inserting run_time in config*/ +execute 'update transactional.source_config a +set run_time=current_timestamp +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/* tagging block_row_numbers for each block in process table*/ +execute 'insert into staging2.stg_process_table_fthlg_sum +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_fthlg_sum a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Tractor Model'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + + +execute 'insert into staging2.stg_process_table_fthlg_sum +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_fthlg_sum a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Trailer Type'' + and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +execute 'insert into staging2.stg_process_table_fthlg_sum +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_fthlg_sum a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Condition_1:'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +execute 'insert into staging2.stg_process_table_fthlg_sum +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_fthlg_sum a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Engineer Comments_1'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +execute 'insert into staging2.stg_process_table_fthlg_sum +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_fthlg_sum a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Manager Comments_1'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + +execute 'insert into staging2.stg_process_table_fthlg_sum +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_fthlg_sum a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Condition_2:'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +execute 'insert into staging2.stg_process_table_fthlg_sum +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_fthlg_sum a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Engineer Comments_2'' +and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +execute 'insert into staging2.stg_process_table_fthlg_sum +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_fthlg_sum a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Manager Comments_2'' + and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + + +/*inserting data into block -FTHLG_SUM_Trac_H1_Block*/ + + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTHLG_SUM_Trac_H1_Block',__file_mnemonic,__file_sheet_mnemonic,1); + +err_block:='FTHLG_SUM_Trac_H1_Block'; + +insert into staging2.FTHLG_SUM_Trac_H1_Block +( +tractor_model, +tractor_make , +tractor_engine_hp, +rated_rpm, +transmission_type, +wheel_drive_type, +fip_type, +steering_type, +tractor_weight_kg_front, +tractor_weight_kg_rear, +tractor_weight_kg_total, +block_row_number +) +select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_fthlg_sum +where block_tag='FTHLG_SUM_Trac_H1' +order by block_row_number; + +update staging2.FTHLG_SUM_Trac_H1_Block set trx_record =0 where tractor_model = '0'; + +update staging2.FTHLG_SUM_Trac_H1_Block set trx_record=0 where block_row_number in (1,2); + + +execute 'update staging2.FTHLG_SUM_Trac_H1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTHLG_SUM_Trac_H1_Block'); + + +/*inserting data into block -FTHLG_SUM_Trail_Type_Block*/ + + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTHLG_SUM_Trail_Type_Block',__file_mnemonic,__file_sheet_mnemonic,2); +err_block:='FTHLG_SUM_Trail_Type_Block'; + +insert into staging2.FTHLG_SUM_Trail_Type_Block +( +Trailer_Type, +Tire_size_and_inflation_pressure_psi, +No_Of_Axle, +No_Of_Wheels, +Trailer_Gross_Weight_Kg, +Tractor_Rear_Wheel_Center_to_Hitch_Point_Center_Distance_mm, +Tractor_Hitch_Height_from_Ground_mm, +Trailer_hitch_Height_above_ground_level_mm, +Gradient_Slope_1_Degree, +Gradient_Slope_2_degree, +Tractor_Hitch_Type, +block_row_number +) +select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_fthlg_sum +where block_tag='FTHLG_SUM_Trail_Type' +order by block_row_number; + +update staging2.FTHLG_SUM_Trail_Type_Block set trx_record=0 where block_row_number = 1; + + update staging2.FTHLG_SUM_Trail_Type_Block a + set trailer_hitch_height_above_ground_level_mm= b.first_value from (SELECT +block_row_number,trailer_hitch_height_above_ground_level_mm, value_partition, first_value(trailer_hitch_height_above_ground_level_mm) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +trailer_hitch_height_above_ground_level_mm, +sum(case when trailer_hitch_height_above_ground_level_mm is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.FTHLG_SUM_Trail_Type_Block where block_row_number >= 2 +ORDER BY block_row_number asc +) as q) b where a.block_row_number = b.block_row_number; + + update staging2.FTHLG_SUM_Trail_Type_Block a + set tractor_hitch_height_from_ground_mm= b.first_value from (SELECT +block_row_number,tractor_hitch_height_from_ground_mm, value_partition, first_value(tractor_hitch_height_from_ground_mm) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +tractor_hitch_height_from_ground_mm, +sum(case when tractor_hitch_height_from_ground_mm is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.FTHLG_SUM_Trail_Type_Block where block_row_number >= 2 +ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + + update staging2.FTHLG_SUM_Trail_Type_Block a + set gradient_slope_1_degree= b.first_value from (SELECT +block_row_number,gradient_slope_1_degree, value_partition, first_value(gradient_slope_1_degree) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +gradient_slope_1_degree, +sum(case when gradient_slope_1_degree is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.FTHLG_SUM_Trail_Type_Block where block_row_number >= 2 +ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + + update staging2.FTHLG_SUM_Trail_Type_Block a + set gradient_slope_2_degree= b.first_value from (SELECT +block_row_number,gradient_slope_2_degree, value_partition, first_value(gradient_slope_2_degree) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +gradient_slope_2_degree, +sum(case when gradient_slope_2_degree is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.FTHLG_SUM_Trail_Type_Block where block_row_number >= 2 +ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + + update staging2.FTHLG_SUM_Trail_Type_Block a + set tractor_hitch_type= b.first_value from (SELECT +block_row_number,tractor_hitch_type, value_partition, first_value(tractor_hitch_type) over (partition by value_partition order by block_row_number) +FROM ( +SELECT +block_row_number, +tractor_hitch_type, +sum(case when tractor_hitch_type is null then 0 else 1 end) over (order by block_row_number) as value_partition + FROM staging2.FTHLG_SUM_Trail_Type_Block where block_row_number >= 2 +ORDER BY block_row_number ASC +) as q) b where a.block_row_number = b.block_row_number; + +update staging2.FTHLG_SUM_Trail_Type_Block set trx_record=0 +where Trailer_Type in ('Performance Test Results'); + +execute 'update staging2.FTHLG_SUM_Trail_Type_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTHLG_SUM_Trail_Type_Block'); + + +/*inserting data into block -FTHLG_SUM_Test_Condition_1_Block*/ + + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTHLG_SUM_Test_Condition_1_Block',__file_mnemonic,__file_sheet_mnemonic,3); + +err_block:='FTHLG_SUM_Test_Condition_1_Block'; + +insert into staging2.FTHLG_SUM_Test_Condition_1_Block +( +dummy_f, +Test_Condition, +Test_Date, +Tractor_Model, +Fuel_consumption_Ltr_hr, +Mileage_Km_Ltr, +Average_speed_of_travel_kmph, +Total_distance_travelled_km, +Gear_used_on_Straight_Road, +Straight_road_RPM_Drop, +Gear_used_on_Up_Slope_1, +Up_Slope_RPM_Drop_1, +Gear_used_on_Up_Slope_2, +Up_Slope_RPM_Drop_2, +Gear_used_on_Down_Slope, +Down_Slope_RPM_Shoot_up, +Performance_compared_to_respective_competitor_tractors, +Fuel_consumption_lit_hr_2, +Mileage_Km_Ltr_2, +M_M_Performance_in_compared_to_respective_competitor_tractors, +Fuel_consumption_lit_hr_3, +Mileage_Km_Ltr_3, +Engine_Smoke_on_Load, +Engine_acceleration_smoke, +Range_Gear_Shifting, +Speed_Gear_Shifting, +Tractor_Steer_ability, +Tractor_braking_performance, +Front_Visibility, +Implement_Accessibility, +Front_end_lifting_during_operation, +RPM_Recovery_Time, +Engine_Vibration, +Engine_Sound +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column3::text, +column4::text,column5::text,column6::text,column7::text]) AS val + FROM staging2.stg_process_table_FTHLG_sum where block_tag=''FTHLG_SUM_Test_Condition_1'' + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text, + a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text + ,a_21 text,a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text, +a_31 text,a_32 text,a_33 text); + + +update staging2.FTHLG_SUM_Test_Condition_1_Block +set test_iterationnumber=1; + + + +insert into staging2.FTHLG_SUM_Test_Condition_1_Block +( +dummy_f, +Test_Condition, +Test_Date, +Tractor_Model, +Fuel_consumption_Ltr_hr, +Mileage_Km_Ltr, +Average_speed_of_travel_kmph, +Total_distance_travelled_km, +Gear_used_on_Straight_Road, +Straight_road_RPM_Drop, +Gear_used_on_Up_Slope_1, +Up_Slope_RPM_Drop_1, +Gear_used_on_Up_Slope_2, +Up_Slope_RPM_Drop_2, +Gear_used_on_Down_Slope, +Down_Slope_RPM_Shoot_up, +Performance_compared_to_respective_competitor_tractors, +Fuel_consumption_lit_hr_2, +Mileage_Km_Ltr_2, +M_M_Performance_in_compared_to_respective_competitor_tractors, +Fuel_consumption_lit_hr_3, +Mileage_Km_Ltr_3, +Engine_Smoke_on_Load, +Engine_acceleration_smoke, +Range_Gear_Shifting, +Speed_Gear_Shifting, +Tractor_Steer_ability, +Tractor_braking_performance, +Front_Visibility, +Implement_Accessibility, +Front_end_lifting_during_operation, +RPM_Recovery_Time, +Engine_Vibration, +Engine_Sound +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column8,column9,column10,column11,column12}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column8::text, +column9::text,column10::text,column11::text,column12::text]) AS val + FROM staging2.stg_process_table_FTHLG_sum where block_tag=''FTHLG_SUM_Test_Condition_1'' + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text, + a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text + ,a_21 text,a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text, +a_31 text,a_32 text,a_33 text); + +update staging2.FTHLG_SUM_Test_Condition_1_Block +set test_iterationnumber=2 +where test_iterationnumber is null; + + update staging2.FTHLG_SUM_Test_Condition_1_Block a + set Test_Condition= b.first_value from (SELECT +test_iterationnumber,Test_Condition, value_partition, first_value(Test_Condition) over (partition by value_partition order by test_iterationnumber) +FROM ( +SELECT +test_iterationnumber, +Test_Condition, +sum(case when Test_Condition is null then 0 else 1 end) over (order by test_iterationnumber) as value_partition + FROM staging2.FTHLG_SUM_Test_Condition_1_Block +ORDER BY test_iterationnumber asc +) as q) b where a.test_iterationnumber = b.test_iterationnumber; + +update staging2.FTHLG_SUM_Test_Condition_1_Block set trx_record =0 +where tractor_model = '0' or fuel_consumption_ltr_hr is NULL; + +update staging2.FTHLG_SUM_Test_Condition_1_Block +set fuel_consumption_lit_hr_2=null where fuel_consumption_lit_hr_2 like '%indicates%'; + +update staging2.FTHLG_SUM_Test_Condition_1_Block +set fuel_consumption_lit_hr_2=left(fuel_consumption_lit_hr_2,length(fuel_consumption_lit_hr_2)-3), +Mileage_Km_Ltr_2 = left(Mileage_Km_Ltr_2,length(Mileage_Km_Ltr_2)-3) +where fuel_consumption_lit_hr_2 notnull; + +update staging2.FTHLG_SUM_Test_Condition_1_Block +set fuel_consumption_lit_hr_3=null where fuel_consumption_lit_hr_3 like '%indicates%'; + +update staging2.FTHLG_SUM_Test_Condition_1_Block +set fuel_consumption_lit_hr_3 = left(fuel_consumption_lit_hr_3,length(fuel_consumption_lit_hr_3)-3), +Mileage_Km_Ltr_3 = left(Mileage_Km_Ltr_3,length(Mileage_Km_Ltr_3)-3) +where fuel_consumption_lit_hr_2 notnull; + +delete from staging2.FTHLG_SUM_Test_Condition_1_Block where dummy_f is null ; +execute 'update staging2.FTHLG_SUM_Test_Condition_1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTHLG_SUM_Test_Condition_1_Block'); + + + +/*inserting data into block -FTHLG_SUM_Test_Condition_2_Block*/ + + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTHLG_SUM_Test_Condition_2_Block',__file_mnemonic,__file_sheet_mnemonic,4); +err_block:='FTHLG_SUM_Test_Condition_2_Block'; + +insert into staging2.FTHLG_SUM_Test_Condition_2_Block +( +dummy_f, +Test_Condition, +Test_Date, +Tractor_Model, +Fuel_consumption_Ltr_hr, +Mileage_Km_Ltr, +Average_speed_of_travel_kmph, +Total_distance_travelled_km, +Gear_used_on_Straight_Road, +Straight_road_RPM_Drop, +Gear_used_on_Up_Slope_1, +Up_Slope_RPM_Drop_1, +Gear_used_on_Up_Slope_2, +Up_Slope_RPM_Drop_2, +Gear_used_on_Down_Slope, +Down_Slope_RPM_Shoot_up, +Performance_compared_to_respective_competitor_tractors, +Fuel_consumption_lit_hr_2, +Mileage_Km_Ltr_2, +M_M_Performance_in_compared_to_respective_competitor_tractors, +Fuel_consumption_lit_hr_3, +Mileage_Km_Ltr_3, +Engine_Smoke_on_Load, +Engine_acceleration_smoke, +Range_Gear_Shifting, +Speed_Gear_Shifting, +Tractor_Steer_ability, +Tractor_braking_performance, +Front_Visibility, +Implement_Accessibility, +Front_end_lifting_during_operation, +RPM_Recovery_Time, +Engine_Vibration, +Engine_Sound +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val + FROM staging2.stg_process_table_FTHLG_sum where block_tag=''FTHLG_SUM_Test_Condition_2'' + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text, + a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text,a_21 text, + a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text,a_31 text, + a_32 text,a_33 text); + +update staging2.FTHLG_SUM_Test_Condition_2_Block +set test_iterationnumber=3; + + +insert into staging2.FTHLG_SUM_Test_Condition_2_Block +( +dummy_f, +Test_Condition, +Test_Date, +Tractor_Model, +Fuel_consumption_Ltr_hr, +Mileage_Km_Ltr, +Average_speed_of_travel_kmph, +Total_distance_travelled_km, +Gear_used_on_Straight_Road, +Straight_road_RPM_Drop, +Gear_used_on_Up_Slope_1, +Up_Slope_RPM_Drop_1, +Gear_used_on_Up_Slope_2, +Up_Slope_RPM_Drop_2, +Gear_used_on_Down_Slope, +Down_Slope_RPM_Shoot_up, +Performance_compared_to_respective_competitor_tractors, +Fuel_consumption_lit_hr_2, +Mileage_Km_Ltr_2, +M_M_Performance_in_compared_to_respective_competitor_tractors, +Fuel_consumption_lit_hr_3, +Mileage_Km_Ltr_3, +Engine_Smoke_on_Load, +Engine_acceleration_smoke, +Range_Gear_Shifting, +Speed_Gear_Shifting, +Tractor_Steer_ability, +Tractor_braking_performance, +Front_Visibility, +Implement_Accessibility, +Front_end_lifting_during_operation, +RPM_Recovery_Time, +Engine_Vibration, +Engine_Sound +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column8,column9,column10,column11,column12}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column8::text,column9::text,column10::text,column11::text,column12::text]) AS val + FROM staging2.stg_process_table_FTHLG_sum where block_tag=''FTHLG_SUM_Test_Condition_2'' + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text, + a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text,a_21 text, + a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text,a_31 text, + a_32 text,a_33 text); + +update staging2.FTHLG_SUM_Test_Condition_2_Block +set test_iterationnumber=4 +where test_iterationnumber is null; + + update staging2.FTHLG_SUM_Test_Condition_2_Block a + set Test_Condition= b.first_value from (SELECT +test_iterationnumber,Test_Condition, value_partition, first_value(Test_Condition) over (partition by value_partition order by test_iterationnumber) +FROM ( +SELECT +test_iterationnumber, +Test_Condition, +sum(case when Test_Condition is null then 0 else 1 end) over (order by test_iterationnumber) as value_partition + FROM staging2.FTHLG_SUM_Test_Condition_2_Block +ORDER BY test_iterationnumber asc +) as q) b where a.test_iterationnumber = b.test_iterationnumber; + + +update staging2.FTHLG_SUM_Test_Condition_2_Block a +set Test_Date=(select Test_Date from staging2.FTHLG_SUM_Test_Condition_1_Block b +where a.tractor_model=b.tractor_model and a.file_syspk=b.file_syspk) +where Test_Date='0' and a.file_syspk=__file_syspk; + +update staging2.FTHLG_SUM_Test_Condition_2_Block a +set Test_Date=(select Test_Date from staging2.FTHLG_SUM_Test_Condition_1_Block b +where a.tractor_model=b.tractor_model and a.file_syspk=b.file_syspk) +where Test_Date='0' and a.file_syspk=__file_syspk; + +update staging2.FTHLG_SUM_Test_Condition_2_Block set trx_record =0 +where tractor_model = '0' or +fuel_consumption_ltr_hr is NULL; + +update staging2.FTHLG_SUM_Test_Condition_2_Block +set fuel_consumption_lit_hr_2=null where fuel_consumption_lit_hr_2 like '%indicates%'; + +update staging2.FTHLG_SUM_Test_Condition_2_Block +set fuel_consumption_lit_hr_2=left(fuel_consumption_lit_hr_2,length(fuel_consumption_lit_hr_2)-3), +Mileage_Km_Ltr_2 = left(Mileage_Km_Ltr_2,length(Mileage_Km_Ltr_2)-3) +where fuel_consumption_lit_hr_2 notnull; + +update staging2.FTHLG_SUM_Test_Condition_2_Block +set fuel_consumption_lit_hr_3=null where fuel_consumption_lit_hr_3 like '%indicates%'; + +update staging2.FTHLG_SUM_Test_Condition_2_Block +set fuel_consumption_lit_hr_3 = left(fuel_consumption_lit_hr_3,length(fuel_consumption_lit_hr_3)-3), +Mileage_Km_Ltr_3 = left(Mileage_Km_Ltr_3,length(Mileage_Km_Ltr_3)-3) +where fuel_consumption_lit_hr_2 notnull; + + +delete from staging2.FTHLG_SUM_Test_Condition_2_Block where dummy_f is null ; +execute 'update staging2.FTHLG_SUM_Test_Condition_2_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTHLG_SUM_Test_Condition_2_Block'); + + +/*inserting data into block -FTHLG_SUM_Comments_By_Block*/ + + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTHLG_SUM_Comments_By_Block',__file_mnemonic,__file_sheet_mnemonic,5); +err_block:='FTHLG_SUM_Comments_By_Block'; + + +insert into staging2.FTHLG_SUM_Comments_By_Block (dummy_f) values +('dummy'); + +execute 'update staging2.FTHLG_SUM_Comments_By_Block set test_engineer_comments_1= +(select column3 from staging2.stg_process_table_fthlg_sum a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.block_tag=''FTHLG_SUM_Engineer_Comments_1'' +and block_row_number=1 ) where dummy_f=''dummy''' ; + +execute 'update staging2.FTHLG_SUM_Comments_By_Block set test_engineer_comments_3= +(select column3 from staging2.stg_process_table_fthlg_sum a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.block_tag=''FTHLG_SUM_Engineer_Comments_2'' +and block_row_number=1 ) where dummy_f=''dummy'''; + +execute 'update staging2.FTHLG_SUM_Comments_By_Block set test_manager_comments_1= +(select column3 from staging2.stg_process_table_fthlg_sum a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.block_tag=''FTHLG_SUM_Manager_Comments_1'' +and block_row_number=1 ) where dummy_f=''dummy'''; + +execute 'update staging2.FTHLG_SUM_Comments_By_Block set test_manager_comments_3= +(select column3 from staging2.stg_process_table_fthlg_sum a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.block_tag=''FTHLG_SUM_Manager_Comments_2'' +and block_row_number=1 ) where dummy_f=''dummy'''; + + +execute 'update staging2.FTHLG_SUM_Comments_By_Block set test_engineer_comments_2= +(select column8 from staging2.stg_process_table_fthlg_sum a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.block_tag=''FTHLG_SUM_Egnineer_Comments_1'' +and block_row_number=1 ) where dummy_f=''dummy'''; + + +execute 'update staging2.FTHLG_SUM_Comments_By_Block set test_engineer_comments_4= +(select column8 from staging2.stg_process_table_fthlg_sum a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.block_tag=''FTHLG_SUM_Engineer_Comments_2'' +and block_row_number=1 ) where dummy_f=''dummy'''; + +execute 'update staging2.FTHLG_SUM_Comments_By_Block set test_manager_comments_2= +(select column8 from staging2.stg_process_table_fthlg_sum a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.block_tag=''FTHLG_SUM_Manager_Comments_1'' +and block_row_number=1 ) where dummy_f=''dummy'''; + +execute 'update staging2.FTHLG_SUM_Comments_By_Block set test_manager_comments_4= +(select column8 from staging2.stg_process_table_fthlg_sum a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.block_tag=''FTHLG_SUM_Manager_Comments_2'' +and block_row_number=1 ) where dummy_f=''dummy'''; + + +delete from staging2.FTHLG_SUM_Comments_By_Block where dummy_f is null ; + +execute 'update staging2.FTHLG_SUM_Comments_By_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTHLG_SUM_Comments_By_Block'); + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_fthlg_sum_block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + diff --git a/onetime/dataloadfunctions/field/FTHLG_TRS_ods.sql b/onetime/dataloadfunctions/field/FTHLG_TRS_ods.sql new file mode 100755 index 0000000..88eaa7f --- /dev/null +++ b/onetime/dataloadfunctions/field/FTHLG_TRS_ods.sql @@ -0,0 +1,378 @@ +drop function if exists staging2.fn_FTHLG_TRS_TRX ; +CREATE OR REPLACE FUNCTION staging2.fn_FTHLG_TRS_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + declare __test_tractor_id int; + begin + +__file_syspk := p_file_syspk; + +/************************************************************ +Function Name:fn_FTHLG_TRS_TRX +Function Desc: This function populates data into ODS +File Format: FTHLG +Sheet Format: FTHLG_TRS +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_FTHLG_TRS_TRX() +***************************************************************/ + + +insert into transactional.test_instance +( +client_id, +function_id, +test_report_no, +objective_of_test, +background_of_test, +job_order_no, +test_location_name, +gradient_slope_1_degree, +gradient_slope_2_degree, +tractor_hitch_type, +test_engineer, +test_operator, +date_of_test, +test_report_date, +type_of_road, +tractor_hitch_ht_mm, +tractor_rwheel_c2h_dist_mm, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +Report_Reference_No test_report_no , +Objective_Of_Test, +Background_of_Test, +Job_Order_No, +Test_Location test_location_name, +Gradient_Slope_1_Degree::numeric, +Gradient_Slope_2_Degree::numeric, +Tractor_Hitch_Type, +Test_Engineer, +Test_Operator, +Date_of_Test::date, +Report_Date::date test_report_date, +Type_of_Road, +Tractor_Hitch_Height_from_Ground_mm::numeric tractor_hitch_ht_mm , +Tractor_Rear_Wheel_Center_to_Hitch_Point_Center_Distance_mm::numeric tractor_rwheel_c2h_dist_mm, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +from staging2.FTHLG_TRS_H1_Block where trx_record=1; + + + +insert into transactional.test_instance_tractor_info +( +client_id, +function_id, +tractor_model, +tractor_make, +tractor_sr_no, +tractor_engine_hp, +fip_type, +hour_meter_reading, +steering_type, +transmission_type, +wheel_drive_type, +egr_yn, +brake_type, +pto_type, +standard_pto_speed_rpm, +epto_speed_rpm, +tractor_weight_front_kg, +tractor_weight_rear_kg, +tractor_weight_total_kg, +ballasted_tractor_accessories, +mechanical_ballast_rear, +water_ballast_rear_75_pct, +mechanical_ballast_front_kg, +mechanical_ballast_front, +total_ballast_weight, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +Tractor_Model, +Tractor_Make, +Tractor_Sr_No, +Tractor_Engine_HP::numeric, +FIP_Type, +Hour_Meter_Reading::float, +Steering_Type, +Transmission_Type, +Wheel_Drive_Type_WD, +EGR_Yes_No egr_yn, +Brake_Type, +PTO_Type, +Standard_PTO_Speed_RPM::numeric, +EPTO_Speed_RPM, +Tractor_Weight_kg_Front::numeric tractor_weight_front_kg, +Tractor_Weight_kg_Rear::numeric tractor_weight_rear_kg, +Tractor_Weight_kg_Total::numeric tractor_weight_total_kg, +Ballasted_Tractor_Accessories, +Mechanical_Ballast_Rear, +Water_Ballast_Rear_75 water_ballast_rear_75_pct, +Mechanical_Ballast_Front_in_kg::numeric mechanical_ballast_front_kg, +Mechanical_Ballast_Front, +Total_Ballast_Weight::numeric, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +from staging2.fthlg_trs_spec_block where trx_record=1; + +update transactional.test_instance_tractor_info +set mahindra_model_yn = ( +case when tractor_make like 'Mahindra%' then 'Y' else 'N' end +) where file_syspk =__file_syspk; + +update transactional.test_instance_tractor_info a +set test_tractor_yn ='Y' where syspk in +(select min(syspk) from transactional.test_instance_tractor_info b +where b.file_syspk =a.file_syspk) +and a.file_syspk =__file_syspk; + +update transactional.test_instance_tractor_info +set test_tractor_yn ='N' +where test_tractor_yn is null and file_syspk =__file_syspk; + +insert into transactional.test_instance_tyre_info +( +client_id, +function_id, +tractor_make, +tractor_model, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_sr_no, +tyre_type, +tyre_make, +tyre_size, +tyre_pressure_psi +) +select +client_id, +function_id, +tractor_make, +tractor_model, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_sr_no, +'front', +front_tyre_make tyre_make, +front_tyre_size tyre_size, +front_tyre_pressure_psi::numeric tyre_pressure_psi +from staging2.fthlg_trs_spec_block where trx_record=1; + +update transactional.test_instance_tyre_info a +set test_instance_tractor_id =(select syspk +from transactional.test_instance_tractor_info b +where a.file_syspk=b.file_syspk and +a.tractor_model=b.tractor_model and a.tractor_sr_no=b.tractor_sr_no) +where a.tyre_type ='front' and a.file_syspk =__file_syspk; + +insert into transactional.test_instance_tyre_info +( +client_id, +function_id, +tractor_make, +tractor_model, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_sr_no, +tyre_type, +tyre_make, +tyre_size, +tyre_pressure_psi +) +select +client_id, +function_id, +tractor_make, +tractor_model, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tractor_sr_no, +'rear', +rear_tyre_make tyre_make, +rear_tyre_size tyre_size, +rear_tyre_pressure_psi::numeric tyre_pressure_psi +from staging2.fthlg_trs_spec_block where trx_record=1; + +update transactional.test_instance_tyre_info a +set test_instance_tractor_id =(select syspk +from transactional.test_instance_tractor_info b +where a.file_syspk=b.file_syspk and +a.tractor_model=b.tractor_model and a.tractor_sr_no=b.tractor_sr_no) +where a.tyre_type ='rear' and a.file_syspk = __file_syspk; + +insert into transactional.test_instance_engine_info +( +client_id, +function_id, +low_idle_declared, +high_idle_declared, +rated_rpm, +engine_to_pto_ratio_540_pto, +engine_to_pto_ratio_540e_pto, +tractor_model, +tractor_make, +tractor_sr_no, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +low_idle low_idle_declared, +high_idle high_idle_declared, +rated_rpm::numeric, +engine_to_pto_ratio_540_pto, +engine_to_pto_ratio_540e_pto, +tractor_model, +tractor_make, +tractor_sr_no, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +from staging2.fthlg_trs_engine_rpm_block where trx_record=1; + +update transactional.test_instance_engine_info a +set test_instance_tractor_id =(select syspk +from transactional.test_instance_tractor_info b +where a.file_syspk=b.file_syspk and +a.tractor_model=b.tractor_model and a.tractor_sr_no=b.tractor_sr_no) +where a.file_syspk = __file_syspk; + +insert into transactional.test_instance_trailer_info +( +client_id, +function_id, +type_of_trailer, +no_of_axle, +no_of_wheels, +trailer_hitch_ht_above_ground_lvl_mm, +make_model_of_trailer, +trailer_platform_length_mm, +trailer_platform_width_mm, +trailer_platform_height_mm, +tire_size, +inflation_pressure_psi, +track_width_of_trailer_mm, +hzntl_dist_of_hitch_pt_from_trailer_face_mm, +tractor_rwc_to_hitch_pt_center_dist_mm, +dist_from_tractor_rwc_to_trailer_rwc_mm, +dist_from_trailer_front_axle_dist_from_hitch_pt_mm, +trailer_empty_weight_kg, +trailer_gross_weight_kg, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +Type_Of_Trailer, +No_Of_Axle::numeric, +No_Of_Wheels::numeric, +Trailer_hitch_Height_above_ground_level_mm::numeric trailer_hitch_ht_above_ground_lvl_mm, +Make_model_of_trailer, +Trailer_platform_length_mm::numeric, +Trailer_platform_Width_mm::numeric, +Trailer_platform_Height_mm::numeric, +Tire_size, +Inflation_pressure_psi::numeric, +Track_width_of_trailer_mm::numeric, +Horizontal_distance_of_hitch_point_from_trailer_front_face_mm::numeric hzntl_dist_of_hitch_pt_from_trailer_face_mm, +Tractor_Rear_Wheel_Center_to_Hitch_Point_Center_Distance_mm::numeric tractor_rwc_to_hitch_pt_center_dist_mm, +Distance_from_Trailer_front_axle_distance_from_hitch_point_mm::numeric dist_from_tractor_rwc_to_trailer_rwc_mm, +Distance_from_tractor_rear_wheel_to_tractor_rear_wheel_mm::numeric dist_from_trailer_front_axle_dist_from_hitch_pt_mm, +Trailer_empty_weight_Kg::numeric, +Trailer_Gross_Weight_Kg::numeric, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +from staging2.fthlg_trs_trailer_block where trx_record=1; + + +update transactional.test_instance a +set report_template_no=b.report_template_no, +report_template_rev_no=b.report_template_rev_no, +report_template_rev_date =b.report_template_rev_date +from staging2.fthlg_trs_trailer_block b where trx_record=1 +and a.file_syspk=b.file_syspk; + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select syspk from transactional.test_master into __test_master_id where test_type ='Field'; +select syspk from transactional.test_instance_tractor_info into __test_tractor_id +where file_syspk =__file_syspk and test_tractor_yn ='Y'; + +update transactional.test_instance +set test_master_id =__test_master_id, +test_tractor_id =__test_tractor_id +where file_syspk=__file_syspk; + +update transactional.test_instance_engine_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_tyre_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.test_instance_implement_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.test_instance_trailer_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.test_instance +set test_file_name =(select a.file_name from staging1.staging_generic_table a where file_syspk = __file_syspk limit 1) +where file_syspk = __file_syspk; + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_FTHLG_TRS_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + diff --git a/onetime/dataloadfunctions/field/FTHLG_TRS_stg2.sql b/onetime/dataloadfunctions/field/FTHLG_TRS_stg2.sql new file mode 100755 index 0000000..fc837ff --- /dev/null +++ b/onetime/dataloadfunctions/field/FTHLG_TRS_stg2.sql @@ -0,0 +1,423 @@ +drop function if exists staging2.fn_fthlg_trs_block; +CREATE OR REPLACE FUNCTION staging2.fn_fthlg_trs_block(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + begin + + + + +/*********************************************************************************** +Function Name:fn_FTHLG_TRS_Block +Function Desc: This function populates data into staging2 blocks +File Format: FTHLG +Sheet Format: FTHLG_TRS +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_fthlg_trs_block(20,1,'FTHLG','FTHLG_TRS',259); +************************************************************************************/ + + SET search_path TO staging2; + +truncate staging2.FTHLG_TRS_H1_INT; +truncate staging2.FTHLG_TRS_H1_Block; +truncate staging2.FTHLG_TRS_SPEC_Block; +truncate staging2.FTHLG_TRS_Engine_RPM_Block; +truncate staging2.FTHLG_TRS_Trailer_Block; +truncate staging2.stg_specific_table_fthlg_trs; +truncate staging2.stg_process_table_fthlg_trs; + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* transfer data from generic to specific for fthlg*/ + +execute 'insert into staging2.stg_specific_table_fthlg_trs +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_fthlg_trs; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for FTHLG Tractor Specifications', + detail = 'No data in table stg_specific_table_fthlg_trs', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + +/* trimming data */ +/* +update staging2.stg_specific_table_fthlg_trs set column2 = TRIM (TRAILING FROM column2 ); +update staging2.stg_specific_table_fthlg_trs set column2 = TRIM (LEADING FROM column2 ); +update transactional.source_config set F1_modified = TRIM (TRAILING FROM F1_modified); +update transactional.source_config set F1_modified = TRIM (LEADING FROM F1_modified); + +update transactional.source_config set F1_source = TRIM (TRAILING FROM F1_source); +update transactional.source_config set F1_source = TRIM (LEADING FROM F1_source); +*/ + +update transactional.source_config set F1_source=F1_modified; + +/* keyword match in config table*/ +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_fthlg_trs b +where F1_source=column2 +and b.is_rownumber_fetched is null) +where a.row_number_start is null and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update in process table for match*/ +execute 'update staging2.stg_specific_table_fthlg_trs a +set is_rownumber_fetched=1 +from transactional.source_config b +where F1_source=column2 +and b.row_number_start=a.row_number +and is_rownumber_fetched is null and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/* update config files for row numbers start, end */ +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a set row_read_end = null where f1_modified =''Trailer Details'' and +a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/*inserting run_time in config*/ +execute 'update transactional.source_config a +set run_time=current_timestamp where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers for each block in process table*/ +execute 'insert into staging2.stg_process_table_fthlg_trs +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_fthlg_trs a +join transactional.source_config b +on a.row_number >row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Tractor specifications sheet'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + + +execute 'insert into staging2.stg_process_table_fthlg_trs +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_fthlg_trs a +join transactional.source_config b +on a.row_number >row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Tractor Specifications'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +execute 'insert into staging2.stg_process_table_fthlg_trs +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_fthlg_trs a +join transactional.source_config b +on a.row_number >row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Engine RPM Data:'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +execute 'insert into staging2.stg_process_table_fthlg_trs +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_fthlg_trs a +join transactional.source_config b +on a.row_number >row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Trailer Details'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + +/*inserting data into FTHLG_TRS_H1_INT*/ +err_block:='FTHLG_TRS_H1_Block'; + +insert into staging2.FTHLG_TRS_H1_INT +(column2,column3,column4,column5,column6,column7,block_row_number) +select column2,column3,column4,column5,column6,column7,block_row_number from staging2.stg_process_table_fthlg_trs a +where block_tag='FTHLG_TRS_H1' order by block_row_number; + + + +insert into staging2.FTHLG_TRS_H1_INT(column2,column3) +select 'Date of Test',column5 +from staging2.FTHLG_TRS_H1_INT +where block_row_number=1; + +insert into staging2.FTHLG_TRS_H1_INT(column2,column3) +select 'Report Date',column7 +from staging2.FTHLG_TRS_H1_INT +where block_row_number=1; + +insert into staging2.FTHLG_TRS_H1_INT(column2,column3) +select column5,column6 +from staging2.FTHLG_TRS_H1_INT +where block_row_number in (5,6,8); + +/*inserting data into block -.FTHLG_TRS_H1_Block*/ + + + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTHLG_TRS_H1_Block',__file_mnemonic,__file_sheet_mnemonic,1); + + +insert into staging2.FTHLG_TRS_H1_Block +( +dummy_f, +Report_Reference_No, +Objective_Of_Test, +Background_of_Test, +Job_Order_No, +Test_Location, +Gradient_Slope_1_Degree, +Gradient_Slope_2_Degree, +Tractor_Hitch_Type, +Test_Engineer, +Test_Operator, +Date_of_Test, +Report_Date, +Type_of_Road, +Tractor_Hitch_Height_from_Ground_mm, +Tractor_Rear_Wheel_Center_to_Hitch_Point_Center_Distance_mm +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column3}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column3::text]) AS val + FROM staging2.FTHLG_TRS_H1_INT + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text, + a_11 text,a_12 text,a_13 text,a_14 text,a_15 text); + + +delete from staging2.FTHLG_TRS_H1_Block where dummy_f is null ; +execute 'update staging2.FTHLG_TRS_H1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTHLG_TRS_H1_Block'); + + + +/*inserting data into block -FTHLG_TRS_SPEC_Block*/ + + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTHLG_TRS_SPEC_Block',__file_mnemonic,__file_sheet_mnemonic,2); +err_block:='FTHLG_TRS_SPEC_Block'; + +insert into staging2.FTHLG_TRS_SPEC_Block +( +dummy_f, +Tractor_Model, +Tractor_Make, +Tractor_Sr_No, +Tractor_Engine_HP, +FIP_Type, +hour_Meter_Reading, +Steering_Type, +Transmission_Type, +Wheel_Drive_Type_WD, +EGR_Yes_No, +Brake_Type, +PTO_Type, +Standard_PTO_Speed_RPM, +EPTO_Speed_RPM, +Front_Tyre_Make, +Front_Tyre_Size, +Front_Tyre_Pressure_psi, +Rear_Tyre_Make, +Rear_Tyre_Size, +Rear_Tyre_Pressure_psi , +Tractor_Weight_kg_Front , +Tractor_Weight_kg_Rear , +Tractor_Weight_kg_Total, +Ballasted_Tractor_Accessories, +Mechanical_Ballast_Rear, +Mechanical_Ballast_Rear_in_KG , +Water_Ballast_Rear_75, +Mechanical_Ballast_Front_in_Kg, +Mechanical_Ballast_Front, +Total_Ballast_Weight +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val + FROM staging2.stg_process_table_fthlg_trs where block_tag=''FTHLG_TRS_SPEC'' + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text, + a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text,a_21 text, + a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text); + +update staging2.FTHLG_TRS_SPEC_Block set trx_record=0 +where tractor_make is null and tractor_sr_no is null; + +update staging2.FTHLG_TRS_SPEC_Block set trx_record=0 +where (tractor_model is null and front_tyre_make is null) or (tractor_model is null and rear_tyre_make is null); + +delete from staging2.FTHLG_TRS_SPEC_Block where dummy_f is null ; +execute 'update staging2.FTHLG_TRS_SPEC_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTHLG_TRS_SPEC_Block'); + + + +/*inserting data into block -FTHLG_TRS_Engine_RPM_Block*/ + + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTHLG_TRS_Engine_RPM_Block',__file_mnemonic,__file_sheet_mnemonic,3); +err_block:='FTHLG_TRS_Engine_RPM_Block'; + +insert into staging2.FTHLG_TRS_Engine_RPM_Block +( +dummy_f, +Tractor_model, +Tractor_make, +tractor_sr_no, +Low_Idle, +High_Idle, +Rated_RPM, +Engine_to_PTO_Ratio_540_PTO, +Engine_to_PTO_Ratio_540E_PTO +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val + FROM staging2.stg_process_table_fthlg_trs where block_tag=''FTHLG_TRS_Engine_RPM'' + or (block_tag=''FTHLG_TRS_SPEC'' and block_row_number in (1,2,3)) + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text); + +update staging2.FTHLG_TRS_Engine_RPM_Block set trx_record=0 +where tractor_model is null; + +delete from staging2.FTHLG_TRS_Engine_RPM_Block where dummy_f is null ; +execute 'update staging2.FTHLG_TRS_Engine_RPM_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTHLG_TRS_Engine_RPM_Block'); + + +/*inserting data into block -FTHLG_TRS_Trailer_Block*/ + + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTHLG_TRS_Trailer_Block',__file_mnemonic,__file_sheet_mnemonic,4); +err_block:='FTHLG_TRS_Trailer_Block'; + +insert into staging2.FTHLG_TRS_Trailer_Block +( +dummy_f, +Type_Of_Trailer, +No_Of_Axle, +No_Of_Wheels, +Trailer_hitch_Height_above_ground_level_mm, +Make_model_of_trailer, +Trailer_platform_length_mm, +Trailer_platform_Width_mm, +Trailer_platform_Height_mm, +Tire_size, +Inflation_pressure_psi, +Track_width_of_trailer_mm, +Horizontal_distance_of_hitch_point_from_trailer_front_face_mm, +Tractor_Rear_Wheel_Center_to_Hitch_Point_Center_Distance_mm, +Distance_from_Trailer_front_axle_distance_from_hitch_point_mm, +Distance_from_tractor_rear_wheel_to_tractor_rear_wheel_mm, +Trailer_empty_weight_Kg, +Trailer_Gross_Weight_Kg +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column3,column4,column5,column6}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column3::text,column4::text,column5::text,column6::text]) AS val + FROM staging2.stg_process_table_fthlg_trs where block_tag=''FTHLG_TRS_Trailer'' and block_row_number <=17 + ORDER BY generate_series(1,15),block_row_number,2' + ) t ( col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text + ,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text); + + +update staging2.FTHLG_TRS_Trailer_Block set report_template_no= +(select column2 from staging2.stg_process_table_fthlg_trs where block_row_number=18 +and block_tag='FTHLG_TRS_Trailer')where make_model_of_trailer is not null; + +update staging2.FTHLG_TRS_Trailer_Block set report_template_rev_no= +(select column4 from staging2.stg_process_table_fthlg_trs where block_row_number=18 +and block_tag='FTHLG_TRS_Trailer')where make_model_of_trailer is not null; + + +update staging2.FTHLG_TRS_Trailer_Block set report_template_rev_date= +(select column6 from staging2.stg_process_table_fthlg_trs where block_row_number=18 and +block_tag='FTHLG_TRS_Trailer')where make_model_of_trailer is not null; + +update staging2.FTHLG_TRS_Trailer_Block set trx_record=0 +where type_of_trailer is null; + +execute 'update staging2.FTHLG_TRS_Trailer_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTHLG_TRS_Trailer_Block'); + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_FTHLG_TRS_Block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + diff --git a/onetime/dataloadfunctions/field/FTWET_SUM_ods.sql b/onetime/dataloadfunctions/field/FTWET_SUM_ods.sql new file mode 100755 index 0000000..e7790d6 --- /dev/null +++ b/onetime/dataloadfunctions/field/FTWET_SUM_ods.sql @@ -0,0 +1,349 @@ +drop function if exists staging2.fn_FTWET_SUM_TRX ; +CREATE OR REPLACE FUNCTION staging2.fn_FTWET_SUM_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + begin + +__file_syspk := p_file_syspk; + +/************************************************************ +Function Name:fn_FTWET_SUM_TRX +Function Desc: This function populates data into ODS +File Format: FTWET +Sheet Format: FTWET_SUM +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_FTWET_SUM_TRX() +***************************************************************/ + + +insert into transactional.field_perf_summary_tractor_info +( +client_id, +function_id, +tractor_model, +tractor_make, +tractor_engine_hp, +rated_rpm, +transmission_type, +wheel_drive_type, +fip_type, +steering_type, +tractor_weight_front_kg, +tractor_weight_rear_kg, +tractor_weight_total_kg, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +tractor_model, +tractor_make, +trim('HP' from tractor_engine_hp)::numeric, +rated_rpm::numeric, +transmission_type, +wheel_drive_type, +fip_type, +steering_type, +tractor_weight_kg_front::numeric, +tractor_weight_kg_rear::numeric, +tractor_weight_kg_total::numeric, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +from staging2.ftwet_sum_trac_h1_block where trx_record=1; + +update transactional.field_perf_summary_tractor_info a +set test_instance_tractor_id = (select syspk +from transactional.test_instance_tractor_info b +where a.tractor_model=trim(b.tractor_model) and a.file_syspk =b.file_syspk +)where a.file_syspk =__file_syspk; + + +insert into transactional.field_perf_summary_implement_info +( +client_id, +function_id, +name_of_implement, +implement_type, +implement_size, +hitch_category, +implement_weight, +soil_type, +soil_moisture_content_pct, +soil_bulk_density_g_per_cc, +soil_cone_index, +field_condition, +season, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +make_of_implement, +implement_type, +implement_size, +hitch_category, +implement_weight::numeric, +soil_type, +moisture_content::numeric soil_moisture_content_pct, +bulk_density_g_cc::numeric soil_bulk_density_g_per_cc, +soil_cone_index::numeric soil_cone_index, +field_condition, +season, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +from staging2.ftwet_sum_implement_block where trx_record=1; + + +insert into transactional.field_perf_summary_implement_info +( +client_id, +function_id, +type_of_cage_wheel, +cage_wheel_width_mm, +cage_wheel_weight, +cage_wheel_inner_and_outer_ring_dia_mm, +cage_wheel_center_ring_dia_mm, +no_of_angles_on_cage_wheel, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +Type_of_Cage_Wheel, +Cage_Wheel_Width_mm::numeric, +Cage_wheel_Weight::numeric, +Cage_Wheel_inner_Outer_Ring_Dia_mm::numeric cage_wheel_inner_and_outer_ring_dia_mm, +Cage_Wheel_Center_Ring_Dia_mm::numeric, +No_of_angles_on_cage_wheel::numeric, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +from staging2.FTWET_SUM_Cage_Wheel_Block where trx_record=1; + + +insert into transactional.field_perf_summary +( +client_id, +function_id, +test_iteration_number, +Test_Condition, +Test_Date, +Tractor_Model, +Engine_RPM_set, +PTO_RPM_set, +Gear_Used, +Nominal_Speed_KMPH, +Engine_RPM_Drop_on_straight_1st_Pass, +Engine_RPM_Drop_on_straight_2nd_Pass, +Engine_RPM_Drop_on_straight_3rd_Pass, +Engine_RPM_Drop_on_turn_1st_Pass, +Engine_RPM_Drop_on_turn_2nd_Pass, +Engine_RPM_Drop_on_turn_3rd_Pass, +No_of_passes, +depth_of_cut_cm, +fuel_consumption_lit_per_hr, +area_covered_acr_per_hr, + fuel_consumption_lit_per_acr, + fuel_consumption_var_lit_per_hr, +area_covered_var_acr_per_hr, +fuel_consumption_var_lit_per_acr, +Engine_Smoke_on_Load, +Engine_acceleration_smoke, +Draft_Response, +Tractor_Steer_ability, +Tractor_braking_perf, +Front_Visibility, +Implement_Accessibility, +Front_Wheel_dragging_at_turning, +Front_end_lifting_during_operation, +RPM_Recovery_Time, +Engine_Vibration, +Engine_Sound, +implement_lifting_per_lowering_response, +Pulverization_Quality, +Pulverization_Index, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +test_iterationnumber::numeric, +Test_Condition, +Test_Date::date, +Tractor_Model, +Engine_RPM_set::numeric, +PTO_RPM_set::numeric, +Gear_Used, +Nominal_Speed_KMPH::numeric, +Engine_RPM_Drop_on_straight_1st_Pass, +Engine_RPM_Drop_on_straight_2nd_Pass, +Engine_RPM_Drop_on_straight_3rd_Pass, +Engine_RPM_Drop_on_turn_1st_Pass, +Engine_RPM_Drop_on_turn_2nd_Pass, +Engine_RPM_Drop_on_turn_3rd_Pass, +No_of_passes::numeric, +Avg_Depth_of_cut_cm depth_of_cut_cm , +Fuel_consumption_lit_hr::numeric fuel_consumption_lit_per_hr, +Area_covered_acr_hr::numeric area_covered_acr_per_hr, +Fuel_consumption_lit_Acr::numeric fuel_consumption_lit_per_acr, +case when fuel_consumption_lit_hr_2 ~ E'^\\d+$' then fuel_consumption_lit_hr_2::numeric else null end as fuel_consumption_var_lit_per_hr , +case when area_covered_acr_hr_2 ~ E'^\\d+$' then area_covered_acr_hr_2::numeric else null end as area_covered_var_acr_per_hr , +case when fuel_consumption_lit_acr_2 ~ E'^\\d+$' then fuel_consumption_lit_acr_2::numeric else null end as fuel_consumption_var_lit_per_acr, +Engine_Smoke_on_Load, +Engine_acceleration_smoke, +Draft_Response, +Tractor_Steer_ability, +Tractor_braking_performance tractor_braking_perf, +Front_Visibility, +Implement_Accessibility, +Front_Wheel_dragging_at_turning, +Front_end_lifting_during_operation, +RPM_Recovery_Time, +Engine_Vibration, +Engine_Sound, +Implement_Lifting_Lowering_response implement_lifting_per_lowering_response, +Pulverization_Quality, +Pulverization_Index, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +from staging2.FTWET_SUM_Test_Condition_Block where trx_record=1; + + + + +update transactional.field_perf_summary a +set test_engr_comments=b.test_engineer_comments_1, +test_mgr_comments =b.test_manager_comments_1 +from staging2.ftwet_sum_comments_by_block b +where a.file_syspk=b.file_syspk and a.test_iteration_number =1; + +update transactional.field_perf_summary a +set test_engr_comments=b.test_engineer_comments_2, +test_mgr_comments =b.test_manager_comments_2 +from staging2.ftwet_sum_comments_by_block b +where a.file_syspk=b.file_syspk and a.test_iteration_number =2; + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; + + + +update transactional.field_perf_summary +set engine_rpm_drop_on_straight_1st_pass =replace(engine_rpm_drop_on_straight_1st_pass,' to ','-'), +engine_rpm_drop_on_straight_2nd_pass =replace(engine_rpm_drop_on_straight_2nd_pass,' to ','-'), +engine_rpm_drop_on_straight_3rd_pass =replace(engine_rpm_drop_on_straight_3rd_pass,' to ','-'), +engine_rpm_drop_on_turn_1st_pass=replace(engine_rpm_drop_on_turn_1st_pass,' to ','-'), +engine_rpm_drop_on_turn_2nd_pass=replace(engine_rpm_drop_on_turn_2nd_pass,' to ','-'), +engine_rpm_drop_on_turn_3rd_pass=replace(engine_rpm_drop_on_turn_3rd_pass,' to ','-'), +depth_of_cut_cm=replace(depth_of_cut_cm,' to ','-') +where file_mnemonic = 'FTWET'; + +UPDATE transactional.field_perf_summary + SET +--updating RPM drop straight 1st pass: + erpmdrop_straight_1stpass_low = trim(split_part(trim(engine_rpm_drop_on_straight_1st_pass), '-', 1))::numeric, + erpmdrop_straight_1stpass_high = case trim(split_part(trim(engine_rpm_drop_on_straight_1st_pass), '-', 2)) + when '' then null + else trim(split_part(trim(engine_rpm_drop_on_straight_1st_pass), '-', 2))::numeric end, +--updating RPM drop straight 2nd pass: + erpmdrop_straight_2ndpass_low = trim(split_part(trim(engine_rpm_drop_on_straight_2nd_pass), '-', 1))::numeric, + erpmdrop_straight_2ndpass_high = case trim(split_part(trim(engine_rpm_drop_on_straight_2nd_pass), '-', 2)) + when '' then null + else trim(split_part(trim(engine_rpm_drop_on_straight_2nd_pass), '-', 2))::numeric end, +--updating RPM drop straight 3rd pass: + erpmdrop_straight_3rdpass_low = trim(split_part(trim(engine_rpm_drop_on_straight_3rd_pass), '-', 1))::numeric, + erpmdrop_straight_3rdpass_high = case trim(split_part(trim(engine_rpm_drop_on_straight_3rd_pass), '-', 2)) + when '' then null + else trim(split_part(trim(engine_rpm_drop_on_straight_3rd_pass), '-', 2))::numeric end, +--updating RPM drop turn 1st pass: + erpmdrop_turn_1stpass_low = trim(split_part(trim(engine_rpm_drop_on_turn_1st_pass), '-', 1))::numeric, + erpmdrop_turn_1stpass_high = case trim(split_part(trim(engine_rpm_drop_on_turn_1st_pass), '-', 2)) + when '' then null + else trim(split_part(trim(engine_rpm_drop_on_turn_1st_pass), '-', 2))::numeric end, +--updating RPM drop turn 2nd pass: + erpmdrop_turn_2ndpass_low = trim(split_part(trim(engine_rpm_drop_on_turn_2nd_pass), '-', 1))::numeric, + erpmdrop_turn_2ndpass_high = case trim(split_part(trim(engine_rpm_drop_on_turn_2nd_pass), '-', 2)) + when '' then null + else trim(split_part(trim(engine_rpm_drop_on_turn_2nd_pass), '-', 2))::numeric end, +--updating RPM drop turn 3rd pass: + erpmdrop_turn_3rdpass_low = trim(split_part(trim(engine_rpm_drop_on_turn_3rd_pass), '-', 1))::numeric, + erpmdrop_turn_3rdpass_high = case trim(split_part(trim(engine_rpm_drop_on_turn_3rd_pass), '-', 2)) + when '' then null + else trim(split_part(trim(engine_rpm_drop_on_turn_3rd_pass), '-', 2))::numeric end, +--updating depth of cut: + depth_of_cut_cm_low = trim(split_part(trim(depth_of_cut_cm), '-', 1))::numeric, + depth_of_cut_cm_high= case trim(split_part(trim(depth_of_cut_cm), '-', 2)) + when '' then null + else trim('cm' from split_part(trim(depth_of_cut_cm), '-', 2))::numeric end + where file_mnemonic = 'FTWET'; + + +update transactional.field_perf_summary +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + + +update transactional.field_perf_summary_implement_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + + +update transactional.field_perf_summary_tractor_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.field_perf_summary_trailer_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.field_perf_summary_implement_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.field_perf_summary a +set test_instance_tractor_id = (select syspk +from transactional.test_instance_tractor_info b +where a.tractor_model=b.tractor_model and a.file_syspk =b.file_syspk +)where test_iteration_number =1 and a.file_syspk =__file_syspk; + +update transactional.field_perf_summary a +set test_instance_tractor_id = (select syspk +from transactional.test_instance_tractor_info b +where a.tractor_model=b.tractor_model and a.file_syspk =b.file_syspk +)where test_iteration_number =2 and a.file_syspk =__file_syspk; + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_FTWET_SUM_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + diff --git a/onetime/dataloadfunctions/field/FTWET_SUM_stg2.sql b/onetime/dataloadfunctions/field/FTWET_SUM_stg2.sql new file mode 100755 index 0000000..78b35f6 --- /dev/null +++ b/onetime/dataloadfunctions/field/FTWET_SUM_stg2.sql @@ -0,0 +1,511 @@ +drop function if exists staging2.fn_FTWET_SUM_Block ; +CREATE OR REPLACE FUNCTION staging2.fn_FTWET_SUM_Block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + + begin + + +/*********************************************************************************** +Function Name:fn_FTWET_SUM_Block +Function Desc: This function populates data into staging2 blocks +File Format: FTWET +Sheet Format: FTWET_SUM +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_ftwet_sum_block(20,1,'FTWET','FTWET_SUM',260); +************************************************************************************/ + +SET search_path TO staging2; +truncate staging2.FTWET_SUM_Trac_H1_Block; +truncate staging2.FTWET_SUM_Implement_Block; +truncate staging2.FTWET_SUM_Cage_Wheel_Block; +truncate staging2.FTWET_SUM_Test_Condition_Block; +truncate staging2.FTWET_SUM_Comments_By_Block; +truncate staging2.stg_specific_table_ftwet_sum; +truncate staging2.stg_process_table_ftwet_sum; + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* transfer data from generic to specific for ftwet*/ + +execute 'insert into staging2.stg_specific_table_ftwet_sum +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' + and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_ftwet_sum; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for FTWET Summary', + detail = 'No data in table stg_specific_table_ftwet_sum', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + +/* trimming data */ +update staging2.stg_specific_table_ftwet_sum set column2 = TRIM (TRAILING FROM column2 ); +update staging2.stg_specific_table_ftwet_sum set column2 = TRIM (LEADING FROM column2 ); +--update transactional.source_config set F1_modified = TRIM (TRAILING FROM F1_modified); +--update transactional.source_config set F1_modified = TRIM (LEADING FROM F1_modified) ; +-- +--update transactional.source_config set F1_source = TRIM (TRAILING FROM F1_source); +--update transactional.source_config set F1_source = TRIM (LEADING FROM F1_source); +update transactional.source_config set F1_source=F1_modified; + + +/* keyword match in config table*/ +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_ftwet_sum b +where F1_source=column2 +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update in process table for match*/ +execute 'update staging2.stg_specific_table_ftwet_sum a +set is_rownumber_fetched=1 +from transactional.source_config b +where F1_source=column2 +and b.row_number_start=a.row_number +and is_rownumber_fetched is null and +a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* keyword match in config table*/ +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a set row_read_end = null where f1_modified =''Test Manager Comments'' and +a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/*inserting run_time in config*/ +execute 'update transactional.source_config a +set run_time=current_timestamp +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers for each block in process table*/ +execute 'insert into staging2.stg_process_table_ftwet_sum +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_ftwet_sum a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Tractor Model'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + + + +execute 'insert into staging2.stg_process_table_ftwet_sum +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_ftwet_sum a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Make of Implement'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +execute 'insert into staging2.stg_process_table_ftwet_sum +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_ftwet_sum a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Type of Cage Wheel'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +execute 'insert into staging2.stg_process_table_ftwet_sum +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_ftwet_sum a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Condition:'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +execute 'insert into staging2.stg_process_table_ftwet_sum +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_ftwet_sum a +join transactional.source_config b +on a.row_number >=row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Test Manager Comments'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +/*inserting data into block -FTWET_SUM_Trac_H1_Block*/ + + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTWET_SUM_Trac_H1_Block',__file_mnemonic,__file_sheet_mnemonic,1); +err_block:='FTWET_SUM_Trac_H1_Block'; + +insert into staging2.FTWET_SUM_Trac_H1_Block +( +Tractor_Model, +Tractor_Make, +Tractor_Engine_HP, +Rated_RPM, +Transmission_Type, +Wheel_Drive_Type, +FIP_Type, +Steering_Type, +Tractor_Weight_kg_Front, +Tractor_Weight_kg_Rear, +Tractor_Weight_kg_Total, +block_row_number +) +select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_FTWET_sum +where block_tag='FTWET_SUM_Trac_H1' +order by block_row_number; + +delete from staging2.FTWET_SUM_Trac_H1_Block where tractor_model='0'; + +update staging2.FTWET_SUM_Trac_H1_Block set trx_record=0 where block_row_number=1; + + +execute 'update staging2.FTWET_SUM_Trac_H1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTWET_SUM_Trac_H1_Block'); + +/*inserting data into block -FTWET_SUM_Implement_Block*/ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTWET_SUM_Implement_Block',__file_mnemonic,__file_sheet_mnemonic,2); + +err_block:='FTWET_SUM_Implement_Block'; + +insert into staging2.FTWET_SUM_Implement_Block +( +Make_of_Implement, +Implement_Type, +Implement_Size, +Hitch_Category, +Implement_Weight, +Soil_Type, +Moisture_Content , +Bulk_Density_g_cc , +Soil_Cone_index, +Field_Condition , +Season, +block_row_number +) +select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,block_row_number +from staging2.stg_process_table_FTWET_sum +where block_tag='FTWET_SUM_Impement' +order by block_row_number; + +execute 'update staging2.FTWET_SUM_Implement_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +update staging2.FTWET_SUM_Implement_Block set trx_record=0 where block_row_number=1; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTWET_SUM_Implement_Block'); + + +/*inserting data into block -FTWET_SUM_Cage_Wheel_Block*/ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTWET_SUM_Cage_Wheel_Block',__file_mnemonic,__file_sheet_mnemonic,3); +err_block:='FTWET_SUM_Cage_Wheel_Block'; + +insert into staging2.FTWET_SUM_Cage_Wheel_Block +( +Type_of_Cage_Wheel, +Cage_Wheel_Width_mm, +Cage_wheel_Weight, +Cage_Wheel_inner_Outer_Ring_Dia_mm, +Cage_Wheel_Center_Ring_Dia_mm, +Distance_between_RHS_LHS_cage_wheel_Inner_Ring_mm, +No_of_angles_on_cage_wheel, +block_row_number +) +select column2,column3,column4,column5,column6,column7,column8,block_row_number +from staging2.stg_process_table_FTWET_sum +where block_tag='FTWET_SUM_Cage_Wheel' +order by block_row_number; + +update staging2.FTWET_SUM_Cage_Wheel_Block +set trx_record=0 where block_row_number in (1,3); + +execute 'update staging2.FTWET_SUM_Cage_Wheel_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTWET_SUM_Cage_Wheel_Block'); + + +/*inserting data into block -FTWET_SUM_Test_Condition_Block*/ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTWET_SUM_Test_Condition_Block',__file_mnemonic,__file_sheet_mnemonic,4); +err_block:='FTWET_SUM_Test_Condition_Block'; + +insert into staging2.FTWET_SUM_Test_Condition_Block +( +dummy_f, +Test_Condition, +Test_Date, +Tractor_Model, +Engine_RPM_set, +PTO_RPM_set, +Gear_Used, +Nominal_Speed_KMPH, +Engine_RPM_Drop_on_straight_1st_Pass, +Engine_RPM_Drop_on_straight_2nd_Pass, +Engine_RPM_Drop_on_straight_3rd_Pass, +Engine_RPM_Drop_on_turn_1st_Pass, +Engine_RPM_Drop_on_turn_2nd_Pass, +Engine_RPM_Drop_on_turn_3rd_Pass, +No_of_passes, +Avg_Depth_of_cut_cm, +Fuel_consumption_lit_hr, +Area_covered_acr_hr, +Fuel_consumption_lit_Acr, +M_M_Performance_in_compared_to_respective_competitor_tractors, +Fuel_consumption_lit_hr_2, +Area_covered_acr_hr_2, +Fuel_consumption_lit_Acr_2, +Trail_Observations, +Engine_Smoke_on_Load, +Engine_acceleration_smoke, +Draft_Response, +Tractor_Steer_ability, +Tractor_braking_performance, +Front_Visibility, +Implement_Accessibility, +Front_Wheel_dragging_at_turning, +Front_end_lifting_during_operation, +RPM_Recovery_Time, +Engine_Vibration, +Engine_Sound, +Implement_Lifting_Lowering_response, +Pulverization_Quality, +Pulverization_Index +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column3::text, +column4::text,column5::text,column6::text,column7::text]) AS val + FROM staging2.stg_process_table_FTWET_sum where block_tag=''FTWET_SUM_Test_Condition'' + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text, + a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text + ,a_21 text,a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text, +a_31 text,a_32 text,a_33 text,a_34 text,a_35 text,a_36 text,a_37 text,a_38 text); + +update staging2.FTWET_SUM_Test_Condition_Block +set test_iterationnumber=1 +where test_iterationnumber is null; + +insert into staging2.FTWET_SUM_Test_Condition_Block +( +dummy_f, +Test_Condition, +Test_Date, +Tractor_Model, +Engine_RPM_set, +PTO_RPM_set, +Gear_Used, +Nominal_Speed_KMPH, +Engine_RPM_Drop_on_straight_1st_Pass, +Engine_RPM_Drop_on_straight_2nd_Pass, +Engine_RPM_Drop_on_straight_3rd_Pass, +Engine_RPM_Drop_on_turn_1st_Pass, +Engine_RPM_Drop_on_turn_2nd_Pass, +Engine_RPM_Drop_on_turn_3rd_Pass, +No_of_passes, +Avg_Depth_of_cut_cm, +Fuel_consumption_lit_hr, +Area_covered_acr_hr, +Fuel_consumption_lit_Acr, +M_M_Performance_in_compared_to_respective_competitor_tractors, +Fuel_consumption_lit_hr_2, +Area_covered_acr_hr_2, +Fuel_consumption_lit_Acr_2, +Trail_Observations, +Engine_Smoke_on_Load, +Engine_acceleration_smoke, +Draft_Response, +Tractor_Steer_ability, +Tractor_braking_performance, +Front_Visibility, +Implement_Accessibility, +Front_Wheel_dragging_at_turning, +Front_end_lifting_during_operation, +RPM_Recovery_Time, +Engine_Vibration, +Engine_Sound, +Implement_Lifting_Lowering_response, +Pulverization_Quality, +Pulverization_Index +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column8,column9,column10,column11,column12}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column8::text, +column9::text,column10::text,column11::text,column12::text]) AS val + FROM staging2.stg_process_table_FTWET_sum where block_tag=''FTWET_SUM_Test_Condition'' + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text, + a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text + ,a_21 text,a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text, +a_31 text,a_32 text,a_33 text,a_34 text,a_35 text,a_36 text,a_37 text,a_38 text); + +update staging2.FTWET_SUM_Test_Condition_Block +set test_iterationnumber=2 +where test_iterationnumber is null; + + update staging2.FTWET_SUM_Test_Condition_Block a + set Test_Condition= b.first_value from (SELECT +test_iterationnumber,Test_Condition, value_partition, first_value(Test_Condition) over (partition by value_partition order by test_iterationnumber) +FROM ( +SELECT +test_iterationnumber, +Test_Condition, +sum(case when Test_Condition is null then 0 else 1 end) over (order by test_iterationnumber) as value_partition + FROM staging2.FTWET_SUM_Test_Condition_Block +ORDER BY test_iterationnumber asc +) as q) b where a.test_iterationnumber = b.test_iterationnumber; + + +delete from staging2.FTWET_SUM_Test_Condition_Block +where tractor_model is null or engine_rpm_set = '0'; + +update staging2.FTWET_SUM_Test_Condition_Block set fuel_consumption_lit_hr_2=null +where lower(fuel_consumption_lit_hr_2) like '%indicates%'; + +update staging2.FTWET_SUM_Test_Condition_Block +set fuel_consumption_lit_hr_2 = left(fuel_consumption_lit_hr_2,length(fuel_consumption_lit_hr_2)-3), +Area_covered_acr_hr_2 = left(Area_covered_acr_hr_2,length(Area_covered_acr_hr_2)-3) , +Fuel_consumption_lit_Acr_2 = left(Fuel_consumption_lit_Acr_2,length(Fuel_consumption_lit_Acr_2)-3) +where fuel_consumption_lit_hr_2 notnull; + + +delete from staging2.FTWET_SUM_Test_Condition_Block where dummy_f is null ; +execute 'update staging2.FTWET_SUM_Test_Condition_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTWET_SUM_Test_Condition_Block'); + + +/*inserting data into block -FTWET_SUM_Comments_By_Block*/ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTWET_SUM_Comments_By_Block',__file_mnemonic,__file_sheet_mnemonic,5); +err_block:='FTWET_SUM_Comments_By_Block'; + + +insert into staging2.FTWET_SUM_Comments_By_Block (dummy_f) values ('dummy'); + + + +execute 'update staging2.FTWET_SUM_Comments_By_Block set test_engineer_comments_1= +(select column3 from staging2.stg_process_table_ftwet_sum a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.block_tag=''FTWET_SUM_Engineer_Comments_1'' +and block_row_number=1 ) where dummy_f=''dummy''' ; + + +execute 'update staging2.FTWET_SUM_Comments_By_Block set test_manager_comments_1= +(select column3 from staging2.stg_process_table_ftwet_sum a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.block_tag=''FTWET_SUM_Manager_Comments_1'' +and block_row_number=1 ) where dummy_f=''dummy''' ; + + + + +execute 'update staging2.FTWET_SUM_Comments_By_Block set test_engineer_comments_2= +(select column8 from staging2.stg_process_table_ftwet_sum a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.block_tag=''FTWET_SUM_Engineer_Comments_1'' +and block_row_number=1 ) where dummy_f=''dummy''' ; + + + +execute 'update staging2.FTWET_SUM_Comments_By_Block set test_manager_comments_2= +(select column8 from staging2.stg_process_table_ftwet_sum a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.block_tag=''FTWET_SUM_Manager_Comments_1'' +and block_row_number=1 ) where dummy_f=''dummy''' ; + + + + + + +delete from staging2.FTWET_SUM_Comments_By_Block where dummy_f is null ; +execute 'update staging2.FTWET_SUM_Comments_By_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTWET_SUM_Comments_By_Block'); + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_FTWET_SUM_Block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + + + + diff --git a/onetime/dataloadfunctions/field/FTWET_TRS_ods.sql b/onetime/dataloadfunctions/field/FTWET_TRS_ods.sql new file mode 100755 index 0000000..297fecf --- /dev/null +++ b/onetime/dataloadfunctions/field/FTWET_TRS_ods.sql @@ -0,0 +1,375 @@ +drop function if exists staging2.fn_FTWET_TRS_TRX ; +CREATE OR REPLACE FUNCTION staging2.fn_FTWET_TRS_TRX(p_client_id int,p_function_id int, p_file_mnemonic text, +p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __test_instance_id int; + declare __test_instance_tractor_id int; + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare __make text; + declare __model text; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare _error int; + declare __test_master_id int; + declare __test_tractor_id int; + begin + +__file_syspk := p_file_syspk; + +/************************************************************ +Function Name:fn_FTWET_TRS_TRX +Function Desc: This function populates data into ODS +File Format: FTWET +Sheet Format: FTWET_TRS +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_FTWET_TRS_TRX() +***************************************************************/ + +insert into transactional.test_instance +( +client_id, +function_id, +test_report_no, +objective_of_test, +background_of_test, +job_order_no, +test_location_name, +soil_moisture_content_pct, +soil_bulk_density_g_per_cc, +test_engineer, +test_operator, +date_of_test, +test_report_date, +season, +type_of_soil, +soil_cone_index, +field_condition, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +) +select client_id, +function_id, +report_reference_no test_report_no, +objective_of_test, +background_of_test, +job_order_no, +test_location test_location_name, +soil_moisture_content_::numeric soil_moisture_content_pct , +soil_bulk_density_g_cc::numeric soil_bulk_density_g_per_cc, +test_engineer, +test_operator, +date_of_test::date, +report_date::date test_report_date, +season, +type_of_soil, +soil_cone_index_kpa::int soil_cone_index, +field_condition, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +from staging2.ftwet_trs_h1_block where trx_record=1; + + +insert into transactional.test_instance_tractor_info +( +client_id, +function_id, +tractor_model, +tractor_make, +tractor_sr_no, +tractor_engine_hp, +fip_type, +hour_Meter_Reading, +Steering_Type, +Transmission_Type, +wheel_drive_type, +egr_yn, +Brake_Type, +PTO_Type, +Standard_PTO_Speed_RPM, +EPTO_Speed_RPM, +tractor_weight_front_kg, +tractor_weight_rear_kg, +tractor_weight_total_kg, +Ballasted_Tractor_Accessories, +mechanical_ballast_rear_in_kg, +water_ballast_rear_75_pct , +Mechanical_Ballast_Front, +mechanical_ballast_front_kg , +Total_Ballast_Weight, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +) +select client_id, +function_id, +Tractor_Model, +Tractor_Make, +Tractor_Sr_No, +trim('HP' from Tractor_Engine_HP)::numeric, +FIP_Type, +hour_Meter_Reading::numeric, +Steering_Type, +Transmission_Type, +Wheel_Drive_Type_WD wheel_drive_type , +EGR_Yes_No egr_yn, +Brake_Type , +PTO_Type , +Standard_PTO_Speed_RPM::numeric, +EPTO_Speed_RPM::numeric, +Tractor_Weight_kg_Front::numeric tractor_weight_front_kg , +Tractor_Weight_kg_Rear::numeric tractor_weight_rear_kg , +Tractor_Weight_kg_Total::numeric tractor_weight_total_kg , +Ballasted_Tractor_Accessories, +Mechanical_Ballast_Rear_in_KG::numeric mechanical_ballast_rear_in_kg , +Water_Ballast_Rear water_ballast_rear_75_pct , +Mechanical_Ballast_Front, +Mechanical_Ballast_Front_in_Kg::int mechanical_ballast_front_kg , +Total_Ballast_Weight::numeric, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +from staging2.ftwet_trs_spec_block where trx_record=1; + +update transactional.test_instance_tractor_info +set mahindra_model_yn = ( +case when tractor_make like 'Mahindra%' then 'Y' else 'N' end +) where file_syspk =__file_syspk; + +update transactional.test_instance_tractor_info a +set test_tractor_yn ='Y' where syspk in +(select min(syspk) from transactional.test_instance_tractor_info b +where b.file_syspk =a.file_syspk ) +and a.file_syspk =__file_syspk; + +update transactional.test_instance_tractor_info +set test_tractor_yn ='N' +where test_tractor_yn is null and file_syspk =__file_syspk; + +insert into transactional.test_instance_tyre_info +( +client_id, +function_id, +tractor_make, +tractor_model, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tyre_type, +tyre_make, +tyre_size, +tyre_pressure_psi +) +select +client_id, +function_id, +tractor_make, +tractor_model, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +'front', +front_tyre_make tyre_make, +front_tyre_size tyre_size, +front_tyre_pressure_psi::int tyre_pressure_psi +from staging2.ftwet_trs_spec_block where trx_record=1; + +update transactional.test_instance_tyre_info a +set test_instance_tractor_id =(select syspk +from transactional.test_instance_tractor_info b +where a.file_syspk=b.file_syspk and +a.tractor_model=b.tractor_model and a.tractor_sr_no=b.tractor_sr_no) +where a.tyre_type ='front' and a.file_syspk =__file_syspk; + +insert into transactional.test_instance_tyre_info +( +client_id, +function_id, +tractor_make, +tractor_model, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +tyre_type, +tyre_make, +tyre_size, +tyre_pressure_psi +) +select +client_id, +function_id, +tractor_make, +tractor_model, +file_syspk, +file_mnemonic, +file_sheet_mnemonic, +'rear', +rear_tyre_make tyre_make, +rear_tyre_size tyre_size, +rear_tyre_pressure_psi::numeric tyre_pressure_psi +from staging2.ftwet_trs_spec_block where trx_record=1; + +update transactional.test_instance_tyre_info a +set test_instance_tractor_id =(select syspk +from transactional.test_instance_tractor_info b +where a.file_syspk=b.file_syspk and +a.tractor_model=b.tractor_model and a.tractor_sr_no=b.tractor_sr_no) +where a.tyre_type ='rear' and a.file_syspk = __file_syspk; + +insert into transactional.test_instance_engine_info +( +client_id, +function_id, +tractor_make, +tractor_model, +low_idle_declared, +high_idle_declared, +rated_rpm, +engine_to_pto_ratio_540_pto, +engine_to_pto_ratio_540e_pto, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +tractor_make, +tractor_model, +low_idle low_idle_declared, +high_idle high_idle_declared, +rated_rpm::numeric, +engine_to_pto_ratio_540_pto, +engine_to_pto_ratio_540e_pto, +file_syspk, +file_mnemonic, +file_sheet_mnemonic + from staging2.ftwet_trs_engine_rpm_block where trx_record=1; + +update transactional.test_instance_engine_info a +set test_instance_tractor_id =(select syspk +from transactional.test_instance_tractor_info b +where a.file_syspk=b.file_syspk and +a.tractor_model=b.tractor_model and a.tractor_sr_no=b.tractor_sr_no) +where a.file_syspk = __file_syspk; + +insert into transactional.test_instance_implement_info +( +client_id, +function_id, +name_of_implement, +type_of_implement, +make_of_implement, +no_of_disc_blades_bottoms, +cutting_width_m, +implement_weight_kg, +hitch_category, +span_for_mounted_implement_mm, +mast_height_for_mounted_implement_mm, +type_of_cage_wheel_hcw_fcw, +Cage_Wheel_Width_mm, +cage_wheel_weight_kg, +cage_wheel_inner_ring_dia_mm, +cage_wheel_outer_ring_dia_mm, +cage_wheel_center_ring_dia_mm, +dist_btwn_lhs_fcw_to_rhs_fcw_mm, +No_of_angles_on_cage_wheel, +No_of_days_of_water_logging, +Depth_of_water_mm, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +) +select +client_id, +function_id, +name_of_implement, +type_of_implement, +make_of_implement, +no_of_bottoms_tyne_disc_blade::numeric no_of_disc_blades_bottoms, +cutting_width_m, +implement_weight_kg::numeric, +hitch_category, +span_cm_for_mounted_implement::numeric span_for_mounted_implement_cm , +mast_height_cm_for_mounted_implement::numeric mast_height_for_mounted_implement_cm, +Type_of_Cage_Wheel_Half_Cage_wheel_Full_Cage_Wheel type_of_cage_wheel_hcw_fcw , +Cage_Wheel_Width_mm::numeric, +Cage_wheel_Weight::numeric cage_wheel_weight_kg, +Cage_Wheel_inner_Outer_Ring_Dia_mm::numeric cage_wheel_inner_ring_dia_mm , +Cage_Wheel_inner_Outer_Ring_Dia_mm::numeric cage_wheel_outer_ring_dia_mm, +Cage_Wheel_Center_Ring_Dia_mm::numeric cage_wheel_center_ring_dia_mm , +Distance_between_cage_wheel_Ring_mm_For_Full_wheel::int dist_btwn_lhs_fcw_to_rhs_fcw_mm, +No_of_angles_on_cage_wheel::numeric, +No_of_days_of_water_logging::numeric, +Depth_of_water_mm::numeric, +file_syspk, +file_mnemonic, +file_sheet_mnemonic +from staging2.ftwet_trs_implement_block where trx_record=1; + + +update transactional.test_instance a +set report_template_no=b.report_template_no, +report_template_rev_no=b.report_template_rev_no, +report_template_rev_date =b.report_template_rev_date +from staging2.ftwet_trs_implement_block b where a.file_syspk=b.file_syspk; + + +select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk; +select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk; +select syspk from transactional.test_master into __test_master_id where test_type ='Field'; +select syspk from transactional.test_instance_tractor_info into __test_tractor_id +where file_syspk =__file_syspk and test_tractor_yn ='Y'; + + +update transactional.test_instance +set test_master_id =__test_master_id, +test_tractor_id =__test_tractor_id +where file_syspk=__file_syspk; + +update transactional.test_instance_engine_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_tractor_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + + +update transactional.test_instance_tyre_info +set test_instance_id=__test_instance_id, +test_instance_tractor_id=__test_instance_tractor_id +where file_syspk=__file_syspk; + +update transactional.test_instance_implement_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.test_instance_trailer_info +set test_instance_id=__test_instance_id +where file_syspk=__file_syspk; + +update transactional.test_instance +set test_file_name =(select a.file_name from staging1.staging_generic_table a where file_syspk = __file_syspk limit 1) +where file_syspk = __file_syspk; + +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_FTWET_TRS_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + diff --git a/onetime/dataloadfunctions/field/FTWET_TRS_stg2.sql b/onetime/dataloadfunctions/field/FTWET_TRS_stg2.sql new file mode 100755 index 0000000..b20d63b --- /dev/null +++ b/onetime/dataloadfunctions/field/FTWET_TRS_stg2.sql @@ -0,0 +1,403 @@ +/*FTWET_TRS starts*/ + +drop function if exists staging2.fn_FTWET_TRS_Block ; +CREATE OR REPLACE FUNCTION staging2.fn_FTWET_TRS_Block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int) + RETURNS void + LANGUAGE plpgsql +AS $function$ + declare __make text; + declare __model text; + + declare __client_id int :=p_client_id; + declare __function_id int :=p_function_id; + declare __file_mnemonic text :=p_file_mnemonic; + declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic; + declare __file_syspk int :=p_file_syspk; + declare err_state text; + declare err_msg text; + declare err_detail text; + declare err_hint text; + declare err_context text; + declare err_query int; + declare err_block text; + + begin + +/*********************************************************************************** +Function Name:fn_FTWET_TRS_Block +Function Desc: This function populates data into staging2 blocks +File Format: FTWET +Sheet Format: FTWET_TRS +Creation Date: +Updation Date: +Author: compegence team +Function Call: select staging2.fn_fthlg_trs_block(20,1,'FTHLG','FTWET_TRS',260); +************************************************************************************/ + +SET search_path TO staging2; + +truncate staging2.FTWET_TRS_H1_INT; +truncate staging2.FTWET_TRS_H1_Block; +truncate staging2.FTWET_TRS_Engine_RPM_Block; +truncate staging2.FTWET_TRS_Implement_Block; +truncate staging2.ftwet_trs_spec_block; +truncate staging2.stg_specific_table_ftwet_trs; +truncate staging2.stg_process_table_ftwet_trs; + + +execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +execute 'update transactional.source_config a +set row_number_start=null, +row_previous_number=null, +row_read_end=null, +run_time=null +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + + +/* transfer data from generic to specific for ftwet*/ +execute 'insert into staging2.stg_specific_table_ftwet_trs +select * from staging1.staging_generic_table a +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +and a.file_syspk='||p_file_syspk||''; + +select count(*) into err_query from staging2.stg_specific_table_ftwet_trs; + +if err_query=0 then +err_context := 'data not present'; + raise exception using + message = 'No Data for FTWET Tractor Specifications', + detail = 'No data in table stg_specific_table_ftwet_trs', + errcode = '42704', + hint = 'check sheet mnemonic in generic table, if it is null update it'; +end if; + +/* trimming data */ + +update staging2.stg_specific_table_ftwet_trs set column2 = TRIM (TRAILING FROM column2 ); +update staging2.stg_specific_table_ftwet_trs set column2 = TRIM (LEADING FROM column2 ); +--update transactional.source_config set F1_modified = TRIM (TRAILING FROM F1_modified); +--update transactional.source_config set F1_modified = TRIM (LEADING FROM F1_modified); +--update transactional.source_config set F1_source = TRIM (TRAILING FROM F1_source); +--update transactional.source_config set F1_source = TRIM (LEADING FROM F1_source); + + +update transactional.source_config set F1_source=F1_modified ; + +/* keyword match in config table*/ +execute 'update transactional.source_config a +set row_number_start=(select min(b.row_number) +from staging2.stg_specific_table_ftwet_trs b +where upper(F1_source)=upper(column2) +and b.is_rownumber_fetched is null) +where a.row_number_start is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* reverese update in process table for match*/ +execute 'update staging2.stg_specific_table_ftwet_trs a +set is_rownumber_fetched=1 +from transactional.source_config b +where upper(F1_source)=upper(column2) +and b.row_number_start=a.row_number +and is_rownumber_fetched is null +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +execute 'update transactional.source_config a set row_previous_number=row_number_start-1 +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* update config files for row numbers start, end */ +execute 'update transactional.source_config a +set row_read_end= (select b.row_number_start +from transactional.source_config b +where b.syspk=a.syspk+1 ) +where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* config file last field update as null otherwise it picks up next format row number*/ +execute 'update transactional.source_config a set row_read_end = null where f1_modified =''Implement Details'' +and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/*inserting run_time in config*/ +execute 'update transactional.source_config a +set run_time=current_timestamp where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +/* tagging block_row_numbers for each block in process table*/ +execute 'insert into staging2.stg_process_table_ftwet_trs +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_ftwet_trs a +join transactional.source_config b +on a.row_number >row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Tractor Specifications Sheet'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +execute 'insert into staging2.stg_process_table_ftwet_trs +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_ftwet_trs a +join transactional.source_config b +on a.row_number >row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Tractor Specifications'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +execute 'insert into staging2.stg_process_table_ftwet_trs +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_ftwet_trs a +join transactional.source_config b +on a.row_number >row_number_start +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Engine RPM Data:'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +execute 'insert into staging2.stg_process_table_ftwet_trs +select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag +from staging2.stg_specific_table_ftwet_trs a +join transactional.source_config b +on a.row_number >row_number_start +and a.column2 <> '''' +and (a.row_number< row_read_end or row_read_end is null) +and f1_modified=''Implement Details'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' +order by a.row_number'; + +/*inserting data into FTHLG_TRS_H1_INT*/ +insert into staging2.FTWET_TRS_H1_INT(column2,column3,column4,column5,column6,column7,block_row_number) +select column2,column3,column4,column5,column6,column7,block_row_number from staging2.stg_process_table_ftwet_trs a +where block_tag='FTWET_TRS_H1'; + +insert into staging2.FTWET_TRS_H1_INT(column2,column3) +select 'Date of Test',column5 +from staging2.FTWET_TRS_H1_INT +where block_row_number=1; + +insert into staging2.FTWET_TRS_H1_INT(column2,column3) +select 'Report Date',column7 +from staging2.FTWET_TRS_H1_INT +where block_row_number=1; + +insert into staging2.FTWET_TRS_H1_INT(column2,column3) +select column5,column6 +from staging2.FTWET_TRS_H1_INT where block_row_number between 4 and 7; + + +/*inserting data into block -.FTWET_TRS_H1_Block*/ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTWET_TRS_H1_Block',__file_mnemonic,__file_sheet_mnemonic,1); +err_block:='FTWET_TRS_H1_Block'; + +insert into staging2.FTWET_TRS_H1_Block +( +dummy_f, +Report_Reference_No, +Objective_Of_Test, +Background_of_Test, +Job_Order_No, +Test_Location, +Soil_Moisture_Content_, +Soil_Bulk_Density_g_cc, +Test_Engineer, +Test_Operator, +Date_of_Test, +Report_Date, +Season, +Type_of_Soil, +Soil_Cone_Index_kPa, +Field_Condition +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column3}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column3::text]) AS val + FROM staging2.FTWET_TRS_H1_INT + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text, + a_11 text,a_12 text,a_13 text,a_14 text,a_15 text); + + + +delete from staging2.FTWET_TRS_H1_Block where dummy_f is null ; +execute 'update staging2.FTWET_TRS_H1_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTWET_TRS_H1_Block'); + + +/*inserting data into block -FTWET_TRS_SPEC_Block*/ + + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTWET_TRS_SPEC_Block',__file_mnemonic,__file_sheet_mnemonic,2); +err_block:='FTWET_TRS_SPEC_Block'; + +insert into staging2.FTWET_TRS_SPEC_Block +( +dummy_f, +Tractor_Model, +Tractor_Make, +Tractor_Sr_No, +Tractor_Engine_HP, +FIP_Type, +hour_Meter_Reading, +Steering_Type, +Transmission_Type, +Wheel_Drive_Type_WD, +EGR_Yes_No, +Brake_Type, +PTO_Type, +Standard_PTO_Speed_RPM, +EPTO_Speed_RPM, +Front_Tyre_Make, +Front_Tyre_Size, +Front_Tyre_Pressure_psi, +Rear_Tyre_Make, +Rear_Tyre_Size, +Rear_Tyre_Pressure_psi , +Tractor_Weight_kg_Front , +Tractor_Weight_kg_Rear , +Tractor_Weight_kg_Total, +Ballasted_Tractor_Accessories, +Mechanical_Ballast_Rear_in_KG , +Water_Ballast_Rear, +Mechanical_Ballast_Front, +Mechanical_Ballast_Front_in_Kg, +Total_Ballast_Weight +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val + FROM staging2.stg_process_table_ftwet_trs where block_tag=''FTWET_TRS_SPEC'' + ORDER BY generate_series(1,15),block_row_number,2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text, + a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text,a_21 text, + a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text); + +update staging2.FTWET_TRS_SPEC_Block set trx_record=0 +where tractor_make is null and tractor_sr_no is null; + +update staging2.FTWET_TRS_SPEC_Block set trx_record=0 +where (tractor_model is null and front_tyre_make is null) or (tractor_model is null and rear_tyre_make is null); + + +delete from staging2.FTWET_TRS_SPEC_Block where dummy_f is null ; +execute 'update staging2.FTWET_TRS_SPEC_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTWET_TRS_SPEC_Block'); + +/*inserting data into block -FTWET_TRS_SPEC_Block*/ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTWET_TRS_Engine_RPM_Block',__file_mnemonic,__file_sheet_mnemonic,3); +err_block:='FTWET_TRS_Engine_RPM_Block'; + +insert into staging2.FTWET_TRS_Engine_RPM_Block +( +dummy_f, +Tractor_model, +Tractor_make, +Low_Idle, +High_Idle, +Rated_RPM, +Engine_to_PTO_Ratio_540_PTO, +Engine_to_PTO_Ratio_540E_PTO +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val + FROM staging2.stg_process_table_ftwet_trs where block_tag=''FTWET_TRS_Engine_RPM'' + or (block_tag=''FTWET_TRS_SPEC'' and block_row_number in (1,2)) + ORDER BY generate_series(1,15),2' + ) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text); + +update staging2.FTWET_TRS_Engine_RPM_Block set trx_record=0 +where tractor_model is null; + +delete from staging2.FTWET_TRS_Engine_RPM_Block where dummy_f is null ; +execute 'update staging2.FTWET_TRS_Engine_RPM_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTWET_TRS_Engine_RPM_Block'); + + +/*inserting data into block -FTWET_TRS_Implement_Block*/ + +perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk, +'FTWET_TRS_Implement_Block',__file_mnemonic,__file_sheet_mnemonic,4); + +err_block:='FTWET_TRS_Implement_Block'; + +insert into staging2.FTWET_TRS_Implement_Block +( +dummy_f, +Name_of_Implement, +Type_of_Implement, +Make_of_Implement, +No_of_bottoms_Tyne_Disc_Blade, +Cutting_Width_m, +Implement_Weight_Kg, +Span_cm_For_Mounted_Implement, +Hitch_Category, +Mast_Height_cm_For_Mounted_Implement, +Type_of_Cage_Wheel_Half_Cage_wheel_Full_Cage_Wheel, +Cage_Wheel_Width_mm, +Cage_wheel_Weight, +Cage_Wheel_inner_Outer_Ring_Dia_mm, +Cage_Wheel_Center_Ring_Dia_mm, +Distance_between_cage_wheel_Ring_mm_For_Full_wheel, +No_of_angles_on_cage_wheel, +No_of_days_of_water_logging, +Depth_of_water_mm +) +SELECT * +FROM crosstab( + 'SELECT unnest(''{column3,column4,column5,column6}''::text[]) AS col + , row_number() OVER () + , unnest(ARRAY[column3::text,column4::text,column5::text,column6::text]) AS val + FROM staging2.stg_process_table_ftwet_trs where block_tag=''FTWET_TRS_Implement'' + ORDER BY generate_series(1,15),block_row_number,2' + ) t ( col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text + ,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text); + + +update staging2.FTWET_TRS_Implement_Block set report_template_no= (select column2 from staging2.stg_process_table_ftwet_trs where block_row_number=19 and block_tag='FTWET_TRS_Implement'); + + +update staging2.FTWET_TRS_Implement_Block set report_template_rev_no= (select column4 from staging2.stg_process_table_ftwet_trs where block_row_number=19 and block_tag='FTWET_TRS_Implement'); + + +update staging2.FTWET_TRS_Implement_Block set report_template_rev_date= (select column6 from staging2.stg_process_table_ftwet_trs where block_row_number=19 and block_tag='FTWET_TRS_Implement'); + +update staging2.FTWET_TRS_Implement_Block set trx_record=0 +where name_of_implement is null; + +execute 'update staging2.FTWET_TRS_Implement_Block set +client_id='||p_client_id||', +function_id='||p_function_id||', +file_syspk='||p_file_syspk||', +file_mnemonic='''||p_file_mnemonic||''', +file_sheet_mnemonic='''||p_file_sheet_mnemonic||''''; + +perform fw_core.fn_jobctl_block_end(__file_syspk,'FTWET_TRS_Implement_Block'); +perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_FTWET_TRS_Block', err_state, err_msg, err_detail, err_hint, err_context,'success'); + +end +$function$ +; + diff --git a/onetime/wrappers/.wrapper_FTDRY.sql.swp b/onetime/wrappers/.wrapper_FTDRY.sql.swp new file mode 100755 index 0000000..74aba12 Binary files /dev/null and b/onetime/wrappers/.wrapper_FTDRY.sql.swp differ diff --git a/onetime/wrappers/master_wrapper.sql b/onetime/wrappers/master_wrapper.sql new file mode 100755 index 0000000..f69c407 --- /dev/null +++ b/onetime/wrappers/master_wrapper.sql @@ -0,0 +1,219 @@ +drop function if exists fw_core.fn_run_master_wrapper; +CREATE OR REPLACE FUNCTION fw_core.fn_run_master_wrapper(p_client_id int,p_function_id int,p_job_id int,p_step_id int) + RETURNS void AS $$ + declare + f record; + stg2_status text; + success_sum int; + err_file_syspk int; + TRX_status text; + w_job_id int := p_job_id; + w_step_id int := p_step_id; + w_function_id int := p_function_id; + w_client_id int := p_client_id; + begin + +-- update fw_core.fw_jobctl_runschedule_jobstep set begin_status='started',start_time=now() where job_id = w_job_id and step_id = w_step_id and latest_runschedule_flag = '1'; + + for f in select distinct file_syspk,file_mnemonic,file_sheet_mnemonic,sheet_id + from fw_core.fw_jobctl_file_sheet_runschedule where file_sheet_mnemonic !='' + and latest_runschedule_flag = '1' and end_status != 'error' and end_status_note = 'generic_validation_completed' + order by file_syspk,sheet_id + loop + + if err_file_syspk = f.file_syspk then + --incase of file stg2/trx fail then dont run script for those files and rollback previous change if any. + --rollback for that file syspk needs to be added + --perform staging2.run_trx_rollback(f.file_syspk) + continue; + else + --run staging 2 scripts depending on sheet mnemonic + if f.file_sheet_mnemonic = 'FTDRY_TRS' then + perform fw_core.fn_get_function_exception('staging2.fn_FTDRY_TRS_Block('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'FTDRY_SUM' then + perform fw_core.fn_get_function_exception('staging2.fn_FTDRY_SUM_Block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'FTWET_TRS' then + perform fw_core.fn_get_function_exception('staging2.fn_ftwet_trs_block('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'FTWET_SUM' then + perform fw_core.fn_get_function_exception('staging2.fn_FTWET_SUM_Block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'FTHLG_TRS' then + perform fw_core.fn_get_function_exception('staging2.fn_FTHLG_TRS_Block('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'FTHLG_SUM' then + perform fw_core.fn_get_function_exception('staging2.fn_FTHLG_SUM_Block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'DBSTD_TEST' then + perform fw_core.fn_get_function_exception('staging2.fn_dbstd_test_block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'DBOECD_TEST' then + perform fw_core.fn_get_function_exception('staging2.fn_dboecd_test_block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic in ('PTOBEN_PRFN','PTOBEN_PRFE','PTOBEN_PRFB','PTOSTD_PRF') then + perform fw_core.fn_get_function_exception('staging2.fn_PTO_PRF_block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic in ('PTOBEN_MPM','PTOSTD_MPM') then + perform fw_core.fn_get_function_exception('staging2.fn_PTO_MPM_block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic in ('PTOBEN_GVG','PTOSTD_GVG') then + perform fw_core.fn_get_function_exception('staging2.fn_PTO_GVG_block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'BUDNI_BRK' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_BRK_Block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'BUDNI_FLD' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_FLD_Block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'BUDNI_HDL' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_HDL_Block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'BUDNI_NMT' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_NMT_Block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'BUDNI_HLG' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_HLG_Block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'BUDNI_PTO' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_PTO_Block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'BUDNI_VMT' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_VMT_Block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'BUDNI_ARC' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_ARC_Block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'BUDNI_DBP' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_DBP_Block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'BUDNI_LCG' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_LCG_Block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'IHTCGM_CGM' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTCGM_CGM_Block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'IHTEMT_STD' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTEMT_STD_Block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'IHTEMT_EMT' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTEMT_EMT_Block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'IHTHAM_HAM' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTHAM_HAM_Block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'IHTHLS_HLS' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTHLS_HLS_Block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'IHTNST_NST' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTNST_NST_Block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'IHTSLL_SLL' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTSLL_SLL_Block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'IHTBT30_BT30' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTBT30_BT30_Block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'IHTBT50_BT50' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTBT50_BT50_Block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'IHTBTD_BTD' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTBTD_BTD_Block ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''||f.file_sheet_mnemonic||''','||f.file_syspk||')'); + else perform fw_core.fn_insert_db_error ( w_function_id, w_function_id, 1001, 'Compegence', f.file_syspk ,f.file_mnemonic,f.file_sheet_mnemonic ,null,'stg2 wrapper', 'unknown block', null, 'no script found', 'Script not present for the particlar sheet mnemonic', null, null,'error'); +end if; + -- check if staging 2 script ran correctly and update fw_jobctl_file_sheet_runschedule table. + select e.status from fw_core.db_run_status e where file_syspk = f.file_syspk and file_sheet_mnemonic =f.file_sheet_mnemonic and staging_type = 'stg2' order by error_timestamp desc into stg2_status; + if stg2_status = 'success' then + update fw_core.fw_jobctl_file_sheet_runschedule set end_status_note = 'stg2_completed', end_status='success',staging_type = 'stg2',end_time = (select e.error_timestamp from fw_core.db_run_status e where e.file_syspk=f.file_syspk and e.file_sheet_mnemonic =f.file_sheet_mnemonic and e.staging_type = 'stg2' order by e.error_timestamp desc limit 1) + where file_syspk=f.file_syspk and file_sheet_mnemonic =f.file_sheet_mnemonic; + else + update fw_core.fw_jobctl_file_sheet_runschedule set end_status_note = 'stg2_failed', end_status='error',staging_type = 'stg2',end_time = (select e.error_timestamp from fw_core.db_run_status e where e.file_syspk=f.file_syspk and e.file_sheet_mnemonic =f.file_sheet_mnemonic and e.staging_type = 'stg2' order by e.error_timestamp desc limit 1) + where file_syspk=f.file_syspk and file_sheet_mnemonic =f.file_sheet_mnemonic; + --if error occured store in err_file_syspk variable and go to next file in loop + err_file_syspk := f.file_syspk; + continue; + end if; + + + +--run transactional scripts depending on sheet mnemonic + if f.file_sheet_mnemonic = 'FTDRY_TRS' then + perform fw_core.fn_get_function_exception('staging2.fn_FTDRY_TRS_TRX('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'FTDRY_SUM' then + perform fw_core.fn_get_function_exception('staging2.fn_FTDRY_SUM_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'FTWET_TRS' then + perform fw_core.fn_get_function_exception('staging2.fn_ftwet_trs_TRX('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'FTWET_SUM' then + perform fw_core.fn_get_function_exception('staging2.fn_FTWET_SUM_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'FTHLG_TRS' then + perform fw_core.fn_get_function_exception('staging2.fn_FTHLG_TRS_TRX('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'FTHLG_SUM' then + perform fw_core.fn_get_function_exception('staging2.fn_FTHLG_SUM_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'DBSTD_TEST' then + perform fw_core.fn_get_function_exception('staging2.fn_dbstd_test_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'DBOECD_TEST' then + perform fw_core.fn_get_function_exception('staging2.fn_dboecd_test_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic in ('PTOBEN_PRFN','PTOBEN_PRFE','PTOBEN_PRFB','PTOSTD_PRF') then + perform fw_core.fn_get_function_exception('staging2.fn_PTO_PRF_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic in ('PTOBEN_MPM','PTOSTD_MPM') then + perform fw_core.fn_get_function_exception('staging2.fn_PTO_MPM_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic in ('PTOBEN_GVG','PTOSTD_GVG') then + perform fw_core.fn_get_function_exception('staging2.fn_PTO_GVG_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'BUDNI_BRK' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_BRK_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'BUDNI_FLD' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_FLD_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'BUDNI_HDL' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_HDL_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'BUDNI_NMT' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_NMT_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'BUDNI_HLG' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_HLG_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'BUDNI_PTO' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_PTO_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'BUDNI_VMT' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_VMT_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'BUDNI_ARC' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_ARC_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'BUDNI_DBP' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_DBP_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'BUDNI_LCG' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_LCG_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'IHTCGM_CGM' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTCGM_CGM_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'IHTEMT_STD' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTEMT_STD_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'IHTEMT_EMT' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTEMT_EMT_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'IHTHAM_HAM' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTHAM_HAM_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'IHTHLS_HLS' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTHLS_HLS_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'IHTNST_NST' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTNST_NST_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'IHTSLL_SLL' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTSLL_SLL_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'IHTBT30_BT30' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTBT30_BT30_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'IHTBT50_BT50' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTBT50_BT50_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + elsif f.file_sheet_mnemonic = 'IHTBTD_BTD' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTBTD_BTD_TRX ('||w_client_id||','||w_function_id||','''||f.file_mnemonic||''','''|| f.file_sheet_mnemonic||''','||f.file_syspk||')'); + else perform fw_core.fn_insert_db_error ( w_client_id, w_function_id, 1001, 'Compegence', f.file_syspk ,f.file_mnemonic, f.file_sheet_mnemonic ,null,'TRX wrapper', 'unknown TRX', null, 'no script found', null, null, null,'error'); +end if; + -- check if transactional script ran correctly and update fw_jobctl_file_sheet_runschedule table. + select e.status from fw_core.db_run_status e where file_syspk = f.file_syspk and file_sheet_mnemonic =f.file_sheet_mnemonic and staging_type = 'trx' order by error_timestamp desc into TRX_status; + if TRX_status = 'success' then + update fw_core.fw_jobctl_file_sheet_runschedule set end_status_note = 'TRX_completed', end_status='success',staging_type = 'trx',end_time = now() +--(select e.error_timestamp from fw_core.db_run_status e where e.file_syspk=f.file_syspk and e.file_sheet_mnemonic =f.file_sheet_mnemonic and e.staging_type = 'trx' order by e.error_timestamp desc limit 1) + where file_syspk=f.file_syspk and file_sheet_mnemonic =f.file_sheet_mnemonic; + else + update fw_core.fw_jobctl_file_sheet_runschedule set end_status_note = 'TRX_failed', end_status='error',staging_type = 'trx',end_time = now() +--(select e.error_timestamp from fw_core.db_run_status e where e.file_syspk=f.file_syspk and e.file_sheet_mnemonic =f.file_sheet_mnemonic and e.staging_type = 'trx' order by e.error_timestamp desc limit 1) + where file_syspk=f.file_syspk and file_sheet_mnemonic =f.file_sheet_mnemonic; + --if error occured store in err_file_syspk variable and go to next file in loop + err_file_syspk := f.file_syspk; + continue; + end if; +end if; +end loop; + +-- update fw_jobctl_file_runschedule table. + +update fw_core.fw_jobctl_file_runschedule set end_status_note = 'stg2_failed', end_status='error',staging_type = 'stg2',end_time=now() from fw_core.fw_jobctl_file_sheet_runschedule a +where a.latest_runschedule_flag = '1' and a.end_status = 'error' and a.end_status_note = 'stg2_failed' and fw_core.fw_jobctl_file_runschedule.file_syspk = a.file_syspk; + +update fw_core.fw_jobctl_file_runschedule set end_status_note = 'TRX_completed', end_status='success',staging_type = 'trx',end_time=now() from fw_core.fw_jobctl_file_sheet_runschedule a +where a.latest_runschedule_flag = '1' and a.end_status = 'success' and a.end_status_note ='TRX_completed' and fw_core.fw_jobctl_file_runschedule.file_syspk = a.file_syspk; + +update fw_core.fw_jobctl_file_runschedule set end_status_note = 'TRX_failed', end_status='error',staging_type = 'trx' ,end_time=now() from fw_core.fw_jobctl_file_sheet_runschedule a +where a.latest_runschedule_flag = '1' and a.end_status = 'error' and a.end_status_note = 'TRX_failed' and fw_core.fw_jobctl_file_runschedule.file_syspk = a.file_syspk; + +-- update fw_jobctl_runschedule_jobstep table. +SELECT SUM (case WHEN end_status = 'success' THEN 1 + ELSE 0 END) AS "Success Sum" FROM fw_core.fw_jobctl_file_runschedule where latest_runschedule_flag = '1' INTO success_sum; +if (success_sum > 0 or success_sum is null) then +update fw_core.fw_jobctl_runschedule_jobstep set end_status_note = 'trx_completed', end_status='success', end_time=now() where job_id = w_job_id and step_id = w_step_id and latest_runschedule_flag = '1'; +else +update fw_core.fw_jobctl_runschedule_jobstep set end_status_note = 'trx_failed', end_status='error', end_time=now() where job_id = w_job_id and step_id = w_step_id and latest_runschedule_flag = '1'; +end if; + + + +--insert into fw_core.track_jobstep select *,'master_wrapper' from fw_core.fw_jobctl_runschedule_jobstep; +--insert into fw_core.track_file select *,'mater_wrapper' from fw_core.fw_jobctl_file_runschedule; +--insert into fw_core.track_file_sheet select *,'master_wrapper' from fw_core.fw_jobctl_file_sheet_runschedule; + +end; +$$ LANGUAGE plpgsql; \ No newline at end of file diff --git a/onetime/wrappers/wrapper_BUDNI.sql b/onetime/wrappers/wrapper_BUDNI.sql new file mode 100755 index 0000000..c3921b1 --- /dev/null +++ b/onetime/wrappers/wrapper_BUDNI.sql @@ -0,0 +1,66 @@ +drop function if exists staging2.fn_BUDNI_RUN; +CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_RUN() + RETURNS void AS $$ + declare + f record; + w_file_syspk int; + status text; + begin + for f in select distinct a.file_syspk + from fw_core.fw_jobctl_file_runschedule a + where end_status like 'stg1-completed' and file_mnemonic='BUDNI' + loop + select f.file_syspk into w_file_syspk; + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_ARC_Block(20,1,''BUDNI'',''BUDNI_ARC'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_ARC' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_ARC_TRX(20,1,''BUDNI'',''BUDNI_ARC'','||w_file_syspk||')'); + end if; + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_BRK_Block (20,1,''BUDNI'',''BUDNI_BRK'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_BRK' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_BRK_TRX(20,1,''BUDNI'',''BUDNI_BRK'','||w_file_syspk||')'); + end if; + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_DBP_Block (20,1,''BUDNI'',''BUDNI_DBP'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_DBP' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_DBP_TRX(20,1,''BUDNI'',''BUDNI_DBP'','||w_file_syspk||')'); + end if; + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_FLD_Block (20,1,''BUDNI'',''BUDNI_FLD'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_FLD' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_FLD_TRX(20,1,''BUDNI'',''BUDNI_FLD'','||w_file_syspk||')'); + end if; + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_HDL_Block(20,1,''BUDNI'',''BUDNI_HDL'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_HDL' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_HDL_TRX(20,1,''BUDNI'',''BUDNI_HDL'','||w_file_syspk||')'); + end if; + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_HLG_Block(20,1,''BUDNI'',''BUDNI_HLG'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_HLG' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_HLG_TRX(20,1,''BUDNI'',''BUDNI_HLG'','||w_file_syspk||')'); + end if; + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_LCG_Block(20,1,''BUDNI'',''BUDNI_LCG'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_LCG' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_LCG_TRX(20,1,''BUDNI'',''BUDNI_LCG'','||w_file_syspk||')'); + end if; + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_NMT_Block(20,1,''BUDNI'',''BUDNI_NMT'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_NMT' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_NMT_TRX(20,1,''BUDNI'',''BUDNI_NMT'','||w_file_syspk||')'); + end if; + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_PTO_Block(20,1,''BUDNI'',''BUDNI_PTO'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_PTO' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_PTO_TRX(20,1,''BUDNI'',''BUDNI_PTO'','||w_file_syspk||')'); + end if; + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_VMT_Block(20,1,''BUDNI'',''BUDNI_VMT'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='BUDNI_VMT' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_BUDNI_VMT_TRX(20,1,''BUDNI'',''BUDNI_VMT'','||w_file_syspk||')'); + end if; + end loop; +end; +$$ LANGUAGE plpgsql; diff --git a/onetime/wrappers/wrapper_DBOECD.sql b/onetime/wrappers/wrapper_DBOECD.sql new file mode 100755 index 0000000..e02a6a4 --- /dev/null +++ b/onetime/wrappers/wrapper_DBOECD.sql @@ -0,0 +1,20 @@ +drop function if exists staging2.fn_DBOECD_RUN; +CREATE OR REPLACE FUNCTION staging2.fn_DBOECD_RUN() + RETURNS void AS $$ + declare + f record; + w_file_syspk int; + status text; + begin + for f in select file_syspk from fw_core.fw_jobctl_file_runschedule + where end_status like 'stg1-completed' and file_mnemonic='DBOECD' + loop + select f.file_syspk into w_file_syspk; + perform fw_core.fn_get_function_exception('staging2.fn_dboecd_test_block(20,1,''DBOECD'',''DBOECD_TEST'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='DBOECD_TEST' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_dboecd_test_trx(20,1,''DBOECD'',''DBOECD_TEST'','||w_file_syspk||')'); + end if; + end loop; +end; +$$ LANGUAGE plpgsql; \ No newline at end of file diff --git a/onetime/wrappers/wrapper_DBSTD.sql b/onetime/wrappers/wrapper_DBSTD.sql new file mode 100755 index 0000000..c460820 --- /dev/null +++ b/onetime/wrappers/wrapper_DBSTD.sql @@ -0,0 +1,20 @@ +drop function if exists staging2.fn_DBSTD_RUN; +CREATE OR REPLACE FUNCTION staging2.fn_DBSTD_RUN() + RETURNS void AS $$ + declare + f record; + w_file_syspk int; + status text; + begin + for f in select file_syspk from fw_core.fw_jobctl_file_runschedule + where end_status like 'stg1-completed' and file_mnemonic='DBSTD' + loop + select f.file_syspk into w_file_syspk; + perform fw_core.fn_get_function_exception('staging2.fn_dbstd_test_block(20,1,''DBSTD'',''DBSTD_TEST'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='DBSTD_TEST' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_dbstd_test_trx(20,1,''DBSTD'',''DBSTD_TEST'','||w_file_syspk||')'); + end if; + end loop; +end; +$$ LANGUAGE plpgsql; diff --git a/onetime/wrappers/wrapper_FTDRY.sql b/onetime/wrappers/wrapper_FTDRY.sql new file mode 100755 index 0000000..b75b68a --- /dev/null +++ b/onetime/wrappers/wrapper_FTDRY.sql @@ -0,0 +1,25 @@ +drop function if exists staging2.fn_FTDRY_RUN; +CREATE OR REPLACE FUNCTION staging2.fn_FTDRY_RUN() + RETURNS void AS $$ + declare + f record; + w_file_syspk int; + status text; + begin + for f in select file_syspk from fw_core.fw_jobctl_file_runschedule + where end_status like 'stg1-completed' and file_mnemonic='FTDRY' + loop + select f.file_syspk into w_file_syspk; + perform fw_core.fn_get_function_exception('staging2.fn_FTDRY_TRS_Block(20,1,''FTDRY'',''FTDRY_TRS'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='FTDRY_TRS' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_FTDRY_TRS_TRX(20,1,''FTDRY'',''FTDRY_TRS'','||w_file_syspk||')'); + end if; + perform fw_core.fn_get_function_exception('staging2.fn_FTDRY_SUM_Block (20,1,''FTDRY'',''FTDRY_SUM'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='FTDRY_SUM' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_FTDRY_SUM_TRX(20,1,''FTDRY'',''FTDRY_SUM'','||w_file_syspk||')'); + end if; + end loop; +end; +$$ LANGUAGE plpgsql; diff --git a/onetime/wrappers/wrapper_FTHLG.sql b/onetime/wrappers/wrapper_FTHLG.sql new file mode 100755 index 0000000..7bd2808 --- /dev/null +++ b/onetime/wrappers/wrapper_FTHLG.sql @@ -0,0 +1,25 @@ +drop function if exists staging2.fn_FTHLG_RUN; +CREATE OR REPLACE FUNCTION staging2.fn_FTHLG_RUN() + RETURNS void AS $$ + declare + f record; + w_file_syspk int; + status text; + begin + for f in select file_syspk from fw_core.fw_jobctl_file_runschedule + where end_status like 'stg1-completed' and file_mnemonic='FTHLG' + loop + select f.file_syspk into w_file_syspk; + perform fw_core.fn_get_function_exception('staging2.fn_FTHLG_TRS_Block(20,1,''FTHLG'',''FTHLG_TRS'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='FTHLG_TRS' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_FTHLG_TRS_TRX(20,1,''FTHLG'',''FTHLG_TRS'','||w_file_syspk||')'); + end if; + perform fw_core.fn_get_function_exception('staging2.fn_FTHLG_SUM_Block (20,1,''FTHLG'',''FTHLG_SUM'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='FTHLG_SUM' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_FTHLG_SUM_TRX(20,1,''FTHLG'',''FTHLG_SUM'','||w_file_syspk||')'); + end if; + end loop; +end; +$$ LANGUAGE plpgsql; \ No newline at end of file diff --git a/onetime/wrappers/wrapper_FTWET.sql b/onetime/wrappers/wrapper_FTWET.sql new file mode 100755 index 0000000..f297049 --- /dev/null +++ b/onetime/wrappers/wrapper_FTWET.sql @@ -0,0 +1,25 @@ +drop function if exists staging2.fn_FTWET_RUN; +CREATE OR REPLACE FUNCTION staging2.fn_FTWET_RUN() + RETURNS void AS $$ + declare + f record; + w_file_syspk int; + status text; + begin + for f in select file_syspk from fw_core.fw_jobctl_file_runschedule + where end_status like 'stg1-completed' and file_mnemonic='FTWET' + loop + select f.file_syspk into w_file_syspk; + perform fw_core.fn_get_function_exception('staging2.fn_ftwet_trs_block(20,1,''FTWET'',''FTWET_TRS'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='FTWET_TRS' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_FTWET_TRS_TRX(20,1,''FTWET'',''FTWET_TRS'','||w_file_syspk||')'); + end if; + perform fw_core.fn_get_function_exception('staging2.fn_ftwet_sum_block (20,1,''FTWET'',''FTWET_SUM'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='FTWET_SUM' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_FTWET_SUM_TRX(20,1,''FTWET'',''FTWET_SUM'','||w_file_syspk||')'); + end if; + end loop; +end; +$$ LANGUAGE plpgsql; \ No newline at end of file diff --git a/onetime/wrappers/wrapper_IHTBT30.sql b/onetime/wrappers/wrapper_IHTBT30.sql new file mode 100755 index 0000000..3e562b5 --- /dev/null +++ b/onetime/wrappers/wrapper_IHTBT30.sql @@ -0,0 +1,21 @@ +drop function if exists staging2.fn_IHTBT30_RUN; +CREATE OR REPLACE FUNCTION staging2.fn_IHTBT30_RUN() + RETURNS void AS $$ + declare + f record; + w_file_syspk int; + status text; + begin + for f in select file_syspk from fw_core.fw_jobctl_file_runschedule + where end_status like 'stg1-completed' and file_mnemonic = 'IHTBT30' order by file_syspk + loop + select f.file_syspk into w_file_syspk; + perform fw_core.fn_get_function_exception('staging2.fn_IHTBT30_BT30_Block(20,1,''IHTBT30'',''IHTBT30_BT30'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='IHTBT30_BT30' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTBT30_BT30_TRX(20,1,''IHTBT30'',''IHTBT30_BT30'','||w_file_syspk||')'); + end if; + end loop; + +end; +$$ LANGUAGE plpgsql; diff --git a/onetime/wrappers/wrapper_IHTBT50.sql b/onetime/wrappers/wrapper_IHTBT50.sql new file mode 100755 index 0000000..ff96a53 --- /dev/null +++ b/onetime/wrappers/wrapper_IHTBT50.sql @@ -0,0 +1,21 @@ +drop function if exists staging2.fn_IHTBT50_RUN; +CREATE OR REPLACE FUNCTION staging2.fn_IHTBT50_RUN() + RETURNS void AS $$ + declare + f record; + w_file_syspk int; + status text; + begin + for f in select file_syspk from fw_core.fw_jobctl_file_runschedule + where end_status like 'stg1-completed' and file_mnemonic = 'IHTBT50' order by file_syspk + loop + select f.file_syspk into w_file_syspk; + perform fw_core.fn_get_function_exception('staging2.fn_IHTBT50_BT50_Block(20,1,''IHTBT50'',''IHTBT50_BT50'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='IHTBT50_BT50' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTBT50_BT50_TRX(20,1,''IHTBT50'',''IHTBT50_BT50'','||w_file_syspk||')'); + end if; + end loop; + +end; +$$ LANGUAGE plpgsql; diff --git a/onetime/wrappers/wrapper_IHTBTD.sql b/onetime/wrappers/wrapper_IHTBTD.sql new file mode 100755 index 0000000..77df592 --- /dev/null +++ b/onetime/wrappers/wrapper_IHTBTD.sql @@ -0,0 +1,22 @@ +drop function if exists staging2.fn_IHTBTD_RUN; +CREATE OR REPLACE FUNCTION staging2.fn_IHTBTD_RUN() + RETURNS void AS $$ + declare + f record; + w_file_syspk int; + status text; + begin + for f in select file_syspk from fw_core.fw_jobctl_file_runschedule + where end_status like 'stg1-completed' and file_mnemonic = 'IHTBTD' order by file_syspk + loop + select f.file_syspk into w_file_syspk; + perform fw_core.fn_get_function_exception('staging2.fn_IHTBTD_BTD_Block(20,1,''IHTBTD'',''IHTBTD_BTD'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='IHTBTD_BTD' + order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTBTD_BTD_TRX(20,1,''IHTBTD'',''IHTBTD_BTD'','||w_file_syspk||')'); + end if; + end loop; + +end; +$$ LANGUAGE plpgsql; diff --git a/onetime/wrappers/wrapper_IHTCGM.sql b/onetime/wrappers/wrapper_IHTCGM.sql new file mode 100755 index 0000000..d380c6a --- /dev/null +++ b/onetime/wrappers/wrapper_IHTCGM.sql @@ -0,0 +1,22 @@ +drop function if exists staging2.fn_IHTCGM_RUN; +CREATE OR REPLACE FUNCTION staging2.fn_IHTCGM_RUN() + RETURNS void AS $$ + declare + f record; + w_file_syspk int; + status text; + begin + for f in select file_syspk from fw_core.fw_jobctl_file_runschedule + where end_status like 'stg1-completed' and file_mnemonic = 'IHTCGM' order by file_syspk + loop + select f.file_syspk into w_file_syspk; + perform fw_core.fn_get_function_exception('staging2.fn_IHTCGM_CGM_Block(20,1,''IHTCGM'',''IHTCGM_CGM'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='IHTCGM_CGM' + order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTCGM_CGM_TRX(20,1,''IHTCGM'',''IHTCGM_CGM'','||w_file_syspk||')'); + end if; + end loop; + +end; +$$ LANGUAGE plpgsql; diff --git a/onetime/wrappers/wrapper_IHTEMT.sql b/onetime/wrappers/wrapper_IHTEMT.sql new file mode 100755 index 0000000..b4ce046 --- /dev/null +++ b/onetime/wrappers/wrapper_IHTEMT.sql @@ -0,0 +1,26 @@ +drop function if exists staging2.fn_IHTEMT_RUN; +CREATE OR REPLACE FUNCTION staging2.fn_IHTEMT_RUN() + RETURNS void AS $$ + declare + f record; + w_file_syspk int; + status text; + begin + for f in select file_syspk from fw_core.fw_jobctl_file_runschedule + where end_status like 'stg1-completed' and file_mnemonic = 'IHTEMT' order by file_syspk + loop + select f.file_syspk into w_file_syspk; + perform fw_core.fn_get_function_exception('staging2.fn_IHTEMT_EMT_Block(20,1,''IHTEMT'',''IHTEMT_EMT'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='IHTEMT_EMT' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTEMT_EMT_TRX(20,1,''IHTEMT'',''IHTEMT_EMT'','||w_file_syspk||')'); + end if; + perform fw_core.fn_get_function_exception('staging2.fn_IHTEMT_STD_Block(20,1,''IHTEMT'',''IHTEMT_STD'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='IHTEMT_STD' order by error_timestamp desc into status; + if status = 'success' then +perform fw_core.fn_get_function_exception('staging2.fn_IHTEMT_STD_TRX(20,1,''IHTEMT'',''IHTEMT_STD'','||w_file_syspk||')'); +end if; + end loop; + +end; +$$ LANGUAGE plpgsql; diff --git a/onetime/wrappers/wrapper_IHTHAM.sql b/onetime/wrappers/wrapper_IHTHAM.sql new file mode 100755 index 0000000..5039b52 --- /dev/null +++ b/onetime/wrappers/wrapper_IHTHAM.sql @@ -0,0 +1,22 @@ +drop function if exists staging2.fn_IHTHAM_RUN; +CREATE OR REPLACE FUNCTION staging2.fn_IHTHAM_RUN() + RETURNS void AS $$ + declare + f record; + w_file_syspk int; + status text; + begin + for f in select file_syspk from fw_core.fw_jobctl_file_runschedule + where end_status like 'stg1-completed' and file_mnemonic = 'IHTHAM' order by file_syspk + loop + select f.file_syspk into w_file_syspk; + perform fw_core.fn_get_function_exception('staging2.fn_IHTHAM_HAM_Block(20,1,''IHTHAM'',''IHTHAM_HAM'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='IHTHAM_HAM' + order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_IHTHAM_HAM_TRX(20,1,''IHTHAM'',''IHTHAM_HAM'','||w_file_syspk||')'); + end if; + end loop; + +end; +$$ LANGUAGE plpgsql; diff --git a/onetime/wrappers/wrapper_IHTHSL.sql b/onetime/wrappers/wrapper_IHTHSL.sql new file mode 100755 index 0000000..7734b1c --- /dev/null +++ b/onetime/wrappers/wrapper_IHTHSL.sql @@ -0,0 +1,21 @@ +drop function if exists staging2.fn_IHTHSL_RUN; +CREATE OR REPLACE FUNCTION staging2.fn_IHTHSL_RUN() + RETURNS void AS $$ + declare + f record; + w_file_syspk int; + status text; + begin + for f in select file_syspk from fw_core.fw_jobctl_file_runschedule + where end_status like 'stg1-completed' and file_mnemonic = 'IHTHSL' order by file_syspk + loop + select f.file_syspk into w_file_syspk; + perform fw_core.fn_get_function_exception('staging2.fn_IHTHSL_HSL_Block(20,1,''IHTHSL'',''IHTHSL_HSL'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='IHTHSL_HSL' order by error_timestamp desc into status; + if status = 'success' then +perform fw_core.fn_get_function_exception('staging2.fn_IHTHSL_HSL_TRX(20,1,''IHTHSL'',''IHTHSL_HSL'','||w_file_syspk||')'); + end if; + end loop; + +end; +$$ LANGUAGE plpgsql; diff --git a/onetime/wrappers/wrapper_IHTNST.sql b/onetime/wrappers/wrapper_IHTNST.sql new file mode 100755 index 0000000..c1e35bd --- /dev/null +++ b/onetime/wrappers/wrapper_IHTNST.sql @@ -0,0 +1,21 @@ +drop function if exists staging2.fn_IHTNST_RUN; +CREATE OR REPLACE FUNCTION staging2.fn_IHTNST_RUN() + RETURNS void AS $$ + declare + f record; + w_file_syspk int; + status text; + begin + for f in select file_syspk from fw_core.fw_jobctl_file_runschedule + where end_status like 'stg1-completed' and file_mnemonic = 'IHTNST' order by file_syspk + loop + select f.file_syspk into w_file_syspk; + perform fw_core.fn_get_function_exception('staging2.fn_IHTNST_NST_Block(20,1,''IHTNST'',''IHTNST_NST'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='IHTNST_NST' order by error_timestamp desc into status; + if status = 'success' then +perform fw_core.fn_get_function_exception('staging2.fn_IHTNST_NST_TRX(20,1,''IHTNST'',''IHTNST_NST'','||w_file_syspk||')'); +end if; + end loop; + +end; +$$ LANGUAGE plpgsql; diff --git a/onetime/wrappers/wrapper_IHTSLL.sql b/onetime/wrappers/wrapper_IHTSLL.sql new file mode 100755 index 0000000..9589805 --- /dev/null +++ b/onetime/wrappers/wrapper_IHTSLL.sql @@ -0,0 +1,20 @@ +drop function if exists staging2.fn_IHTSLL_RUN; +CREATE OR REPLACE FUNCTION staging2.fn_IHTSLL_RUN() + RETURNS void AS $$ + declare + f record; + w_file_syspk int; + status text; + begin + for f in select file_syspk from fw_core.fw_jobctl_file_runschedule + where end_status like 'stg1-completed' and file_mnemonic = 'IHTSLL' order by file_syspk + loop + select f.file_syspk into w_file_syspk; + perform fw_core.fn_get_function_exception('staging2.fn_IHTSLL_SLL_Block(20,1,''IHTSLL'',''IHTSLL_SLL'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='IHTSLL_SLL' order by error_timestamp desc into status; + if status = 'success' then +perform fw_core.fn_get_function_exception('staging2.fn_IHTSLL_SLL_TRX(20,1,''IHTSLL'',''IHTSLL_SLL'','||w_file_syspk||')'); end if; + end loop; + +end; +$$ LANGUAGE plpgsql; diff --git a/onetime/wrappers/wrapper_PTOBEN.sql b/onetime/wrappers/wrapper_PTOBEN.sql new file mode 100755 index 0000000..ca7426d --- /dev/null +++ b/onetime/wrappers/wrapper_PTOBEN.sql @@ -0,0 +1,40 @@ +drop function if exists staging2.fn_PTOBEN_RUN; +CREATE OR REPLACE FUNCTION staging2.fn_PTOBEN_RUN() + RETURNS void AS $$ + declare + f record; + w_file_syspk int; + status text; + begin + for f in select file_syspk from fw_core.fw_jobctl_file_runschedule + where end_status like 'stg1-completed' and file_mnemonic='PTOBEN' + loop + select f.file_syspk into w_file_syspk; + perform fw_core.fn_get_function_exception('staging2.fn_PTO_PRF_block(20,1,''PTOBEN'',''PTOBEN_PRFN'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='PTOBEN_PRFN' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_PTO_PRF_TRX(20,1,''PTOBEN'',''PTOBEN_PRFN'','||w_file_syspk||')'); + end if; + perform fw_core.fn_get_function_exception('staging2.fn_PTO_PRF_block(20,1,''PTOBEN'',''PTOBEN_PRFB'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='PTOBEN_PRFB' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_PTO_PRF_TRX(20,1,''PTOBEN'',''PTOBEN_PRFB'','||w_file_syspk||')'); + end if; + perform fw_core.fn_get_function_exception('staging2.fn_PTO_PRF_block(20,1,''PTOBEN'',''PTOBEN_PRFE'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='PTOBEN_PRFE' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_PTO_PRF_TRX(20,1,''PTOBEN'',''PTOBEN_PRFE'','||w_file_syspk||')'); + end if; + perform fw_core.fn_get_function_exception('staging2.fn_PTO_MPM_block(20,1,''PTOBEN'',''PTOBEN_MPM'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='PTOBEN_MPM' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_PTO_MPM_TRX(20,1,''PTOBEN'',''PTOBEN_MPM'','||w_file_syspk||')'); + end if; + perform fw_core.fn_get_function_exception('staging2.fn_PTO_GVG_block(20,1,''PTOBEN'',''PTOBEN_GVG'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='PTOBEN_GVG' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_PTO_GVG_TRX(20,1,''PTOBEN'',''PTOBEN_GVG'','||w_file_syspk||')'); + end if; + end loop; +end; +$$ LANGUAGE plpgsql; \ No newline at end of file diff --git a/onetime/wrappers/wrapper_PTOSTD.sql b/onetime/wrappers/wrapper_PTOSTD.sql new file mode 100755 index 0000000..a4e6a55 --- /dev/null +++ b/onetime/wrappers/wrapper_PTOSTD.sql @@ -0,0 +1,30 @@ +drop function if exists staging2.fn_PTOSTD_RUN; +CREATE OR REPLACE FUNCTION staging2.fn_PTOSTD_RUN() + RETURNS void AS $$ + declare + f record; + w_file_syspk int; + status text; + begin + for f in select file_syspk from fw_core.fw_jobctl_file_runschedule + where end_status like 'stg1-completed' and file_mnemonic='PTOSTD' + loop + select f.file_syspk into w_file_syspk; + perform fw_core.fn_get_function_exception('staging2.fn_PTO_PRF_block(20,1,''PTOSTD'',''PTOSTD_PRF'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='PTOSTD_PRF' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_PTO_PRF_TRX(20,1,''PTOSTD'',''PTOSTD_PRF'','||w_file_syspk||')'); + end if; + perform fw_core.fn_get_function_exception('staging2.fn_PTO_MPM_block(20,1,''PTOSTD'',''PTOSTD_MPM'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='PTOSTD_MPM' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_PTO_MPM_TRX(20,1,''PTOSTD'',''PTOSTD_MPM'','||w_file_syspk||')'); + end if; + perform fw_core.fn_get_function_exception('staging2.fn_PTO_GVG_block(20,1,''PTOSTD'',''PTOSTD_GVG'','||w_file_syspk||')'); + select e.status from fw_core.db_run_status e where file_syspk = w_file_syspk and file_sheet_mnemonic ='PTOSTD_GVG' order by error_timestamp desc into status; + if status = 'success' then + perform fw_core.fn_get_function_exception('staging2.fn_PTO_GVG_TRX(20,1,''PTOSTD'',''PTOSTD_GVG'','||w_file_syspk||')'); + end if; + end loop; +end; +$$ LANGUAGE plpgsql; \ No newline at end of file diff --git a/scripts/.run_onetime.sh.swm b/scripts/.run_onetime.sh.swm new file mode 100755 index 0000000..6591c89 Binary files /dev/null and b/scripts/.run_onetime.sh.swm differ diff --git a/scripts/.run_onetime.sh.swn b/scripts/.run_onetime.sh.swn new file mode 100755 index 0000000..2d9fa7b Binary files /dev/null and b/scripts/.run_onetime.sh.swn differ diff --git a/scripts/.run_onetime.sh.swo b/scripts/.run_onetime.sh.swo new file mode 100755 index 0000000..0b1fe5f Binary files /dev/null and b/scripts/.run_onetime.sh.swo differ diff --git a/scripts/.run_onetime.sh.swp b/scripts/.run_onetime.sh.swp new file mode 100755 index 0000000..0a9d802 Binary files /dev/null and b/scripts/.run_onetime.sh.swp differ diff --git a/scripts/.run_onetime_v2.sh.swp b/scripts/.run_onetime_v2.sh.swp new file mode 100755 index 0000000..d54bb44 Binary files /dev/null and b/scripts/.run_onetime_v2.sh.swp differ diff --git a/scripts/.run_wrapper_v2.sh.swp b/scripts/.run_wrapper_v2.sh.swp new file mode 100755 index 0000000..439cf8b Binary files /dev/null and b/scripts/.run_wrapper_v2.sh.swp differ diff --git a/scripts/check_duplicate_file.sh b/scripts/check_duplicate_file.sh new file mode 100755 index 0000000..2e538f6 --- /dev/null +++ b/scripts/check_duplicate_file.sh @@ -0,0 +1,50 @@ +#!/bin/bash -e + +HOME="/home/compegence/customer" +#Directories +homeDir=$HOME/MMT +configDir=$homeDir/conf +input_file=$configDir/etl-config.txt +declare -A credentials +while IFS="=" read -r key value; do + credentials[$key]=$value + done < <( sed -e '/^\s*$/ d' -e '/^#/ d' $input_file ) +#for i in ${credentials[@]}; do echo ***$i; done + +user=${credentials[user]} +password=${credentials[password]} +host=${credentials[host]} +db=${credentials[db]} +protocol=${credentials[protocol]} +server=${credentials[server]} + +postgres_con="psql -A -t postgresql://$user:$password@$host/$db" + +count=`$postgres_con -c "select count(*) from fw_core.fw_jobctl_file_runschedule"` +if [[ $count -eq 0 ]] +then + $postgres_con -q -c "update fw_core.fw_jobctl_runschedule_jobstep set end_status_note ='no_duplicate_file_found', end_status='success',end_time = now() where job_script_type = 'shell_script' and job_id = 1 and step_id= 1 and latest_runschedule_flag='1'" +else + while IFS= read -a filenames + do + file_name=$(echo $filenames | sed 's/[[:space:]]/\\ /g') + if [ $(echo "-f $homeDir/files/landing/$file_name") ]; + then + echo "File: $file_name is already processed and is moved to Duplicate Folder" + move=$(echo "mv $homeDir/files/landing/$file_name $homeDir/files/duplicate_file/$file_name") + eval $move + + #update ctl table to exit for duplicate files + $postgres_con -q -c "update fw_core.fw_jobctl_runschedule_jobstep set end_status_note ='duplicate_file_found', end_status='success',end_time = now() where job_script_type = 'shell_script' and job_id = 1 and step_id= 1 and latest_runschedule_flag='1'" + else + $postgres_con -q -c "update fw_core.fw_jobctl_runschedule_jobstep set end_status_note = 'no_duplicate_file_found', end_status='success',end_time = now() where job_script_type = 'shell_script' and job_id = 1 and step_id= 1 and latest_runschedule_flag='1'" + fi +done < <($postgres_con -c "select file_name from fw_core.fw_jobctl_file_runschedule where end_status_note='TRX_completed' and end_status ='success'") +fi + + + +#$postgres_con -c "insert into fw_core.track_jobstep select *,'duplicate_check' from fw_core.fw_jobctl_runschedule_jobstep;" +#$postgres_con -c "insert into fw_core.track_file select *,'duplicate_check' from fw_core.fw_jobctl_file_runschedule;" +#$postgres_con -c "insert into fw_core.track_file_sheet select *,'duplicate_check' from fw_core.fw_jobctl_file_sheet_runschedule;" + diff --git a/scripts/file_move.sh b/scripts/file_move.sh new file mode 100755 index 0000000..1d0c9c3 --- /dev/null +++ b/scripts/file_move.sh @@ -0,0 +1,61 @@ +#!/bin/bash -e +HOME="/home/compegence/customer" +#Directories +homeDir=$HOME/MMT +configDir=$homeDir/conf +input_file=$configDir/etl-config.txt +declare -A credentials +while IFS="=" read -r key value; do + credentials[$key]=$value + done < <( sed -e '/^\s*$/ d' -e '/^#/ d' $input_file ) + + +user=${credentials[user]} +password=${credentials[password]} +host=${credentials[host]} +db=${credentials[db]} +protocol=${credentials[protocol]} +server=${credentials[server]} + +postgres_con="psql -A -t postgresql://$user:$password@$host/$db" + +filesyspks=`$postgres_con -q -c "select file_syspk from fw_core.fw_jobctl_file_runschedule where latest_runschedule_flag='1' /*and end_status_note='TRX_completed'*/;"` + +for filesyspk in ${filesyspks} +do + IFS="|" read name endstatus endnote <<<`$postgres_con -c "select file_name,end_status,end_status_note from fw_core.fw_jobctl_file_runschedule where file_syspk=$filesyspk"` + filename=$(echo $name | sed 's/[[:space:]]/\\ /g') + if [ $endstatus == "success" -a $endnote == 'TRX_completed' ] + then + echo " moving file:$filename to processed folder" + move=$(echo "mv $homeDir/files/landing/$filename $homeDir/files/processed/$filename") + eval $move + + else + echo "moving file: $filename to error_file folder " + move=$(echo "mv $homeDir/files/landing/$filename $homeDir/files/error_file/$filename") + eval $move + fi + +$postgres_con -q -c "update fw_core.fw_jobctl_runschedule_jobstep set end_status_note ='file_movement_completed', end_status='success',end_time = now() where job_script_type = 'shell_script' and latest_runschedule_flag='1' and job_name= 'file_cleanup'" + +echo -e ' ' +done + +#$postgres_con -c "insert into fw_core.track_jobstep select *,'move_check' from fw_core.fw_jobctl_runschedule_jobstep;" +#$postgres_con -c "insert into fw_core.track_file select *,'move_check' from fw_core.fw_jobctl_file_runschedule;" +#$postgres_con -c "insert into fw_core.track_file_sheet select *,'move_check' from fw_core.fw_jobctl_file_sheet_runschedule;" + + + + + + + + + + + + + + diff --git a/scripts/job_load.sh b/scripts/job_load.sh new file mode 100755 index 0000000..6498127 --- /dev/null +++ b/scripts/job_load.sh @@ -0,0 +1,93 @@ +#!/bin/bash -e + +#!/bin/bash -e +HOME="/home/compegence/customer" +#Directories +homeDir=$HOME/MMT +configDir=$homeDir/conf +input_file=$configDir/etl-config.txt +declare -A credentials +while IFS="=" read -r key value; do + credentials[$key]=$value + done < <( sed -e '/^\s*$/ d' -e '/^#/ d' $input_file ) + + +user=${credentials[user]} +password=${credentials[password]} +host=${credentials[host]} +db=${credentials[db]} +protocol=${credentials[protocol]} +server=${credentials[server]} + + + +#let i=0 +#set -A arr +#BASE_CODS_ARGUMENTS="--host=$cods_host --user=$cods_user --password=$cods_pwd --port=$3306" +#BASE_ODS_ARGUMENTS="--user=$user --password=$pwd --host=$host" +psql_base_arg="postgresql://$user:$password@$host/$db" +#psql_base_arg="postgresql://postgres:j3(jLBq}e@localhost/ffm_k2" +#echo $psql_base_arg + +ifStart=`date '+%d'` +#echo "$ifStart" + + +#Check today is sunday. Scheduling weekly job +today="$(date +%a)" +sun="Mon" + + psql $psql_base_arg -q -c "update fw_core.fw_jobctl_runschedule set latest_runschedule_flag='0' where latest_runschedule_flag='1';" + psql $psql_base_arg -q -c "update fw_core.fw_jobctl_runschedule_jobstep set latest_runschedule_flag='0' where latest_runschedule_flag='1';" + psql $psql_base_arg -q -c "update fw_core.fw_jobctl_file_runschedule set latest_runschedule_flag='0' where latest_runschedule_flag='1';" + psql $psql_base_arg -q -c "update fw_core.fw_jobctl_file_sheet_runschedule set latest_runschedule_flag='0' where latest_runschedule_flag='1';" + +#inserting into fw_core.fw_jobctl_runschedule +chkrun=$(psql $psql_base_arg -t -c "select count(*) from fw_core.fw_jobctl_jobstep_master where client_id=21 and function_id=1 and run_frequency='daily' and active_flag=true;") +if [[ $chkrun -gt 0 ]]; then + psql $psql_base_arg -q -c "INSERT INTO fw_core.fw_jobctl_runschedule +(client_id, function_id, run_schedule_timestamp, run_frequency, start_time, begin_status, created_by, updated_by, create_timestamp, update_timestamp) +select client_id, function_id,now(),run_frequency,now(),'','Admin','Admin',now(),now() from fw_core.fw_jobctl_jobstep_master +where active_flag='TRUE' group by client_id, function_id, run_frequency limit 1;" + +#check previous day job status in fw_jobctl_runschedule +chkrun2=$(psql $psql_base_arg -t -c "select trim(end_status) from fw_core.fw_jobctl_runschedule where run_schedule_id = ( + select max(run_schedule_id) as max from fw_core.fw_jobctl_runschedule where latest_runschedule_flag='0' and client_id=21 and function_id=1);") + + if [ "$chkrun2" != " error" ]; then + +#Update fw_jobctl_runschedule + psql $psql_base_arg -q -c "update fw_core.fw_jobctl_runschedule set begin_status='started' where client_id=21 and function_id=1 and run_frequency='daily' and latest_runschedule_flag='1' " + else + psql $psql_base_arg -q -c "update fw_core.fw_jobctl_runschedule set begin_status='started',end_status='error',end_status_note = 'previous day job failed' where client_id=21 and function_id=1 and run_frequency='daily' and latest_runschedule_flag='1' " + echo "welcome2" + exit 1; + fi +else + echo " No active job for daily for client_id=21" + exit 1; +fi + +# looping fw_jobctl_jobstep_master for active records +while IFS="|" read -a line +do + run_frequency=${line[2]} + job_scheduling_day="${line[1]}" + +#echo "$run_frequency" +if [ $run_frequency == "daily" ] ; then + echo "Populating daily job into fw_jobctl_runschedule_jobstep" + + psql $psql_base_arg -q -c"insert into fw_core.fw_jobctl_runschedule_jobstep(client_id, function_id,latest_runschedule_flag,run_schedule_id,run_schedule_timestamp, run_frequency, job_id, step_id, job_step_run_dependency_seuqence, +job_script_type,job_step_script_name,job_fun_param_array,job_name, step_name, job_scope, job_scope_qualifier_array, created_by,updated_by, create_timestamp, update_timestamp) +select a.client_id, a.function_id,b.latest_runschedule_flag, b.run_schedule_id,b.run_schedule_timestamp,a.run_frequency, a.job_id, a.step_id, a.job_step_run_dependency_seuqence, +a.job_script_type,a.job_step_script_name,a.job_fun_param_array,a.job_name,a.step_name,a.job_scope, a.job_scope_qualifier_array, 'Admin','Admin',now(),now() +from fw_core.fw_jobctl_jobstep_master a join fw_core.fw_jobctl_runschedule b +on a.client_id=b.client_id and a.function_id=b.function_id and a.run_frequency=b.run_frequency +where latest_runschedule_flag='1' and b.begin_status = 'started' and b.end_status is null and a.active_flag='true' and a.run_frequency='daily' +order by a.client_id,a.function_id,a.job_id,a.step_id,a.job_step_run_dependency_seuqence;" + +fi +done < <(psql $psql_base_arg -At -c"select distinct client_id,function_id,run_frequency from fw_core.fw_jobctl_jobstep_master order by run_frequency ") + + diff --git a/scripts/run_onetime_compile.sh b/scripts/run_onetime_compile.sh new file mode 100755 index 0000000..a1b3f0a --- /dev/null +++ b/scripts/run_onetime_compile.sh @@ -0,0 +1,48 @@ +#!/bin/bash -e +HOME="/home/compegence/customer" +#Directories +homeDir=$HOME/MMT +configDir=$homeDir/conf +input_file=$configDir/etl-config.txt +declare -A credentials +while IFS="=" read -r key value; do + credentials[$key]=$value + done < <( sed -e '/^\s*$/ d' -e '/^#/ d' $input_file ) +#for i in ${credentials[@]}; do echo ***$i; done + +user=${credentials[user]} +password=${credentials[password]} +host=${credentials[host]} +db=${credentials[db]} +protocol=${credentials[protocol]} +server=${credentials[server]} + +mmt_con="psql -X -q -A -t postgresql://$user:$password@$host/$db?options=--search_path%3D" + +declare -a archivepathvar=("$homeDir/sql/onetime/archive/schema") + +declare -a archivepathsvar=("$homeDir/sql/onetime/archive/create" "$homeDir/sql/onetime/archive/function") + +declare -a trxpathvar=("$homeDir/sql/onetime/createtables/common" "$homeDir/sql/onetime/createtables/ods" "$homeDir/sql/onetime/createtables/control" "$homeDir/sql/onetime/commonfunctions" "$homeDir/sql/onetime/configentries" "$homeDir/sql/onetime/dataloadfunctions/ODS_Load") + +declare -a stgpathvar=("$homeDir/sql/onetime/createtables/staging" "$homeDir/sql/onetime/dataloadfunctions/budni" "$homeDir/sql/onetime/dataloadfunctions/Drawbar" "$homeDir/sql/onetime/dataloadfunctions/IHT" "$homeDir/sql/onetime/dataloadfunctions/field" "$homeDir/sql/onetime/dataloadfunctions/PTO" "$homeDir/sql/onetime/wrappers") + +func_execute_conn(){ + local conn="$1" + local -n param=$2 + for path in "${param[@]}" + do + for files in "$path"/* + do + $conn -f $files + done + done +} + +func_execute_conn "$mmt_con'archive'" archivepathvar + +func_execute_conn "$mmt_con'staging2'" stgpathvar + +func_execute_conn "$mmt_con'trx'" trxpathvar + +func_execute_conn "$mmt_con'archive'" archivepathsvar diff --git a/scripts/run_schedule.sh b/scripts/run_schedule.sh new file mode 100755 index 0000000..b14e557 --- /dev/null +++ b/scripts/run_schedule.sh @@ -0,0 +1,149 @@ +#!/bin/bash -e +HOME="/home/compegence/customer" +#Directories +homeDir=$HOME/MMT +configDir=$homeDir/conf +input_file=$configDir/etl-config.txt +declare -A credentials +while IFS="=" read -r key value; do + credentials[$key]=$value + done < <( sed -e '/^\s*$/ d' -e '/^#/ d' $input_file ) + + +user=${credentials[user]} +password=${credentials[password]} +host=${credentials[host]} +db=${credentials[db]} +protocol=${credentials[protocol]} +server=${credentials[server]} + + + +psql_base_arg="postgresql://$user:$password@$host/$db" + +# load the record into the fw_jobctl_runschedule accounting for run frequency (hourly, daily, monthly, yearly) and insert + /home/compegence/customer/MMT/sql/scripts/job_load.sh + +##***** Run frequency loop; Outer Loop +#while loop for each client_id,function_id,run_frequency from fw_jobctl_runschedule_jobstep + +while IFS="|" read -a outer +do + client_id=${outer[0]} + function_id=${outer[1]} + run_frequency=${outer[2]} + +#Update start_time for fw_jobctl_runschedule + #psql $psql_base_arg -q -c "update fw_core.fw_jobctl_runschedule set start_time=now(),begin_status='started' where latest_runschedule_flag='1' and client_id=$client_id and function_id=$function_id and run_frequency='$run_frequency' and end_status is null " + +##** Job and Step Loop; innner loop; +#while loop for each job & step +##** Job and Step Loop; innner loop; based on the entries on the table fw_jobctl_runschedule_jobstep + + job_status=0 + prev_job_seq='' + file_count=0 + while IFS="|" read -a inner + do + client_id=${inner[0]} + function_id=${inner[1]} + run_frequency=${inner[2]} + job_id=${inner[4]} + step_id=${inner[5]} + job_name=${inner[6]} + #step_name=(${inner[7]}) + job_script_type=${inner[8]} + job_step_script_name=${inner[9]} + #remove first and last char - curly braces + job_fun_param_array=${inner[10]:1:-1} + job_step_run_dependency_seuqence=${inner[11]} + + param='' + var1=' ' + job_step_script_name_concat=$job_step_script_name'('$client_id,$function_id,$job_id,$step_id')' + + #reading array column and spliting each var and appending $ & space + IFS=',' read -r -a ADDR <<< "$job_fun_param" + for i in "${ADDR[@]}"; do + param=$param$i$var1 + done + + + +##get file count + file_count=$(psql $psql_base_arg -t -c "select object_count from fw_core.fw_jobctl_runschedule where latest_runschedule_flag='1';") + echo "file-count is $file_count" + +echo "Executing Job: $job_name by checking Previous End Status" +## Process java Program + if [[ $job_script_type == "java" ]]; then + psql $psql_base_arg -t -q -c "update fw_core.fw_jobctl_runschedule_jobstep set start_time=now(),begin_status='started' where job_step_script_name='$job_step_script_name' and client_id=$client_id and function_id=$function_id and run_frequency='$run_frequency' and latest_runschedule_flag='1' " + if [[ $prev_job_seq == '' ]]; then + java -jar $job_step_script_name + else + chkrun=$(psql $psql_base_arg -t -c "select TRIM(end_status) from fw_core.fw_jobctl_runschedule_jobstep where latest_runschedule_flag='1' and job_step_run_dependency_seuqence=$prev_job_seq and client_id=21 and function_id=1;") + if [[ "$chkrun" == " success" ]]; then + java -jar $job_step_script_name + else + exit 1; + fi + fi + +## Process sql files + elif [[ $job_script_type == "sql" ]] ; then + psql $psql_base_arg -t -q -c "update fw_core.fw_jobctl_runschedule_jobstep set start_time=now(),begin_status='started' where job_step_script_name='$job_step_script_name' and client_id=$client_id and function_id=$function_id and run_frequency='$run_frequency' and latest_runschedule_flag='1' " + if [[ $prev_job_seq == '' ]]; then + psql $psql_base_arg -a -f $job_step_script_name $host $port $user $pwd $dbname $param $client_id $function_id $data_from_date $data_to_date $job_scope $job_scope_qualifier + else + chkrun=$(psql $psql_base_arg -t -c "select TRIM(end_status) from fw_core.fw_jobctl_runschedule_jobstep where latest_runschedule_flag='1' and job_step_run_dependency_seuqence=$prev_job_seq and client_id=21 and function_id=1;") + if [[ $file_count -gt 0 ]]; then + psql $psql_base_arg -a -f $job_step_script_name $host $port $user $pwd $dbname $param $client_id $function_id $data_from_date $data_to_date $job_scope $job_scope_qualifier + else + exit 1; + fi + fi + +## Process shell_script Program + elif [[ $job_script_type == "shell_script" ]] ; then + psql $psql_base_arg -t -q -c "update fw_core.fw_jobctl_runschedule_jobstep set start_time=now(),begin_status='started' where job_step_script_name='$job_step_script_name' and client_id=$client_id and function_id=$function_id and run_frequency='$run_frequency' and latest_runschedule_flag='1' " + if [[ $prev_job_seq == '' ]]; then + $job_step_script_name + else + chkrun=$(psql $psql_base_arg -t -c "select TRIM(end_status) from fw_core.fw_jobctl_runschedule_jobstep where latest_runschedule_flag='1' and job_step_run_dependency_seuqence=$prev_job_seq and client_id=21 and function_id=1;") + + if [[ $file_count -gt 0 ]]; then + $job_step_script_name + else + exit 1; + fi + fi + +## Process sql fn Program + elif [[ $job_script_type == "sql_fn" ]] ; then + psql $psql_base_arg -t -q -c "update fw_core.fw_jobctl_runschedule_jobstep set start_time=now(),begin_status='started' where job_step_script_name='$job_step_script_name' and client_id=$client_id and function_id=$function_id and run_frequency='$run_frequency' and latest_runschedule_flag='1' " + if [[ $prev_job_seq == '' ]]; then + psql $psql_base_arg -c "select $job_step_script_name_concat" + else + + chkrun=$(psql $psql_base_arg -t -c "select TRIM(end_status) from fw_core.fw_jobctl_runschedule_jobstep where latest_runschedule_flag='1' and job_step_run_dependency_seuqence=$prev_job_seq and client_id=21 and function_id=1;") + if [[ $file_count -gt 0 ]]; then + psql $psql_base_arg -t -c "select $job_step_script_name_concat" + else + exit 1; + fi + fi + fi + +prev_job_seq=$job_step_run_dependency_seuqence +## End of While Loop +#2nd looping through fw_core.fw_jobctl_runschedule_jobstep for each client_id,function_id,run_frequency,run_schedule_id1 is completed +done < <(psql $psql_base_arg -At -c"select client_id,function_id,run_frequency,run_schedule_id,job_id,step_id,job_name,step_name,job_script_type,job_step_script_name,job_fun_param_array,job_step_run_dependency_seuqence from fw_core.fw_jobctl_runschedule_jobstep where latest_runschedule_flag='1' and client_id=$client_id and function_id=$function_id and run_frequency='$run_frequency' order by client_id,function_id,run_schedule_id,job_id,step_id,job_step_run_dependency_seuqence; ") + + +#Update end_time for fw_jobctl_runschedule + psql $psql_base_arg -q -c "update fw_core.fw_jobctl_runschedule set end_status='success',end_status_note='run_completed' ,latest_runschedule_flag='0',end_time=now() where client_id=$client_id and function_id=$function_id and run_frequency='$run_frequency' and latest_runschedule_flag='1' " + +#1st loop for client_id,function_id,run_frequency +done < <(psql $psql_base_arg -At -c"select distinct client_id,function_id,run_frequency from fw_core.fw_jobctl_runschedule_jobstep where latest_runschedule_flag='1' order by client_id,function_id,run_frequency ") + +