latest_mmt_version
This commit is contained in:
@@ -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$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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$
|
||||
;
|
||||
|
||||
|
||||
|
||||
@@ -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$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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$
|
||||
;
|
||||
|
||||
|
||||
|
||||
@@ -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$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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$
|
||||
;
|
||||
|
||||
|
||||
|
||||
@@ -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$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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$
|
||||
;
|
||||
|
||||
|
||||
|
||||
@@ -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$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user