folder name changed

This commit is contained in:
Deepthi
2021-04-27 16:41:49 +05:30
parent c8985b2d62
commit 559fa36e6a
71 changed files with 0 additions and 0 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,351 @@
drop function if exists mmt_staging2.fn_PTO_GVG_block;
CREATE OR REPLACE FUNCTION mmt_staging2.fn_PTO_GVG_block(p_client_id int,p_function_id int, p_file_format text,
p_sheet_mnemonic text, p_file_syspk int)
RETURNS void AS $$
declare __make text;
declare __model text;
declare __client_id int :=p_client_id;
declare __function_id int :=p_function_id;
declare __file_format text :=p_file_format;
declare __sheet_mnemonic text :=p_sheet_mnemonic;
declare __file_syspk int :=p_file_syspk;
begin
/**************************************************************************************
Function Name:fn_PTO_GVG_block
Function Desc: This function populates data into staging2 blocks
File Format: PTOBST
Sheet Format: PTOBST_GVG
Creation Date: March 25 2021
Updation Date:
Author: compegence team
Function Call: select mmt_staging2.fn_PTO_GVG_block(1,1,'PTOBST','PTOBST_GVG',255)
***************************************************************************************/
SET search_path TO mmt_staging2;
/* rerunnability - delete block tables and update config tables to null */
truncate table mmt_staging2.stg_specific_table_PTO_GVG;
truncate table mmt_staging2.stg_process_table_PTO_GVG;
truncate table mmt_staging2.PTOBST_GVG_performance_governing_trails_block;
execute 'delete from mmt_ods.fw_jobctrl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=null,
row_previous_number=null,
row_read_end=null,
run_time=null
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* transfer data from generic to specific for PTOBST */
execute 'insert into mmt_staging2.stg_specific_table_PTO_GVG
select * from mmt_staging1.mmt_staging_generic_table a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.file_syspk='||p_file_syspk||'';
/* trimming data */
update mmt_staging2.stg_specific_table_PTO_GVG set column3 = TRIM (TRAILING FROM column3 );
update mmt_staging2.stg_specific_table_PTO_GVG set column3 = TRIM (LEADING FROM column3 );
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified) ;
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified) ;
update mmt_ods.mmt_config set F1_source=F1_modified ;
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source);
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source);
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_staging2.stg_specific_table_PTO_GVG b
where trim(upper(F1_modified))=trim(upper(column2))
and b.is_rownumber_fetched is null)
where a.row_number_start is null
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* keyword match in config table*/
execute 'update mmt_staging2.stg_specific_table_PTO_GVG a
set is_rownumber_fetched=1
from mmt_ods.mmt_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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_read_end= (select b.row_number_start
from mmt_ods.mmt_config b
where b.syspk=a.syspk+1 and file_format='''||p_file_format||''' and sheet_mnemonic='''||p_sheet_mnemonic||''' )
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* config file last field update as null otherwise it picks up next format row number*/
execute 'update mmt_ods.mmt_config a
set row_read_end = null ,run_time=current_timestamp
where f1_modified =''Graphs - for Example''
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* tagging ranks*/
execute 'insert into mmt_staging2.stg_process_table_PTO_GVG
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_PTO_GVG a
join mmt_ods.mmt_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=''Governing Trails on Boost Mode''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'insert into mmt_staging2.stg_process_table_PTO_GVG
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_PTO_GVG a
join mmt_ods.mmt_config b
on a.row_number >=row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Graphs - for Example''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
select column3 into __make from mmt_staging2.stg_process_table_PTO_report a
where rank_tag='PTOBST_RPT_test_tractor_specifiactions' and rank=3 ;
select column4 into __model from mmt_staging2.stg_process_table_PTO_report a
where rank_tag='PTOBST_RPT_test_tractor_specifiactions' and rank=3;
/* block PTOBST_GVG_performance_governing_trails_block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'PTOBST_GVG_performance_governing_trails_block',__file_format,__sheet_mnemonic,1);
insert into mmt_staging2.PTOBST_GVG_performance_governing_trails_block
(
c2,
c3,
c4,
c5,
c6,
c7,
c8,
c9,
c10,
c11,
c12,
c13,
c14,
c15,
c16,
c17,
c18,
c19,
c20,
c21,
c22,
c23,
c24,
c25,
c26,
c27,
c28,
c29,
c30,
c31,
c32,
c33,
c34,
c35,
c36,
rank
)
select column2,
column3,
column4,
column5,
column6,
column7,
column8,
column9,
column10,
column11,
column12,
column13,
column14,
column15,
column16,
column17,
column18,
column19,
column20,
column21,
column22,
column23,
column24,
column25,
column26,
column27,
column28,
column29,
column30,
column31,
column32,
column33,
column34,
column35,
column36,
rank
from mmt_staging2.stg_process_table_PTO_GVG a
where rank_tag='PTOBST_GVG_performance_governing_trails';
update mmt_staging2.PTOBST_GVG_performance_governing_trails_block
set test_condition=c2
where rank=1;
update mmt_staging2.PTOBST_GVG_performance_governing_trails_block
set c2=null
where rank=1;
update mmt_staging2.PTOBST_GVG_performance_governing_trails_block a
set test_condition= b.first_value from (SELECT
rank, test_condition, value_partition, first_value(test_condition) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
test_condition,
sum(case when test_condition is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.PTOBST_GVG_performance_governing_trails_block
ORDER BY rank ASC
) as q) b where a.rank = b.rank ;
update mmt_staging2.PTOBST_GVG_performance_governing_trails_block
set c1=c2 where rank=4;
update mmt_staging2.PTOBST_GVG_performance_governing_trails_block a
set c1= b.first_value from (SELECT
rank, c1, value_partition, first_value(c1) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
c1,
sum(case when c1 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.PTOBST_GVG_performance_governing_trails_block
ORDER BY rank ASC
) as q) b where a.rank = b.rank ;
update mmt_staging2.PTOBST_GVG_performance_governing_trails_block
set c7_1=c7 where rank=4;
update mmt_staging2.PTOBST_GVG_performance_governing_trails_block a
set c7_1= b.first_value from (SELECT
rank, c7_1, value_partition, first_value(c7_1) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
c7_1,
sum(case when c7_1 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.PTOBST_GVG_performance_governing_trails_block
ORDER BY rank ASC
) as q) b where a.rank = b.rank ;
update mmt_staging2.PTOBST_GVG_performance_governing_trails_block
set c12_1=c12 where rank=4;
update mmt_staging2.PTOBST_GVG_performance_governing_trails_block a
set c12_1= b.first_value from (SELECT
rank, c12_1, value_partition, first_value(c12_1) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
c12_1,
sum(case when c12_1 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.PTOBST_GVG_performance_governing_trails_block
ORDER BY rank ASC
) as q) b where a.rank = b.rank ;
update mmt_staging2.PTOBST_GVG_performance_governing_trails_block
set c17_1=c17 where rank=4;
update mmt_staging2.PTOBST_GVG_performance_governing_trails_block a
set c17_1= b.first_value from (SELECT
rank, c17_1, value_partition, first_value(c17_1) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
c17_1,
sum(case when c17_1 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.PTOBST_GVG_performance_governing_trails_block
ORDER BY rank ASC
) as q) b where a.rank = b.rank ;
update mmt_staging2.PTOBST_GVG_performance_governing_trails_block
set c22_1=c22 where rank=4;
update mmt_staging2.PTOBST_GVG_performance_governing_trails_block a
set c22_1= b.first_value from (SELECT
rank, c22_1, value_partition, first_value(c22_1) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
c22_1,
sum(case when c22_1 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.PTOBST_GVG_performance_governing_trails_block
ORDER BY rank ASC
) as q) b where a.rank = b.rank ;
update mmt_staging2.PTOBST_GVG_performance_governing_trails_block
set c27_1=c27 where rank=4;
update mmt_staging2.PTOBST_GVG_performance_governing_trails_block a
set c27_1= b.first_value from (SELECT
rank, c27_1, value_partition, first_value(c27_1) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
c27_1,
sum(case when c27_1 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.PTOBST_GVG_performance_governing_trails_block
ORDER BY rank ASC
) as q) b where a.rank = b.rank ;
update mmt_staging2.PTOBST_GVG_performance_governing_trails_block
set c32_1=c32 where rank=4;
update mmt_staging2.PTOBST_GVG_performance_governing_trails_block a
set c32_1= b.first_value from (SELECT
rank, c32_1, value_partition, first_value(c32_1) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
c32_1,
sum(case when c32_1 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.PTOBST_GVG_performance_governing_trails_block
ORDER BY rank ASC
) as q) b where a.rank = b.rank ;
update mmt_staging2.PTOBST_GVG_performance_governing_trails_block
set ods_record=0 where rank in (1,2,3,4);
execute 'update mmt_staging2.PTOBST_GVG_performance_governing_trails_block set client_id='||p_client_id||'';
execute 'update mmt_staging2.PTOBST_GVG_performance_governing_trails_block set function_id='||p_function_id||'';
execute 'update mmt_staging2.PTOBST_GVG_performance_governing_trails_block set file_format='''||p_file_format||'''';
execute 'update mmt_staging2.PTOBST_GVG_performance_governing_trails_block set sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_staging2.PTOBST_GVG_performance_governing_trails_block set file_syspk='||p_file_syspk||'';
update mmt_staging2.PTOBST_GVG_performance_governing_trails_block set make=__make;
update mmt_staging2.PTOBST_GVG_performance_governing_trails_block set model=__model;
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'PTOBST_GVG_performance_governing_trails_block');
end
$$ LANGUAGE plpgsql;

View File

@@ -0,0 +1,168 @@
drop function if exists mmt_staging2.fn_PTO_MPM_block;
CREATE OR REPLACE FUNCTION mmt_staging2.fn_PTO_MPM_block(p_client_id int,p_function_id int, p_file_format text,p_sheet_mnemonic text, p_file_syspk int)
RETURNS void AS $$
declare __make text;
declare __model text;
declare __client_id int :=p_client_id;
declare __function_id int :=p_function_id;
declare __file_format text :=p_file_format;
declare __sheet_mnemonic text :=p_sheet_mnemonic;
declare __file_syspk int :=p_file_syspk;
begin
/**************************************************************************************
Function Name:fn_PTO_MPM_block
Function Desc: This function populates data into staging2 blocks
File Format: PTOBST
Sheet Format: PTOBST_MPM
Creation Date: March 21 2021
Updation Date:
Author: compegence team
Function Call: select mmt_staging2.fn_PTO_MPM_block(1,1,'PTOBST','PTOBST_MPM',255)
***************************************************************************************/
SET search_path TO mmt_staging2;
/* rerunnability - delete block tables and update config tables to null */
truncate table mmt_staging2.stg_specific_table_PTO_MPM;
truncate table mmt_staging2.stg_process_table_PTO_MPM;
truncate table mmt_staging2.PTOBST_MPM_performance_boost_natuaral_block;
execute 'delete from mmt_ods.fw_jobctrl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=null,
row_previous_number=null,
row_read_end=null,
run_time=null
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* transfer data from generic to specific for PTOBST */
execute 'insert into mmt_staging2.stg_specific_table_PTO_MPM
select * from mmt_staging1.mmt_staging_generic_table a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.file_syspk='||p_file_syspk||'';
/* trimming data */
update mmt_staging2.stg_specific_table_PTO_MPM set column3 = TRIM (TRAILING FROM column3 );
update mmt_staging2.stg_specific_table_PTO_MPM set column3 = TRIM (LEADING FROM column3 );
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified) ;
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified) ;
update mmt_ods.mmt_config set F1_source=F1_modified ;
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source);
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source);
/* keyword match in config table*/
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_staging2.stg_specific_table_PTO_MPM b
where trim(upper(F1_modified))=trim(upper(column2))
and b.is_rownumber_fetched is null)
where a.row_number_start is null
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* reverese update*/
execute 'update mmt_staging2.stg_specific_table_PTO_MPM a
set is_rownumber_fetched=1
from mmt_ods.mmt_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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_read_end= (select b.row_number_start
from mmt_ods.mmt_config b
where b.syspk=a.syspk+1 and file_format='''||p_file_format||''' and sheet_mnemonic='''||p_sheet_mnemonic||''' )
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* config file last field update as null otherwise it picks up next format row number*/
execute 'update mmt_ods.mmt_config a
set row_read_end = null ,run_time=current_timestamp
where f1_modified =''Performance - Boost Mode @ Natural Ambient''
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* tagging ranks*/
execute 'insert into mmt_staging2.stg_process_table_PTO_MPM
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_PTO_MPM a
join mmt_ods.mmt_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=''Performance - Boost Mode @ Natural Ambient''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
select column3 into __make from mmt_staging2.stg_process_table_PTO_report a
where rank_tag='PTOBST_RPT_test_tractor_specifiactions' and rank=3 ;
select column4 into __model from mmt_staging2.stg_process_table_PTO_report a
where rank_tag='PTOBST_RPT_test_tractor_specifiactions' and rank=3;
/* block - PTOBST_MPM_performance_boost_natuaral_block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'PTOBST_MPM_performance_boost_natuaral_block',__file_format,__sheet_mnemonic,1);
insert into mmt_staging2.PTOBST_MPM_performance_boost_natuaral_block
(
c2,
c3,
c4,
c5,
rank
)
select column2,column3,column4 ,column5,rank from mmt_staging2.stg_process_table_PTO_MPM
where rank_tag='PTOBST_MPM_performance_boost_natuaral';
update mmt_staging2.PTOBST_MPM_performance_boost_natuaral_block
set test_condition=c2
where rank=1;
update mmt_staging2.PTOBST_MPM_performance_boost_natuaral_block
set c2=null
where rank=1;
update mmt_staging2.PTOBST_MPM_performance_boost_natuaral_block a
set test_condition= b.first_value from (SELECT
rank, test_condition, value_partition, first_value(test_condition) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
test_condition,
sum(case when test_condition is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.PTOBST_MPM_performance_boost_natuaral_block
ORDER BY rank ASC
) as q) b where a.rank = b.rank ;
update mmt_staging2.PTOBST_MPM_performance_boost_natuaral_block
set ods_record=0
where rank in (1,2);
execute 'update mmt_staging2.PTOBST_MPM_performance_boost_natuaral_block set client_id='||p_client_id||'';
execute 'update mmt_staging2.PTOBST_MPM_performance_boost_natuaral_block set function_id='||p_function_id||'';
execute 'update mmt_staging2.PTOBST_MPM_performance_boost_natuaral_block set file_format='''||p_file_format||'''';
execute 'update mmt_staging2.PTOBST_MPM_performance_boost_natuaral_block set sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_staging2.PTOBST_MPM_performance_boost_natuaral_block set file_syspk='||p_file_syspk||'';
update mmt_staging2.PTOBST_MPM_performance_boost_natuaral_block set make=__make;
update mmt_staging2.PTOBST_MPM_performance_boost_natuaral_block set model=__model;
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'PTOBST_MPM_performance_boost_natuaral_block');
end
$$ LANGUAGE plpgsql;

View File

@@ -0,0 +1,457 @@
/*
select mmt_staging2.fn_PTO_PHA_block(1,1,'PTOBST','PTOBST_PHA',183)
select * from mmt_ods.mmt_config where file_format='PTOBST' and sheet_mnemonic ='PTOBST_PHA' order by syspk
select * from mmt_staging1.mmt_staging_generic_table where file_format='PTOBST' and sheet_mnemonic ='PTOBST_PHA'
*/
drop function if exists mmt_staging2.fn_PTO_PHA_block;
CREATE OR REPLACE FUNCTION mmt_staging2.fn_PTO_PHA_block(p_client_id int,p_function_id int, p_file_format text,
p_sheet_mnemonic text, p_file_syspk int)
RETURNS void AS $$
declare __make text;
declare __model text;
declare __client_id int :=p_client_id;
declare __function_id int :=p_function_id;
declare __file_format text :=p_file_format;
declare __sheet_mnemonic text :=p_sheet_mnemonic;
declare __file_syspk int :=p_file_syspk;
begin
/**************************************************************************************
Function Name:fn_PTO_PHA_block
Function Desc: This function populates data into staging2 blocks
File Format: PTOBST
Sheet Format: PTOBST_PHA
Creation Date: March 21 2021
Updation Date:
Author: compegence team
Function Call: select mmt_staging2.fn_PTO_PHA_block(1,1,'PTOBST','PTOBST_PHA',255)
***************************************************************************************/
SET search_path TO mmt_staging2;
/* rerunnability - delete block tables and update config tables to null */
truncate table mmt_staging2.stg_specific_table_PTO_PHA;
truncate table mmt_staging2.stg_process_table_PTO_PHA;
truncate table mmt_staging2.PTOBST_PHA_key_perfomrance_parameters_int;
truncate table mmt_staging2.PTOBST_PHA_key_perfomrance_parameters_block;
truncate table mmt_staging2.PTOBST_PHA_2Hrs_max_power_test_block;
truncate table mmt_staging2.PTOBST_PHA_varying_speed_test_block;
truncate table mmt_staging2.PTOBST_PHA_Engine_oil_consumption_block;
execute 'delete from mmt_ods.fw_jobctrl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=null,
row_previous_number=null,
row_read_end=null,
run_time=null
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* transfer data from generic to specific for PTOBST */
execute 'insert into mmt_staging2.stg_specific_table_PTO_PHA
select * from mmt_staging1.mmt_staging_generic_table a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.file_syspk='||p_file_syspk||'';
/* trimming data */
update mmt_staging2.stg_specific_table_PTO_PHA set column3 = TRIM (TRAILING FROM column3 );
update mmt_staging2.stg_specific_table_PTO_PHA set column3 = TRIM (LEADING FROM column3 );
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified) ;
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified) ;
update mmt_ods.mmt_config set F1_source=F1_modified ;
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source);
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source);
/* keyword match in config table*/
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_staging2.stg_specific_table_PTO_PHA b
where trim(upper(F1_modified))=trim(upper(column2))
and b.is_rownumber_fetched is null)
where a.row_number_start is null
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* update config files for row numbers start, end */
execute 'update mmt_staging2.stg_specific_table_PTO_PHA a
set is_rownumber_fetched=1
from mmt_ods.mmt_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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_read_end= (select b.row_number_start
from mmt_ods.mmt_config b
where b.syspk=a.syspk+1 and file_format='''||p_file_format||''' and sheet_mnemonic='''||p_sheet_mnemonic||''' )
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* config file last field update as null otherwise it picks up next format row number*/
execute 'update mmt_ods.mmt_config a
set row_read_end = null ,run_time=current_timestamp
where f1_modified =''Engine Oil Consumption''
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* tagging ranks for each block in process table*/
execute 'insert into mmt_staging2.stg_process_table_PTO_PHA
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_PTO_PHA a
join mmt_ods.mmt_config b
on a.row_number >=row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''KEY Performance Parameters''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'insert into mmt_staging2.stg_process_table_PTO_PHA
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_PTO_PHA a
join mmt_ods.mmt_config b
on a.row_number >=row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''2Hrs Max Power Test''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'insert into mmt_staging2.stg_process_table_PTO_PHA
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag from mmt_staging2.stg_specific_table_PTO_PHA a
join mmt_ods.mmt_config b
on a.row_number >=row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Varying Speed Test''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'insert into mmt_staging2.stg_process_table_PTO_PHA
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag from mmt_staging2.stg_specific_table_PTO_PHA a
join mmt_ods.mmt_config b
on a.row_number >=row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Engine Oil Consumption''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/*
execute format('select column6 from mmt_staging2.stg_process_table_PTO a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and rank_tag=''PTO_test_tractor_specifications'' and trim(column4)=''Make''') into __make;
execute format('select column6 from mmt_staging2.stg_process_table_PTO a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and rank_tag=''PTO_test_tractor_specifications'' and trim(column4)=''Model''') into __model;
*/
/* fetching tractor model and make */
select column3 into __make from mmt_staging2.stg_process_table_PTO_report a
where rank_tag='PTOBST_RPT_test_tractor_specifiactions' and rank=3 ;
select column4 into __model from mmt_staging2.stg_process_table_PTO_report a
where rank_tag='PTOBST_RPT_test_tractor_specifiactions' and rank=3;
/* int data loading PTOBST_PHA_key_perfomrance_parameters_int */
insert into mmt_staging2.PTOBST_PHA_key_perfomrance_parameters_int
( file_syspk,c1,c2,rank)
select file_syspk,column2,column5,rank from mmt_staging2.stg_process_table_PTO_PHA
where rank_tag = 'PTOBST_PHA_KEY_performance_parameters' and rank<>1
union
select file_syspk,column8,column12,rank from mmt_staging2.stg_process_table_PTO_PHA
where rank_tag = 'PTOBST_PHA_KEY_performance_parameters' and rank<>1
union
select file_syspk,column13,column16,rank from mmt_staging2.stg_process_table_PTO_PHA
where rank_tag = 'PTOBST_PHA_KEY_performance_parameters' and rank<>1
union
select file_syspk,column17,column20,rank from mmt_staging2.stg_process_table_PTO_PHA
where rank_tag = 'PTOBST_PHA_KEY_performance_parameters' and rank<>1
union
select file_syspk,column21,column24 ,rank from mmt_staging2.stg_process_table_PTO_PHA
where rank_tag = 'PTOBST_PHA_KEY_performance_parameters' and rank<>1
order by rank,column2;
delete from mmt_staging2.PTOBST_PHA_key_perfomrance_parameters_int where c1 is null;
/* block data loading PTOBST_PHA_key_perfomrance_parameters_block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'PTOBST_PHA_key_perfomrance_parameters_block',__file_format,__sheet_mnemonic,1);
insert into mmt_staging2.PTOBST_PHA_key_perfomrance_parameters_block
(
dummy_f,
Ambient_pressure_mm_of_hg ,
PTO_gear_ratio ,
PTO_power_hp ,
Rated_engine_speed ,
Test_engineer ,
Engine_high_Idle_speed ,
PTO_SFC_gm_hp ,
Relative_humidity ,
Test_bed ,
Backup_Torque ,
Engine_low_idle_speed ,
Exhaust_temperature ,
Place ,
Specific_gravity_of_Fuel ,
back_pressure ,
Dyno_Constant ,
Engine_oil_temp ,
Maximum_Equ_Crankshaft ,
Total_run_hrs ,
Coolant_temp ,
Engine_oil_pressure_bar ,
Equ_crankshaft_torque_at_maximum_power ,
Test_date
)
SELECT *
FROM crosstab(
'SELECT unnest(''{c1,c2}''::text[]) AS col
, row_number() OVER ()
, unnest(ARRAY[c1::text,c2::text]) AS val
FROM mmt_staging2.PTOBST_PHA_key_perfomrance_parameters_int
ORDER BY generate_series(1,15),2'
) t (col text,a1 text,a2 text,a3 text,a4 text,a5 text,
a6 text,a7 text,a8 text,a9 text,a10 text,a11 text,a12 text,a13 text,a14 text,
a15 text,a16 text,a17 text,a18 text,a19 text,a20 text,a21 text,a22 text,a23 text);
delete from mmt_staging2.PTOBST_PHA_key_perfomrance_parameters_block where dummy_f is null;
update mmt_staging2.PTOBST_PHA_key_perfomrance_parameters_block set ods_record=0 where dummy_f='c1';
update mmt_staging2.PTOBST_PHA_key_perfomrance_parameters_block set test_condition='key_performance_parameters';
execute 'update mmt_staging2.PTOBST_PHA_key_perfomrance_parameters_block set client_id='||p_client_id||'';
execute 'update mmt_staging2.PTOBST_PHA_key_perfomrance_parameters_block set function_id='||p_function_id||'';
execute 'update mmt_staging2.PTOBST_PHA_key_perfomrance_parameters_block set file_format='''||p_file_format||'''';
execute 'update mmt_staging2.PTOBST_PHA_key_perfomrance_parameters_block set sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_staging2.PTOBST_PHA_key_perfomrance_parameters_block set file_syspk='||p_file_syspk||'';
update mmt_staging2.PTOBST_PHA_key_perfomrance_parameters_block set make=__make;
update mmt_staging2.PTOBST_PHA_key_perfomrance_parameters_block set model=__model;
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'PTOBST_PHA_key_perfomrance_parameters_block');
/* block - PTOBST_PHA_2Hrs_max_power_test_block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'PTOBST_PHA_2Hrs_max_power_test_block',__file_format,__sheet_mnemonic,2);
insert into mmt_staging2.PTOBST_PHA_2Hrs_max_power_test_block
(
c2,
c3,
c4,
c5,
c6,
c7,
c8,
c9,
c10,
c11,
c12,
c13,
c14,
c15,
c16,
c17,
c18,
c19,
c20,
c21,
c22,
c23,
c24,
c25,
rank
)
select column2,
column3,
column4,
column5,
column6,
column7,
column8,
column9,
column10,
column11,
column12,
column13,
column14,
column15,
column16,
column17,
column18,
column19,
column20,
column21,
column22,
column23,
column24,
column25,
rank
from mmt_staging2.stg_process_table_PTO_PHA
where rank_tag = 'PTOBST_PHA_2Hrs_max_power_test';
update mmt_staging2.PTOBST_PHA_2Hrs_max_power_test_block
set test_condition=c2 where rank=1;
update mmt_staging2.PTOBST_PHA_2Hrs_max_power_test_block a
set test_condition= b.first_value from (SELECT
rank, test_condition, value_partition, first_value(test_condition) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
test_condition,
sum(case when test_condition is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.PTOBST_PHA_2Hrs_max_power_test_block
ORDER BY rank ASC
) as q) b where a.rank = b.rank ;
update mmt_staging2.PTOBST_PHA_2Hrs_max_power_test_block set ods_record=0 where
rank in (1,2,3,4);
execute 'update mmt_staging2.PTOBST_PHA_2Hrs_max_power_test_block set client_id='||p_client_id||'';
execute 'update mmt_staging2.PTOBST_PHA_2Hrs_max_power_test_block set function_id='||p_function_id||'';
execute 'update mmt_staging2.PTOBST_PHA_2Hrs_max_power_test_block set file_format='''||p_file_format||'''';
execute 'update mmt_staging2.PTOBST_PHA_2Hrs_max_power_test_block set sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_staging2.PTOBST_PHA_2Hrs_max_power_test_block set file_syspk='||p_file_syspk||'';
update mmt_staging2.PTOBST_PHA_2Hrs_max_power_test_block set make=__make;
update mmt_staging2.PTOBST_PHA_2Hrs_max_power_test_block set model=__model;
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'PTOBST_PHA_2Hrs_max_power_test_block');
/* block - PTOBST_PHA_varying_speed_test_block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'PTOBST_PHA_varying_speed_test_block',__file_format,__sheet_mnemonic,3);
insert into mmt_staging2.PTOBST_PHA_varying_speed_test_block
(
c2,
c3,
c4,
c5,
c6,
c7,
c8,
c9,
c10,
c11,
c12,
c13,
c14,
c15,
c16,
c17,
c18,
c19,
c20,
c21,
c22,
c23,
c24,
c25,
rank
)
select column2,
column3,
column4,
column5,
column6,
column7,
column8,
column9,
column10,
column11,
column12,
column13,
column14,
column15,
column16,
column17,
column18,
column19,
column20,
column21,
column22,
column23,
column24,
column25,
rank
from mmt_staging2.stg_process_table_PTO_PHA
where rank_tag='PTOBST_PHA_varying_speed_test';
update mmt_staging2.PTOBST_PHA_varying_speed_test_block
set test_condition=c2 where rank=1;
update mmt_staging2.PTOBST_PHA_varying_speed_test_block a
set test_condition= b.first_value from (SELECT
rank, test_condition, value_partition, first_value(test_condition) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
test_condition,
sum(case when test_condition is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.PTOBST_PHA_varying_speed_test_block
ORDER BY rank ASC
) as q) b where a.rank = b.rank ;
update mmt_staging2.PTOBST_PHA_varying_speed_test_block set ods_record=0 where
rank in (1,2,3,4);
execute 'update mmt_staging2.PTOBST_PHA_varying_speed_test_block set client_id='||p_client_id||'';
execute 'update mmt_staging2.PTOBST_PHA_varying_speed_test_block set function_id='||p_function_id||'';
execute 'update mmt_staging2.PTOBST_PHA_varying_speed_test_block set file_format='''||p_file_format||'''';
execute 'update mmt_staging2.PTOBST_PHA_varying_speed_test_block set sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_staging2.PTOBST_PHA_varying_speed_test_block set file_syspk='||p_file_syspk||'';
update mmt_staging2.PTOBST_PHA_varying_speed_test_block set make=__make;
update mmt_staging2.PTOBST_PHA_varying_speed_test_block set model=__model;
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'PTOBST_PHA_varying_speed_test_block');
/* block PTOBST_PHA_Engine_oil_consumption_block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'PTOBST_PHA_Engine_oil_consumption_block',__file_format,__sheet_mnemonic,4);
insert into mmt_staging2.PTOBST_PHA_Engine_oil_consumption_block
(
c2,
c3,c5,
rank
)
select column2,column3,column5 ,rank from mmt_staging2.stg_process_table_PTO_PHA
where rank_tag='PTOBST_PHA_Engine_oil_consumption';
update mmt_staging2.PTOBST_PHA_Engine_oil_consumption_block set ods_record=0 where
rank in (1,2);
execute 'update mmt_staging2.PTOBST_PHA_Engine_oil_consumption_block set client_id='||p_client_id||'';
execute 'update mmt_staging2.PTOBST_PHA_Engine_oil_consumption_block set function_id='||p_function_id||'';
execute 'update mmt_staging2.PTOBST_PHA_Engine_oil_consumption_block set file_format='''||p_file_format||'''';
execute 'update mmt_staging2.PTOBST_PHA_Engine_oil_consumption_block set sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_staging2.PTOBST_PHA_Engine_oil_consumption_block set file_syspk='||p_file_syspk||'';
update mmt_staging2.PTOBST_PHA_Engine_oil_consumption_block set make=__make;
update mmt_staging2.PTOBST_PHA_Engine_oil_consumption_block set model=__model;
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'PTOBST_PHA_Engine_oil_consumption_block');
end
$$ LANGUAGE plpgsql;

View File

@@ -0,0 +1,325 @@
drop function if exists mmt_staging2.fn_PTO_report_block;
CREATE OR REPLACE FUNCTION mmt_staging2.fn_PTO_report_block(p_client_id int,p_function_id int, p_file_format text,
p_sheet_mnemonic text, p_file_syspk int)
RETURNS void AS $$
declare __make text;
declare __model text;
declare __client_id int :=p_client_id;
declare __function_id int :=p_function_id;
declare __file_format text :=p_file_format;
declare __sheet_mnemonic text :=p_sheet_mnemonic;
declare __file_syspk int :=p_file_syspk;
begin
/***********************************************************************************
Function Name:fn_PTO_PNA_block
Function Desc: This function populates data into staging2 blocks
File Format: PTOBST
Sheet Format: PTOBST_RPT
Creation Date: March 21 2021
Updation Date:
Author: compegence team
Function Call: select mmt_staging2.fn_PTO_report_block(1,1,'PTOBST','PTOBST_RPT',255)
************************************************************************************/
SET search_path TO mmt_staging2;
/* rerunnability - delete block tables and update config tables to null */
truncate table mmt_staging2.stg_specific_table_PTO_report;
truncate table mmt_staging2.stg_process_table_PTO_report;
truncate table mmt_staging2.PTOBST_RPT_tractor_specs_block;
truncate table mmt_staging2.PTOBST_RPT_PTO_performance_report_block;
truncate table mmt_staging2.PTOBST_RPT_MMTKeyword1_block;
truncate table mmt_staging2.PTOBST_RPT_MMTKeyword2_block;
truncate table mmt_staging2.PTOBST_RPT_PTO_Performance_Test_Observations_Summary_block;
execute 'delete from mmt_ods.fw_jobctrl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=null,
row_previous_number=null,
row_read_end=null,
run_time=null
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* transfer data from generic to specific for PTOBST */
execute 'insert into mmt_staging2.stg_specific_table_PTO_report
select * from mmt_staging1.mmt_staging_generic_table a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.file_syspk='||p_file_syspk||'';
/* trimming data */
update mmt_staging2.stg_specific_table_PTO_report set column3 = TRIM (TRAILING FROM column3 );
update mmt_staging2.stg_specific_table_PTO_report set column3 = TRIM (LEADING FROM column3 );
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified) ;
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified) ;
update mmt_ods.mmt_config set F1_source=F1_modified ;
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source);
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source);
/* keyword match in config table*/
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_staging2.stg_specific_table_PTO_report 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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* reverese update in process table for match*/
execute 'update mmt_staging2.stg_specific_table_PTO_report a
set is_rownumber_fetched=1
from mmt_ods.mmt_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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* update config files for row numbers start, end */
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_read_end= (select b.row_number_start
from mmt_ods.mmt_config b
where b.syspk=a.syspk+1 and file_format='''||p_file_format||''' and sheet_mnemonic='''||p_sheet_mnemonic||''' )
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* config file last field update as null otherwise it picks up next format row number*/
execute 'update mmt_ods.mmt_config a
set row_read_end = null ,run_time=current_timestamp
where f1_modified =''PTO Performance Test Observations Summary''
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* tagging ranks for each block in process table*/
execute 'insert into mmt_staging2.stg_process_table_PTO_report
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_PTO_report a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'insert into mmt_staging2.stg_process_table_PTO_report
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_PTO_report a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'insert into mmt_staging2.stg_process_table_PTO_report
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag from mmt_staging2.stg_specific_table_PTO_report a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'insert into mmt_staging2.stg_process_table_PTO_report
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag from mmt_staging2.stg_specific_table_PTO_report a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'insert into mmt_staging2.stg_process_table_PTO_report
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_PTO_report a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* fetching tractor model and make */
select column3 into __make from mmt_staging2.stg_process_table_PTO_report a
where rank_tag='PTOBST_RPT_test_tractor_specifiactions' and rank=3 ;
select column4 into __model from mmt_staging2.stg_process_table_PTO_report a
where rank_tag='PTOBST_RPT_test_tractor_specifiactions' and rank=3;
/* blocks data loading start - PTOBST_RPT_tractor_specs_block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'PTOBST_RPT_tractor_specs_block',__file_format,__sheet_mnemonic,1);
insert into mmt_staging2.PTOBST_RPT_tractor_specs_block
(make,model,tractor_HP,rated_rpm,configuration,transmission_type,wheel_drive_type,FIP_type,rank)
select column3,column4,column5,column6,column7,column8,column9,column10,rank
from mmt_staging2.stg_process_table_PTO_report where rank_tag='PTOBST_RPT_test_tractor_specifiactions'
and rank=3;
execute 'update mmt_staging2.PTOBST_RPT_tractor_specs_block set file_syspk='||p_file_syspk||'';
update mmt_staging2.PTOBST_RPT_tractor_specs_block a
set date= date '1899-12-30' + column12::int * interval '1' day
from mmt_staging2.stg_process_table_PTO_report b
where b.rank_tag='PTOBST_RPT_test_tractor_specifiactions'
and b.rank=1
and a.file_syspk=b.file_syspk ;
update mmt_staging2.PTOBST_RPT_tractor_specs_block a
set steering_type=column3,Engine_to_PTO_ratio= column4
from mmt_staging2.stg_process_table_PTO_report b
where b.rank_tag='PTOBST_RPT_test_tractor_specifiactions'
and b.rank=5
and a.file_syspk=b.file_syspk;
update mmt_staging2.PTOBST_RPT_tractor_specs_block set make=__make;
update mmt_staging2.PTOBST_RPT_tractor_specs_block set model=__model;
execute 'update mmt_staging2.PTOBST_RPT_tractor_specs_block set client_id='||p_client_id||'';
execute 'update mmt_staging2.PTOBST_RPT_tractor_specs_block set function_id='||p_function_id||'';
execute 'update mmt_staging2.PTOBST_RPT_tractor_specs_block set file_format='''||p_file_format||'''';
execute 'update mmt_staging2.PTOBST_RPT_tractor_specs_block set sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'PTOBST_RPT_tractor_specs_block');
/* blocks data loading - PTOBST_RPT_PTO_performance_report_block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'PTOBST_RPT_PTO_performance_report_block',__file_format,__sheet_mnemonic,2);
insert into mmt_staging2.PTOBST_RPT_PTO_performance_report_block
( c2,c3,c4,c5,c6,c7,c8,c9,c10,rank)
select column2,column3,column4,column5,column6,column7,column8,column9,column10,rank
from mmt_staging2.stg_process_table_PTO_report
where rank_tag='PTOBST_RPT_PTO_performance_report';
update mmt_staging2.PTOBST_RPT_PTO_performance_report_block
set c2=c3;
update mmt_staging2.PTOBST_RPT_PTO_performance_report_block
set c2=null
where c2 like 'i%';
update mmt_staging2.PTOBST_RPT_PTO_performance_report_block
set c2=null
where c2 like 'v%';
update mmt_staging2.PTOBST_RPT_PTO_performance_report_block a
set c2= b.first_value from (SELECT
rank, c2, value_partition, first_value(c2) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
c2,
sum(case when c2 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.PTOBST_RPT_PTO_performance_report_block
ORDER BY rank ASC
) as q) b where a.rank = b.rank ;
update mmt_staging2.PTOBST_RPT_PTO_performance_report_block
set c3 =null
where c2=c3;
update mmt_staging2.PTOBST_RPT_PTO_performance_report_block
set ods_record=0 where rank in (1,2,3);
update mmt_staging2.PTOBST_RPT_PTO_performance_report_block set ods_record=0 where c3 is null
and c2 in(
select c2 from mmt_staging2.PTOBST_RPT_PTO_performance_report_block group by c2 having count(*)>1
);
update mmt_staging2.PTOBST_RPT_PTO_performance_report_block set make=__make;
update mmt_staging2.PTOBST_RPT_PTO_performance_report_block set model=__model;
execute 'update mmt_staging2.PTOBST_RPT_PTO_performance_report_block set client_id='||p_client_id||'';
execute 'update mmt_staging2.PTOBST_RPT_PTO_performance_report_block set function_id='||p_function_id||'';
execute 'update mmt_staging2.PTOBST_RPT_PTO_performance_report_block set file_format='''||p_file_format||'''';
execute 'update mmt_staging2.PTOBST_RPT_PTO_performance_report_block set sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_staging2.PTOBST_RPT_PTO_performance_report_block set file_syspk='||p_file_syspk||'';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'PTOBST_RPT_PTO_performance_report_block');
/* block loading data - PTOBST_RPT_MMTKeyword1_block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'PTOBST_RPT_MMTKeyword1_block',__file_format,__sheet_mnemonic,3);
insert into mmt_staging2.PTOBST_RPT_MMTKeyword1_block
( c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,rank)
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,rank
from mmt_staging2.stg_process_table_PTO_report
where rank_tag='PTOBST_RPT_MMTKeyword1';
update mmt_staging2.PTOBST_RPT_MMTKeyword1_block set ods_record=0 where rank in (1,2);
update mmt_staging2.PTOBST_RPT_MMTKeyword1_block set make=__make;
update mmt_staging2.PTOBST_RPT_MMTKeyword1_block set model=__model;
execute 'update mmt_staging2.PTOBST_RPT_MMTKeyword1_block set client_id='||p_client_id||'';
execute 'update mmt_staging2.PTOBST_RPT_MMTKeyword1_block set function_id='||p_function_id||'';
execute 'update mmt_staging2.PTOBST_RPT_MMTKeyword1_block set file_format='''||p_file_format||'''';
execute 'update mmt_staging2.PTOBST_RPT_MMTKeyword1_block set sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_staging2.PTOBST_RPT_MMTKeyword1_block set file_syspk='||p_file_syspk||'';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'PTOBST_RPT_MMTKeyword1_block');
/* block loading data PTOBST_RPT_MMTKeyword2_block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'PTOBST_RPT_MMTKeyword2_block',__file_format,__sheet_mnemonic,4);
insert into mmt_staging2.PTOBST_RPT_MMTKeyword2_block
( c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,rank)
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,rank
from mmt_staging2.stg_process_table_PTO_report
where rank_tag='PTOBST_RPT_MMTKeyword2';
update mmt_staging2.PTOBST_RPT_MMTKeyword2_block set ods_record=0 where rank in (1,2);
update mmt_staging2.PTOBST_RPT_MMTKeyword2_block set make=__make;
update mmt_staging2.PTOBST_RPT_MMTKeyword2_block set model=__model;
execute 'update mmt_staging2.PTOBST_RPT_MMTKeyword2_block set client_id='||p_client_id||'';
execute 'update mmt_staging2.PTOBST_RPT_MMTKeyword2_block set function_id='||p_function_id||'';
execute 'update mmt_staging2.PTOBST_RPT_MMTKeyword2_block set file_format='''||p_file_format||'''';
execute 'update mmt_staging2.PTOBST_RPT_MMTKeyword2_block set sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_staging2.PTOBST_RPT_MMTKeyword2_block set file_syspk='||p_file_syspk||'';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'PTOBST_RPT_MMTKeyword2_block');
/* block loading data PTOBST_RPT_PTO_Performance_Test_Observations_Summary_block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'PTOBST_RPT_PTO_Performance_Test_Observations_Summary_block',__file_format,__sheet_mnemonic,5);
insert into mmt_staging2.PTOBST_RPT_PTO_Performance_Test_Observations_Summary_block
( c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,rank)
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,rank
from mmt_staging2.stg_process_table_PTO_report
where rank_tag='PTOBST_RPT_PTO_Performance_Test_Observations_Summary';
update mmt_staging2.PTOBST_RPT_PTO_Performance_Test_Observations_Summary_block set ods_record=0 where rank in (1,2);
update mmt_staging2.PTOBST_RPT_PTO_Performance_Test_Observations_Summary_block set make=__make;
update mmt_staging2.PTOBST_RPT_PTO_Performance_Test_Observations_Summary_block set model=__model;
execute 'update mmt_staging2.PTOBST_RPT_PTO_Performance_Test_Observations_Summary_block set client_id='||p_client_id||'';
execute 'update mmt_staging2.PTOBST_RPT_PTO_Performance_Test_Observations_Summary_block set function_id='||p_function_id||'';
execute 'update mmt_staging2.PTOBST_RPT_PTO_Performance_Test_Observations_Summary_block set file_format='''||p_file_format||'''';
execute 'update mmt_staging2.PTOBST_RPT_PTO_Performance_Test_Observations_Summary_block set sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_staging2.PTOBST_RPT_PTO_Performance_Test_Observations_Summary_block set file_syspk='||p_file_syspk||'';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'PTOBST_RPT_PTO_Performance_Test_Observations_Summary_block');
/* final update */
update mmt_staging2.PTOBST_RPT_PTO_performance_report_block set test_condition='PTO performance report';
update mmt_staging2.PTOBST_RPT_PTO_performance_report_block set test_condition='PTO performance report';
update mmt_staging2.PTOBST_RPT_PTO_Performance_Test_Observations_Summary_block set test_condition='PTO_Performance_Test_Observations_Summary';
end
$$ LANGUAGE plpgsql;

View File

@@ -0,0 +1,290 @@
drop function if exists mmt_staging2.fn_BUDNI_ARC_Block ;
CREATE OR REPLACE FUNCTION mmt_staging2.fn_BUDNI_ARC_Block(p_client_id int,p_function_id int, p_file_format text,
p_sheet_mnemonic text, p_file_syspk int)
RETURNS void AS $$
declare __make text;
declare __model text;
declare __client_id int :=p_client_id;
declare __function_id int :=p_function_id;
declare __file_format text :=p_file_format;
declare __sheet_mnemonic text :=p_sheet_mnemonic;
declare __file_syspk int :=p_file_syspk;
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 mmt_staging2.fn_FTDRY_SUM_Block (20,1,'BUDNI','BUDNI_ARC',273);
************************************************************************************/
SET search_path TO mmt_staging2;
truncate mmt_staging2.BUDNI_ARC_Spec_H1_Block;
truncate mmt_staging2.BUDNI_ARC_Perf_Atmos_Meas_Test_Block;
truncate mmt_staging2.BUDNI_ARC_Test_Obs_Summary_Block;
truncate mmt_staging2.stg_specific_table_BUDNI_ARC;
truncate mmt_staging2.stg_process_table_BUDNI_ARC;
execute 'delete from mmt_ods.fw_jobctrl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=null,
row_previous_number=null,
row_read_end=null,
run_time=null
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* transfer data from generic to specific for ftdry*/
execute 'insert into mmt_staging2.stg_specific_table_BUDNI_ARC
select * from mmt_staging1.mmt_staging_generic_table a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.file_syspk='||p_file_syspk||'';
/* trimming data */
update mmt_staging2.stg_specific_table_BUDNI_ARC set column3 = TRIM (TRAILING FROM column3 );
update mmt_staging2.stg_specific_table_BUDNI_ARC set column3 = TRIM (LEADING FROM column3 );
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified);
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified);
update mmt_ods.mmt_config set F1_source=F1_modified;
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source);
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source) ;
/* keyword match in config table*/
execute 'update mmt_ods.mmt_config a set f1_source = replace(f1_source,''_1'','''')
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* update config files for row numbers start, end */
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_staging2.stg_specific_table_BUDNI_ARC 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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* reverese update in process table for match*/
execute 'update mmt_staging2.stg_specific_table_BUDNI_ARC a
set is_rownumber_fetched=1
from mmt_ods.mmt_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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a set f1_source = replace(f1_source,''_2'','''')
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_staging2.stg_specific_table_BUDNI_ARC 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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_staging2.stg_specific_table_BUDNI_ARC a
set is_rownumber_fetched=1
from mmt_ods.mmt_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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* update config files for row numbers start, end */
execute 'update mmt_ods.mmt_config a
set row_read_end= (select b.row_number_start
from mmt_ods.mmt_config b
where b.syspk=a.syspk+1 )
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* config file last field update as null otherwise it picks up next format row number*/
execute 'update mmt_ods.mmt_config a
set row_read_end = null
where f1_modified =''AIR CLEANER OIL PULL OVER TEST Observations Summary''
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/*inserting run_time in config*/
execute 'update mmt_ods.mmt_config a
set run_time=current_timestamp
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* tagging ranks for each block in process table*/
execute 'insert into mmt_staging2.stg_process_table_BUDNI_ARC
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_BUDNI_ARC a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_BUDNI_ARC
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_BUDNI_ARC a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_BUDNI_ARC
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_BUDNI_ARC a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
/* fetching tractor model and make */
select column3 into __make from mmt_staging2.stg_process_table_BUDNI_ARC a
where rank_tag='BUDNI_ARC_Spec_H1' and rank=3;
select column4 into __model from mmt_staging2.stg_process_table_BUDNI_ARC a
where rank_tag='BUDNI_ARC_Spec_H1' and rank=3;
/* blocks data loading start - BUDNI_ARC_Spec_H1_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_ARC_Spec_H1_Block',__file_format,__sheet_mnemonic,1);
insert into mmt_staging2.BUDNI_ARC_Spec_H1_block
(
make,model,tractor_HP,rated_rpm,configuration,transmission_type,wheel_drive_type,rank)
select column3,column4,column5,column6,column7,column8,column9,rank
from mmt_staging2.stg_process_table_BUDNI_ARC where rank_tag='BUDNI_ARC_Spec_H1'
and rank=3;
execute 'update mmt_staging2.BUDNI_ARC_Spec_H1_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
update mmt_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 mmt_staging2.stg_process_table_BUDNI_ARC b
where b.rank_tag='BUDNI_ARC_Spec_H1'
and b.rank=5
and a.file_syspk=b.file_syspk;
update mmt_staging2.BUDNI_ARC_Spec_H1_Block
set ods_record=0 where rank in(1,2);
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_ARC_Spec_H1_block');
/* blocks data loading start - BUDNI_ARC_Perf_Atmos_Meas_Test_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_ARC_Perf_Atmos_Meas_Test_Block',__file_format,__sheet_mnemonic,2);
insert into mmt_staging2.BUDNI_ARC_Perf_Atmos_Meas_Test_Block
(
Position_of_tractor,
Loss_of_oil,
Oil_pull_Over,
Engine_oil_pressure,
rank
)
select
column3,column6,column7,column8,rank
from mmt_staging2.stg_process_table_BUDNI_ARC a
where rank_tag ='BUDNI_ARC_Perf_Atmos_Meas_Test' and rank in (5,6,7,8,9)
order by rank;
update mmt_staging2.BUDNI_ARC_Perf_Atmos_Meas_Test_Block set make=__make,model=__model;
execute 'update mmt_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_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
update mmt_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 mmt_staging2.stg_process_table_BUDNI_ARC b
where b.rank_tag ='BUDNI_ARC_Perf_Atmos_Meas_Test'
and b.rank =3
and a.file_syspk=b.file_syspk;
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_ARC_Perf_Atmos_Meas_Test_Block');
/* blocks data loading start - BUDNI_ARC_Test_Obs_Summary_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_ARC_Test_Obs_Summary_Block',__file_format,__sheet_mnemonic,3);
insert into mmt_staging2.BUDNI_ARC_Test_Obs_Summary_Block
(
column3,column4,column5,column6,column7,
column8,column9,rank
)
select
column3,column4,column5,column6,column7,
column8,column9,rank
from mmt_staging2.stg_process_table_BUDNI_ARC a
where rank_tag='BUDNI_ARC_Test_Obs_Summary' and rank in (1,2,3)
order by rank;
update mmt_staging2.BUDNI_ARC_Test_Obs_Summary_Block
set ods_record=0 where
rank in(1,2);
update mmt_staging2.BUDNI_ARC_Test_Obs_Summary_Block set make=__make,model=__model;
execute 'update mmt_staging2.BUDNI_ARC_Test_Obs_Summary_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_ARC_Test_Obs_Summary_Block');
end
$$ LANGUAGE plpgsql;

View File

@@ -0,0 +1,694 @@
drop function if exists mmt_staging2.fn_BUDNI_BRK_Block;
CREATE OR REPLACE FUNCTION mmt_staging2.fn_BUDNI_BRK_Block(p_client_id int,p_function_id int, p_file_format text,
p_sheet_mnemonic text, p_file_syspk int)
RETURNS void AS $$
declare __make text;
declare __model text;
declare __characteristic_1 text;
declare __client_id int :=p_client_id;
declare __function_id int :=p_function_id;
declare __file_format text :=p_file_format;
declare __sheet_mnemonic text :=p_sheet_mnemonic;
declare __file_syspk int :=p_file_syspk;
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 mmt_staging2.fn_BUDNI_BRK_Block(20,1,'BUDNI','BUDNI_BRK',273);
************************************************************************************/
SET search_path TO mmt_staging2;
truncate table mmt_staging2.BUDNI_BRK_Spec_H1_Block;
truncate table mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int;
truncate table mmt_staging2.budni_brk_service_cold_ballasted_maximum_block;
truncate table mmt_staging2.budni_brk_service_cold_standard_25kmph_block;
truncate table mmt_staging2.budni_brk_service_cold_standard_maximum_block;
truncate table mmt_staging2.BUDNI_BRK_service_cold_ballasted_25kmph_Block;
truncate table mmt_staging2.BUDNI_BRK_service_fade_standard_maximum_Block;
truncate table mmt_staging2.BUDNI_BRK_service_fade_ballasted_25kmph_Block;
truncate table mmt_staging2.BUDNI_BRK_other_observations_Block;
truncate table mmt_staging2.BUDNI_BRK_Parking_Barke_Test_Int;
truncate table mmt_staging2.BUDNI_BRK_Parking_Barke_Test_Block;
truncate table mmt_staging2.BUDNI_BRK_Test_Obs_Summary_Block;
truncate table mmt_staging2.stg_specific_table_BUDNI_BRK;
truncate table mmt_staging2.stg_process_table_BUDNI_BRK;
execute 'delete from mmt_ods.fw_jobctrl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=null,
row_previous_number=null,
row_read_end=null,
run_time=null
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* transfer data from generic to specific for ftdry*/
execute 'insert into mmt_staging2.stg_specific_table_BUDNI_BRK
select * from mmt_staging1.mmt_staging_generic_table a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.file_syspk='||p_file_syspk||'';
/* trimming data */
execute 'update mmt_staging2.stg_specific_table_BUDNI_BRK set column2 = TRIM (TRAILING FROM column2 )';
execute 'update mmt_staging2.stg_specific_table_BUDNI_BRK set column2 = TRIM (LEADING FROM column2 )';
execute 'update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified)';
execute 'update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified)' ;
execute 'update mmt_ods.mmt_config set F1_source=F1_modified' ;
execute 'update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source)';
execute 'update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source)' ;
/* keyword match in config table*/
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_staging2.stg_specific_table_BUDNI_BRK 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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* reverese update in process table for match*/
execute 'update mmt_staging2.stg_specific_table_BUDNI_BRK a
set is_rownumber_fetched=1
from mmt_ods.mmt_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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* update config files for row numbers start, end */
execute 'update mmt_ods.mmt_config a
set row_read_end= (select b.row_number_start
from mmt_ods.mmt_config b
where b.syspk=a.syspk+1 )
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* config file last field update as null otherwise it picks up next format row number*/
execute 'update mmt_ods.mmt_config a
set row_read_end = null
where f1_modified =''Brake Performance Test Observations Summary''
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/*inserting run_time in config*/
execute 'update mmt_ods.mmt_config a
set run_time=current_timestamp
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* tagging ranks for each block in process table*/
execute 'insert into mmt_staging2.stg_process_table_BUDNI_BRK
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_BUDNI_BRK a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_BUDNI_BRK
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_BUDNI_BRK a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_BUDNI_BRK
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_BUDNI_BRK a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_BUDNI_BRK
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_BUDNI_BRK a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
/* fetching tractor model and make */
select column3 into __make from mmt_staging2.stg_process_table_BUDNI_BRK a
where rank_tag='BUDNI_BRK_Spec_H1' and rank=3;
select column4 into __model from mmt_staging2.stg_process_table_BUDNI_BRK a
where rank_tag='BUDNI_BRK_Spec_H1' and rank=3;
/* blocks data loading start - BUDNI_BRK_Spec_H1_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_BRK_Spec_H1_Block',__file_format,__sheet_mnemonic,1);
insert into mmt_staging2.BUDNI_BRK_Spec_H1_block
(
make,model,tractor_HP,rated_rpm,Type_of_brake ,
Type_of_track,rank)
select column3,column4,column5,column6,column7,column8,rank
from mmt_staging2.stg_process_table_BUDNI_BRK where rank_tag='BUDNI_BRK_Spec_H1'
and rank=3;
execute 'update mmt_staging2.BUDNI_BRK_Spec_H1_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
update mmt_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 mmt_staging2.stg_process_table_BUDNI_BRK b
where b.rank_tag='BUDNI_BRK_Spec_H1'
and b.rank=6
and a.file_syspk=b.file_syspk;
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_BRK_Spec_H1_block');
insert into mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int
(
column3,
column4,
column5,
column6,
column7,
column8,
column9,
rank
)
select
column3,column4,column5,column6,column7,column8,column9,rank
from mmt_staging2.stg_process_table_BUDNI_BRK a
where rank_tag ='BUDNI_BRK_Service_Barke_Test'
order by rank;
update mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int
set column2=(select column3 from mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int
where rank=1) where rank=3;
update mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int
set column3=(select column3 from mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int
where rank=2) where rank=3;
update mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int
set column3=(select column3 from mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int
where rank=3)where rank=10;
update mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int
set column5=(select column5 from mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int
where rank=18)where rank=17;
update mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int
set column3=(select column3 from mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int
where rank=17)where rank=22;
update mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int
set column3=null where rank =1;
update mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int
set column3=null where rank =2;
update mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int
set column5 =null where rank=18;
update mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int a
set column2= b.first_value from (SELECT
rank, column2, value_partition, first_value(column2) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column2,
sum(case when column2 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int
ORDER BY rank ASC
) as q) b where a.rank = b.rank;
update mmt_staging2.budni_brk_service_barke_test_int set make=__make,model=__model;
execute 'update mmt_staging2.BUDNI_BRK_Service_Barke_Test_int set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* blocks data loading start - BUDNI_BRK_service_cold_standard_maximum_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_BRK_service_cold_standard_maximum_Block',__file_format,__sheet_mnemonic,2);
insert into mmt_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 mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int where rank in (4,5,6)
ORDER BY generate_series(1,15),2'
) t (col text,a_1 text,a_2 text,a_3 text);
update mmt_staging2.BUDNI_BRK_service_cold_standard_maximum_Block set make=__make,model=__model;
delete from mmt_staging2.BUDNI_BRK_service_cold_standard_maximum_Block where dummy_f is null;
execute 'update mmt_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_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
update mmt_staging2.BUDNI_BRK_service_cold_standard_maximum_Block a
set brake_test_type =column2,
brake_test_name =column3,
speed_condition =column5
from mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int b
where b.rank=3 and a.file_syspk=b.file_syspk;
update mmt_staging2.BUDNI_BRK_service_cold_standard_maximum_Block a
set ballast_condition =column3
from mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int b
where b.rank=4 and a.file_syspk=b.file_syspk;
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_BRK_service_cold_standard_maximum_Block');
/* blocks data loading start - BUDNI_BRK_service_cold_ballasted_maximum_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_BRK_service_cold_ballasted_maximum_Block',__file_format,__sheet_mnemonic,3);
insert into mmt_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 mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int where rank in (7,8,9)
ORDER BY generate_series(1,15),2'
) t (col text,a_1 text,a_2 text,a_3 text);
update mmt_staging2.BUDNI_BRK_service_cold_ballasted_maximum_Block set make=__make,model=__model;
delete from mmt_staging2.BUDNI_BRK_service_cold_ballasted_maximum_Block where dummy_f is null;
execute 'update mmt_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_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
update mmt_staging2.BUDNI_BRK_service_cold_ballasted_maximum_Block a
set brake_test_type =column2,
brake_test_name =column3,
speed_condition =column5
from mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int b
where b.rank=3 and a.file_syspk=b.file_syspk;
update mmt_staging2.BUDNI_BRK_service_cold_ballasted_maximum_Block a
set ballast_condition =column3
from mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int b
where b.rank=7 and a.file_syspk=b.file_syspk;
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_BRK_service_cold_ballasted_maximum_Block');
/* blocks data loading start - BUDNI_BRK_service_cold_standard_25kmph_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_BRK_service_cold_standard_25kmph_Block',__file_format,__sheet_mnemonic,4);
insert into mmt_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 mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int where rank in (11,12,13)
ORDER BY generate_series(1,15),2'
) t (col text,a_1 text,a_2 text,a_3 text);
update mmt_staging2.BUDNI_BRK_service_cold_standard_25kmph_Block set make=__make,model=__model;
delete from mmt_staging2.BUDNI_BRK_service_cold_standard_25kmph_Block where dummy_f is null;
execute 'update mmt_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_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
update mmt_staging2.BUDNI_BRK_service_cold_standard_25kmph_Block a
set brake_test_type =column2,
brake_test_name =column3,
speed_condition =column5
from mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int b
where b.rank=10 and a.file_syspk=b.file_syspk;
update mmt_staging2.BUDNI_BRK_service_cold_standard_25kmph_Block a
set ballast_condition =column3
from mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int b
where b.rank=11 and a.file_syspk=b.file_syspk;
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_BRK_service_cold_standard_25kmph_Block');
/* blocks data loading start - BUDNI_BRK_service_cold_ballasted_25kmph_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_BRK_service_cold_ballasted_25kmph_Block',__file_format,__sheet_mnemonic,5);
insert into mmt_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 mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int where rank in (14,15,16)
ORDER BY generate_series(1,15),2'
) t (col text,a_1 text,a_2 text,a_3 text);
update mmt_staging2.BUDNI_BRK_service_cold_ballasted_25kmph_Block set make=__make,model=__model;
delete from mmt_staging2.BUDNI_BRK_service_cold_ballasted_25kmph_Block where dummy_f is null;
execute 'update mmt_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_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
update mmt_staging2.BUDNI_BRK_service_cold_ballasted_25kmph_Block a
set brake_test_type =column2,
brake_test_name =column3,
speed_condition =column5
from mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int b
where b.rank=10 and a.file_syspk=b.file_syspk;
update mmt_staging2.BUDNI_BRK_service_cold_ballasted_25kmph_Block a
set ballast_condition =column3
from mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int b
where b.rank=14 and a.file_syspk=b.file_syspk;
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_BRK_service_cold_ballasted_25kmph_Block');
/* blocks data loading start - BUDNI_BRK_service_fade_standard_maximum_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_BRK_service_fade_standard_maximum_Block',__file_format,__sheet_mnemonic,6);
insert into mmt_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 mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int where rank in (19,20,21)
ORDER BY generate_series(1,15),2'
) t (col text,a_1 text,a_2 text,a_3 text);
update mmt_staging2.BUDNI_BRK_service_fade_standard_maximum_Block set make=__make,model=__model;
delete from mmt_staging2.BUDNI_BRK_service_fade_standard_maximum_Block where dummy_f is null;
execute 'update mmt_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_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
update mmt_staging2.BUDNI_BRK_service_fade_standard_maximum_Block a
set brake_test_type =column2,
brake_test_name =column3,
speed_condition =column5
from mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int b
where b.rank=17 and a.file_syspk=b.file_syspk;
update mmt_staging2.BUDNI_BRK_service_fade_standard_maximum_Block a
set ballast_condition =column3
from mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int b
where b.rank=19 and a.file_syspk=b.file_syspk;
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_BRK_service_fade_standard_maximum_Block');
/* blocks data loading start - BUDNI_BRK_service_fade_ballasted_25kmph_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_BRK_service_fade_ballasted_25kmph_Block',__file_format,__sheet_mnemonic,7);
insert into mmt_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 mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int where rank in (23,24,25)
ORDER BY generate_series(1,15),2'
) t (col text,a_1 text,a_2 text,a_3 text);
update mmt_staging2.BUDNI_BRK_service_fade_ballasted_25kmph_Block set make=__make,model=__model;
delete from mmt_staging2.BUDNI_BRK_service_fade_ballasted_25kmph_Block where dummy_f is null;
execute 'update mmt_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_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
update mmt_staging2.BUDNI_BRK_service_fade_ballasted_25kmph_Block a
set brake_test_type =column2,
brake_test_name =column3,
speed_condition =column5
from mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int b
where b.rank=22 and a.file_syspk=b.file_syspk;
update mmt_staging2.BUDNI_BRK_service_fade_ballasted_25kmph_Block a
set ballast_condition =column3
from mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int b
where b.rank=23 and a.file_syspk=b.file_syspk;
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_BRK_service_fade_ballasted_25kmph_Block');
/* blocks data loading start - BUDNI_BRK_other_observations_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_BRK_other_observations_Block',__file_format,__sheet_mnemonic,8);
insert into mmt_staging2.BUDNI_BRK_other_observations_Block
(
column3,
column5,
column7,
rank
)
select
column3,
column5,
column7,
rank
from mmt_staging2.BUDNI_BRK_Service_Barke_Test_Int
where rank in (26,27,28) order by rank;
update mmt_staging2.BUDNI_BRK_other_observations_Block
set ods_record=0 where rank in (26,27);
update mmt_staging2.BUDNI_BRK_other_observations_Block set make=__make,model=__model;
execute 'update mmt_staging2.BUDNI_BRK_other_observations_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_BRK_other_observations_Block');
insert into mmt_staging2.BUDNI_BRK_Parking_Barke_Test_Int
(
column3,
column5,
column6,
column7,
column8,
rank
)
select
column3,column5,column6,column7,column8,rank
from mmt_staging2.stg_process_table_BUDNI_BRK a
where rank_tag ='BUDNI_BRK_Parking_Brake_Test'
order by rank;
update mmt_staging2.BUDNI_BRK_Parking_Barke_Test_Int
set column6=column5 where rank=2;
update mmt_staging2.BUDNI_BRK_Parking_Barke_Test_Int
set column8=column7 where rank=2;
update mmt_staging2.BUDNI_BRK_Parking_Barke_Test_Int
set column6=column5 where rank=5;
update mmt_staging2.BUDNI_BRK_Parking_Barke_Test_Int
set column8=column7 where rank=5;
update mmt_staging2.BUDNI_BRK_Parking_Barke_Test_Int set make=__make,model=__model;
execute 'update mmt_staging2.BUDNI_BRK_Parking_Barke_Test_Int set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* blocks data loading start -BUDNI_BRK_Parking_Barke_Test_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_BRK_Parking_Barke_Test_Block',__file_format,__sheet_mnemonic,9);
insert into mmt_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 mmt_staging2.BUDNI_BRK_Parking_Barke_Test_Int where rank <> 1
ORDER BY generate_series(1,15),rank,2'
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text);
update mmt_staging2.BUDNI_BRK_Parking_Barke_Test_Block set make=__make,model=__model;
delete from mmt_staging2.BUDNI_BRK_Parking_Barke_Test_Block where dummy_f is null;
execute 'update mmt_staging2.BUDNI_BRK_Parking_Barke_Test_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_BRK_Parking_Barke_Test_Block');
/* blocks data loading start - BUDNI_BRK_Test_Obs_Summary_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_BRK_Test_Obs_Summary_Block',__file_format,__sheet_mnemonic,10);
insert into mmt_staging2.BUDNI_BRK_Test_Obs_Summary_Block
(
column3,column4,column5,column6,column7,
column8,column9,rank
)
select
column3,column4,column5,column6,column7,
column8,column9,rank
from mmt_staging2.stg_process_table_BUDNI_BRK a
where rank_tag='BUDNI_BRK_Test_Obs_Summary' and rank <=7
order by rank;
select column3 into __characteristic_1 from mmt_staging2.BUDNI_BRK_Test_Obs_Summary_Block
where rank=3;
update mmt_staging2.BUDNI_BRK_Test_Obs_Summary_Block set
column3=concat(__characteristic_1,'-',column3) where rank in (4,5);
update mmt_staging2.BUDNI_BRK_Test_Obs_Summary_Block
set ods_record=0 where
rank in(1,2,3);
update mmt_staging2.BUDNI_BRK_Test_Obs_Summary_Block set make=__make,model=__model;
execute 'update mmt_staging2.BUDNI_BRK_Test_Obs_Summary_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
end
$$ LANGUAGE plpgsql;

View File

@@ -0,0 +1,238 @@
drop function if exists mmt_staging2.fn_BUDNI_DBP_Block ;
CREATE OR REPLACE FUNCTION mmt_staging2.fn_BUDNI_DBP_Block(p_client_id int,p_function_id int, p_file_format text,
p_sheet_mnemonic text, p_file_syspk int)
RETURNS void AS $$
declare __make text;
declare __model text;
declare __client_id int :=p_client_id;
declare __function_id int :=p_function_id;
declare __file_format text :=p_file_format;
declare __sheet_mnemonic text :=p_sheet_mnemonic;
declare __file_syspk int :=p_file_syspk;
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 mmt_staging2.fn_BUDNI_DBP_Block(20,1,'BUDNI','BUDNI_DBP',261);
************************************************************************************/
SET search_path TO mmt_staging2;
/* rerunnability - delete block tables and update config tables to null */
truncate table mmt_staging2.BUDNI_DBP_Spec_H1_Block;
truncate table mmt_staging2.BUDNI_DBP_Drawbar_Perf_Block;
truncate table mmt_staging2.stg_specific_table_budni_dbp;
truncate table mmt_staging2.stg_process_table_budni_dbp;
execute 'delete from mmt_ods.fw_jobctrl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=null,
row_previous_number=null,
row_read_end=null,
run_time=null
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* transfer data from generic to specific for PTOBST */
execute 'insert into mmt_staging2.stg_specific_table_budni_dbp
select * from mmt_staging1.mmt_staging_generic_table a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.file_syspk='||p_file_syspk||'';
/* trimming data */
update mmt_staging2.stg_specific_table_budni_dbp set column3 = TRIM (TRAILING FROM column3 );
update mmt_staging2.stg_specific_table_budni_dbp set column3 = TRIM (LEADING FROM column3 );
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified);
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified);
update mmt_ods.mmt_config set F1_source=F1_modified ;
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source);
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source) ;
/* keyword match in config table*/
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_staging2.stg_specific_table_budni_dbp 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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* reverese update in process table for match*/
execute 'update mmt_staging2.stg_specific_table_budni_dbp a
set is_rownumber_fetched=1
from mmt_ods.mmt_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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* update config files for row numbers start, end */
execute 'update mmt_ods.mmt_config a
set row_read_end= (select b.row_number_start
from mmt_ods.mmt_config b
where b.syspk=a.syspk+1 )
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* config file last field update as null otherwise it picks up next format row number*/
execute 'update mmt_ods.mmt_config a
set row_read_end = null
where f1_modified =''Tractor Drawbar Performance Report.''
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set run_time=current_timestamp
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* tagging ranks for each block in process table*/
execute 'insert into mmt_staging2.stg_process_table_budni_dbp
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_budni_dbp a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_budni_dbp
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_budni_dbp a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
/* fetching tractor model and make */
select column3 into __make from mmt_staging2.stg_process_table_budni_dbp a
where rank_tag='BUDNI_DBP_Spec_H1' and rank=2;
select column4 into __model from mmt_staging2.stg_process_table_budni_dbp a
where rank_tag='BUDNI_DBP_Spec_H1' and rank=2;
/* blocks data loading start - BUDNI_DBP_Spec_H1_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_DBP_Spec_H1_Block',__file_format,__sheet_mnemonic,1);
insert into mmt_staging2.BUDNI_DBP_Spec_H1_Block
(
column2,column3,column4,column5,column6,column7,
column8,column9,column10,column11,column12,column13,
column14,column15,rank
)
select
column2,column3,column4,column5,column6,column7,column8,column9,column10,
column11,column12,column13,column14,column15,rank
from mmt_staging2.stg_process_table_budni_dbp
where rank_tag='BUDNI_DBP_Spec_H1';
update mmt_staging2.BUDNI_DBP_Spec_H1_Block
set ods_record=0 where rank in
(select distinct first_value(b.rank)
over (partition by b.column2 order by b.syspk) from mmt_staging2.BUDNI_DBP_Spec_H1_Block b);
execute 'update mmt_staging2.BUDNI_DBP_Spec_H1_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_DBP_Spec_H1_Block');
/* blocks data loading start - BUDNI_DBP_Spec_H1_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_DBP_Drawbar_Perf_Block',__file_format,__sheet_mnemonic,2);
insert into mmt_staging2.BUDNI_DBP_Drawbar_Perf_Block
(
column2,column3,column4,column5,column6,column7,
column8,column9,column10,column11,column12,column13,
column14,column15,column16,column17,column18,column19,rank
)
select
column2,column3,column4,column5,column6,column7,
column8,column9,column10,column11,column12,column13,column14,
column15,column16,column17,column18,column19,rank
from mmt_staging2.stg_process_table_budni_dbp a
where rank_tag='BUDNI_DBP_Drawbar_Perf' and rank <=22
order by rank;
update mmt_staging2.BUDNI_DBP_Drawbar_Perf_Block set make=__make,model=__model;
execute 'update mmt_staging2.BUDNI_DBP_Drawbar_Perf_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
update mmt_staging2.BUDNI_DBP_Drawbar_Perf_Block
set column2= column3 where column3 like 'i%';
update mmt_staging2.BUDNI_DBP_Drawbar_Perf_Block
set column3=null
where column3 like 'i%';
update mmt_staging2.BUDNI_DBP_Drawbar_Perf_Block a
set column2= b.first_value from (SELECT
rank, column2, value_partition, first_value(column2) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column2,
sum(case when column2 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_DBP_Drawbar_Perf_Block
ORDER BY rank ASC
) as q) b where a.rank = b.rank;
update mmt_staging2.BUDNI_DBP_Drawbar_Perf_Block
set ods_record=0 where column4 is null or
rank in
(select distinct first_value(b.rank)
over (partition by b.column2 order by b.syspk) from mmt_staging2.BUDNI_DBP_Drawbar_Perf_Block b);
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_DBP_Drawbar_Perf_Block');
end
$$ LANGUAGE plpgsql;

View File

@@ -0,0 +1,569 @@
drop function if exists mmt_staging2.fn_BUDNI_FLD_Block ;
CREATE OR REPLACE FUNCTION mmt_staging2.fn_BUDNI_FLD_Block(p_client_id int,p_function_id int, p_file_format text,
p_sheet_mnemonic text, p_file_syspk int)
RETURNS void AS $$
declare __make text;
declare __model text;
declare __client_id int :=p_client_id;
declare __function_id int :=p_function_id;
declare __file_format text :=p_file_format;
declare __sheet_mnemonic text :=p_sheet_mnemonic;
declare __file_syspk int :=p_file_syspk;
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 mmt_staging2.fn_BUDNI_FLD_Block(20,1,'BUDNI','BUDNI_FLD',261)
************************************************************************************/
SET search_path TO mmt_staging2;
/* rerunnability - delete block tables and update config tables to null */
truncate table mmt_staging2.BUDNI_FLD_Spec_H1_Block;
truncate table mmt_staging2.BUDNI_FLD_Impl_Test_Int;
truncate table mmt_staging2.BUDNI_FLD_Impl_Test_Block;
truncate table mmt_staging2.BUDNI_FLD_Cage_Wheel_Block;
truncate table mmt_staging2.BUDNI_FLD_Sum_Perf_Test_Int;
truncate table mmt_staging2.BUDNI_FLD_Sum_Perf_Test_Block;
truncate table mmt_staging2.BUDNI_FLD_Test_Obs_Summary_Block;
truncate table mmt_staging2.stg_specific_table_BUDNI_FLD;
truncate table mmt_staging2.stg_process_table_BUDNI_FLD;
execute 'delete from mmt_ods.fw_jobctrl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=null,
row_previous_number=null,
row_read_end=null,
run_time=null
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* transfer data from generic to specific for PTOBST */
execute 'insert into mmt_staging2.stg_specific_table_BUDNI_FLD
select * from mmt_staging1.mmt_staging_generic_table a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.file_syspk='||p_file_syspk||'';
/* trimming data */
update mmt_staging2.stg_specific_table_BUDNI_FLD set column3 = TRIM (TRAILING FROM column3 );
update mmt_staging2.stg_specific_table_BUDNI_FLD set column3 = TRIM (LEADING FROM column3 );
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified);
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified) ;
update mmt_ods.mmt_config set F1_source=F1_modified ;
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source);
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source) ;
/* keyword match in config table*/
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_staging2.stg_specific_table_BUDNI_FLD 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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* reverese update in process table for match*/
execute 'update mmt_staging2.stg_specific_table_BUDNI_FLD a
set is_rownumber_fetched=1
from mmt_ods.mmt_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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* update config files for row numbers start, end */
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_read_end= (select b.row_number_start
from mmt_ods.mmt_config b
where b.syspk=a.syspk+1 )
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* config file last field update as null otherwise it picks up next format row number*/
execute 'update mmt_ods.mmt_config a
set row_read_end = null
where f1_modified =''Field Performance Test Observations Summary''
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set run_time=current_timestamp
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* tagging ranks for each block in process table*/
execute 'insert into mmt_staging2.stg_process_table_BUDNI_FLD
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_BUDNI_FLD a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_BUDNI_FLD
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_BUDNI_FLD a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_BUDNI_FLD
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_BUDNI_FLD a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_BUDNI_FLD
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_BUDNI_FLD a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
/* fetching tractor model and make */
select column3 into __make from mmt_staging2.stg_process_table_BUDNI_FLD a
where rank_tag='BUDNI_FLD_Spec_H1' and rank=3;
select column4 into __model from mmt_staging2.stg_process_table_BUDNI_FLD a
where rank_tag='BUDNI_FLD_Spec_H1' and rank=3;
/* blocks data loading start - BUDNI_FLD_Spec_H1_block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_FLD_Spec_H1_block',__file_format,__sheet_mnemonic,1);
insert into mmt_staging2.BUDNI_FLD_Spec_H1_block
(
make,model,tractor_HP,rated_rpm,configuration,transmission_type,wheel_drive_type,rank)
select column3,column4,column5,column6,column7,column8,column9,rank
from mmt_staging2.stg_process_table_BUDNI_FLD where rank_tag='BUDNI_FLD_Spec_H1'
and rank=3;
execute 'update mmt_staging2.BUDNI_FLD_Spec_H1_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
update mmt_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 mmt_staging2.stg_process_table_BUDNI_FLD b
where b.rank_tag='BUDNI_FLD_Spec_H1'
and b.rank=5
and a.file_syspk=b.file_syspk;
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_FLD_Spec_H1_block');
insert into mmt_staging2.BUDNI_FLD_Impl_Test_Int
(
column3,column4,column5,column6,column7,
column8,column9,rank
)
select
column3,column4,column5,column6,column7,
column8,column9,rank
from mmt_staging2.stg_process_table_BUDNI_FLD a
where rank_tag ='BUDNI_FLD_Impl_Test' and rank <> 1
order by rank;
update mmt_staging2.BUDNI_FLD_Impl_Test_Int a
set column3= b.first_value from (SELECT
rank, column3, value_partition, first_value(column3) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column3,
sum(case when column3 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_FLD_Impl_Test_Int
ORDER BY rank ASC
) as q) b where a.rank = b.rank and a.rank <> 13 ;
update mmt_staging2.BUDNI_FLD_Impl_Test_Int a
set column4= b.first_value from (SELECT
rank, column4, value_partition, first_value(column4) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column4,
sum(case when column4 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_FLD_Impl_Test_Int
ORDER BY rank ASC
) as q) b where a.rank = b.rank and a.rank <> 13 ;
update mmt_staging2.BUDNI_FLD_Impl_Test_Int a
set column5= b.first_value from (SELECT
rank, column5, value_partition, first_value(column5) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column5,
sum(case when column5 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_FLD_Impl_Test_Int
ORDER BY rank ASC
) as q) b where a.rank = b.rank and a.rank <> 13 ;
update mmt_staging2.BUDNI_FLD_Impl_Test_Int a
set column6= b.first_value from (SELECT
rank, column6, value_partition, first_value(column6) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column6,
sum(case when column6 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_FLD_Impl_Test_Int
ORDER BY rank ASC
) as q) b where a.rank = b.rank and a.rank <> 13;
update mmt_staging2.BUDNI_FLD_Impl_Test_Int a
set column7= b.first_value from (SELECT
rank, column7, value_partition, first_value(column7) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column7,
sum(case when column7 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_FLD_Impl_Test_Int
ORDER BY rank ASC
) as q) b where a.rank = b.rank;
update mmt_staging2.BUDNI_FLD_Impl_Test_Int a
set column8= b.first_value from (SELECT
rank, column8, value_partition, first_value(column8) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column8,
sum(case when column8 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_FLD_Impl_Test_Int
ORDER BY rank ASC
) as q) b where a.rank = b.rank;
execute 'update mmt_staging2.BUDNI_FLD_Impl_Test_Int set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* blocks data loading - BUDNI_FLD_Impl_Test_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_FLD_Impl_Test_Block',__file_format,__sheet_mnemonic,2);
insert into mmt_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 mmt_staging2.BUDNI_FLD_Impl_Test_Int where ods_record=1
ORDER BY generate_series(1,15),rank,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 mmt_staging2.BUDNI_FLD_Impl_Test_Block where dummy_f is null;
execute 'update mmt_staging2.BUDNI_FLD_Impl_Test_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_FLD_Impl_Test_Block');
/* blocks data loading - BUDNI_FLD_Cage_Wheel_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_FLD_Cage_Wheel_Block',__file_format,__sheet_mnemonic,3);
insert into mmt_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 mmt_staging2.BUDNI_FLD_Impl_Test_Int where ods_record=1
ORDER BY generate_series(1,15),rank,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 mmt_staging2.BUDNI_FLD_Cage_Wheel_Block where dummy_f is null;
execute 'update mmt_staging2.BUDNI_FLD_Cage_Wheel_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_FLD_Cage_Wheel_Block');
insert into mmt_staging2.BUDNI_FLD_Sum_Perf_Test_Int
(
column3,column4,column5,column6,column7,rank
)
select
column3,column4,column5,column6,column7,rank
from mmt_staging2.stg_process_table_BUDNI_FLD a
where rank_tag ='BUDNI_FLD_Sum_Perf_Test' and rank <> 1
order by rank,column3 ;
update mmt_staging2.BUDNI_FLD_Sum_Perf_Test_Int set make=__make,model=__model;
execute 'update mmt_staging2.BUDNI_FLD_Sum_Perf_Test_Int set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* blocks data loading - BUDNI_FLD_Sum_Perf_Test_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_FLD_Sum_Perf_Test_Block',__file_format,__sheet_mnemonic,4);
insert into mmt_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 mmt_staging2.BUDNI_FLD_Sum_Perf_Test_Int where ods_record=1
ORDER BY generate_series(1,15),rank,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 mmt_staging2.BUDNI_FLD_Sum_Perf_Test_Block where dummy_f is null;
update mmt_staging2.BUDNI_FLD_Sum_Perf_Test_Block set make=__make,model=__model;
execute 'update mmt_staging2.BUDNI_FLD_Sum_Perf_Test_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_FLD_Sum_Perf_Test_Block');
/* blocks data loading - BUDNI_FLD_Test_Obs_Summary_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_FLD_Test_Obs_Summary_Block',__file_format,__sheet_mnemonic,5);
insert into mmt_staging2.BUDNI_FLD_Test_Obs_Summary_Block
(
column3,column4,column5,column6,column7,
column8,column9,rank
)
select
column3,column4,column5,column6,column7,
column8,column9,rank
from mmt_staging2.stg_process_table_BUDNI_FLD a
where rank_tag='BUDNI_FLD_Test_Obs_Summary' and rank <=6;
update mmt_staging2.BUDNI_FLD_Test_Obs_Summary_Block
set ods_record=0
where rank in (1,2);
update mmt_staging2.BUDNI_FLD_Test_Obs_Summary_Block a
set column4= b.first_value from (SELECT
rank, column4, value_partition, first_value(column4) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column4,
sum(case when column4 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_FLD_Test_Obs_Summary_Block
ORDER BY rank ASC
) as q) b where a.rank = b.rank;
update mmt_staging2.BUDNI_FLD_Test_Obs_Summary_Block a
set column5= b.first_value from (SELECT
rank, column5, value_partition, first_value(column5) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column5,
sum(case when column5 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_FLD_Test_Obs_Summary_Block
ORDER BY rank ASC
) as q) b where a.rank = b.rank;
update mmt_staging2.BUDNI_FLD_Test_Obs_Summary_Block a
set column6= b.first_value from (SELECT
rank, column6, value_partition, first_value(column6) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column6,
sum(case when column6 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_FLD_Test_Obs_Summary_Block
ORDER BY rank ASC
) as q) b where a.rank = b.rank;
update mmt_staging2.BUDNI_FLD_Test_Obs_Summary_Block a
set column7= b.first_value from (SELECT
rank, column7, value_partition, first_value(column7) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column7,
sum(case when column7 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_FLD_Test_Obs_Summary_Block
ORDER BY rank ASC
) as q) b where a.rank = b.rank;
update mmt_staging2.BUDNI_FLD_Test_Obs_Summary_Block a
set column8= b.first_value from (SELECT
rank, column8, value_partition, first_value(column8) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column8,
sum(case when column8 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_FLD_Test_Obs_Summary_Block
ORDER BY rank ASC
) as q) b where a.rank = b.rank;
update mmt_staging2.BUDNI_FLD_Test_Obs_Summary_Block a
set column9= b.first_value from (SELECT
rank, column9, value_partition, first_value(column9) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column9,
sum(case when column9 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_FLD_Test_Obs_Summary_Block
ORDER BY rank ASC
) as q) b where a.rank = b.rank;
update mmt_staging2.BUDNI_FLD_Test_Obs_Summary_Block set make=__make,model=__model;
execute 'update mmt_staging2.BUDNI_FLD_Test_Obs_Summary_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_FLD_Test_Obs_Summary_Block');
end
$$ LANGUAGE plpgsql;

View File

@@ -0,0 +1,533 @@
drop function if exists mmt_staging2.fn_budni_hdl_Block ;
CREATE OR REPLACE FUNCTION mmt_staging2.fn_budni_hdl_Block(p_client_id int,p_function_id int, p_file_format text,
p_sheet_mnemonic text, p_file_syspk int)
RETURNS void AS $$
declare __make text;
declare __model text;
declare __characteristic_A text;
declare __client_id int :=p_client_id;
declare __function_id int :=p_function_id;
declare __file_format text :=p_file_format;
declare __sheet_mnemonic text :=p_sheet_mnemonic;
declare __file_syspk int :=p_file_syspk;
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 mmt_staging2.fn_BUDNI_FLD_Block(20,1,'BUDNI','BUDNI_FLD',261);
************************************************************************************/
SET search_path TO mmt_staging2;
/* rerunnability - delete block tables and update config tables to null */
truncate table mmt_staging2.stg_specific_table_budni_hdl;
truncate table mmt_staging2.stg_process_table_budni_hdl;
truncate table mmt_staging2.budni_hdl_Spec_H1_Block;
truncate table mmt_staging2.budni_hdl_power_test_Block;
truncate table mmt_staging2.budni_hdl_Lifting_Capacity_Test_Block;
truncate table mmt_staging2.budni_hdl_Maintenance_of_lift_load_int;
truncate table mmt_staging2.budni_hdl_Maintenance_of_lift_load_Block;
truncate table mmt_staging2.budni_hdl_Test_Obs_Summary_Block;
execute 'delete from mmt_ods.fw_jobctrl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=null,
row_previous_number=null,
row_read_end=null,
run_time=null
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* transfer data from generic to specific for BUDNI */
execute 'insert into mmt_staging2.stg_specific_table_budni_hdl
select * from mmt_staging1.mmt_staging_generic_table a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.file_syspk='||p_file_syspk||'';
/* trimming data */
update mmt_staging2.stg_specific_table_budni_hdl set column3 = TRIM (TRAILING FROM column3 );
update mmt_staging2.stg_specific_table_budni_hdl set column3 = TRIM (LEADING FROM column3 );
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified);
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified) ;
update mmt_ods.mmt_config set F1_source=F1_modified ;
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source);
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source);
/* keyword match in config table*/
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_staging2.stg_specific_table_budni_hdl 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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* reverese update in process table for match*/
execute 'update mmt_staging2.stg_specific_table_budni_hdl a
set is_rownumber_fetched=1
from mmt_ods.mmt_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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* update config files for row numbers start, end */
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_read_end= (select b.row_number_start
from mmt_ods.mmt_config b
where b.syspk=a.syspk+1 )
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* config file last field update as null otherwise it picks up next format row number*/
execute 'update mmt_ods.mmt_config a
set row_read_end = null
where f1_modified =''Power Lift and Hydraulic Pump Performance Test Observations Summary''
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* tagging ranks for each block in process table*/
execute 'update mmt_ods.mmt_config a
set run_time=current_timestamp
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'insert into mmt_staging2.stg_process_table_budni_hdl
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_budni_hdl a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_budni_hdl
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_budni_hdl a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_budni_hdl
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_budni_hdl a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_budni_hdl
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_budni_hdl a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_budni_hdl
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_budni_hdl a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
/* fetching tractor model and make */
select column3 into __make from mmt_staging2.stg_process_table_budni_hdl a
where rank_tag='BUDNI_HDL_Spec_H1' and rank=3;
select column4 into __model from mmt_staging2.stg_process_table_budni_hdl a
where rank_tag='BUDNI_HDL_Spec_H1' and rank=3;
/* blocks data loading start - budni_hdl_Spec_H1_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_HDL_Spec_H1_block',__file_format,__sheet_mnemonic,1);
insert into mmt_staging2.budni_hdl_Spec_H1_Block
(
tractor_model,
tractor_make,
tractor_HP,
rated_rpm,
hydraulic_type,
Pump_speed_at_rated_engine_speed_rpm,
Steering_Type,
Oil,rank
)
select
column3,column4,column5,column6,column7,column8,column9,column10,rank
from mmt_staging2.stg_process_table_budni_hdl
where rank_tag='BUDNI_HDL_Spec_H1' and rank=3;
execute 'update mmt_staging2.budni_hdl_Spec_H1_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
update mmt_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 mmt_staging2.stg_process_table_budni_hdl b
where b.rank_tag='BUDNI_HDL_Spec_H1'
and b.rank=6
and a.file_syspk=b.file_syspk;
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_HDL_Spec_H1_block');
/* blocks data loading - budni_hdl_power_test_block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'budni_hdl_power_test_block',__file_format,__sheet_mnemonic,2);
insert into mmt_staging2.budni_hdl_power_test_block (dummy_f) values('dummy');
update mmt_staging2.budni_hdl_power_test_block
set Pump_delivery_rate_at_minimum_pressure_and_rated_engine_speed_l_min= (select column3
from mmt_staging2.stg_process_table_budni_hdl
where rank_tag ='BUDNI_HDL_Power_Test' and rank=3)
where dummy_f='dummy';
update mmt_staging2.budni_hdl_power_test_block
set Maximum_hydraulic_power_kW= (select column5
from mmt_staging2.stg_process_table_budni_hdl
where rank_tag ='BUDNI_HDL_Power_Test' and rank=3)
where dummy_f='dummy';
update mmt_staging2.budni_hdl_power_test_block
set Pump_delivery_rate_at_maximum_hydraulic_power_l_min= (select column7
from mmt_staging2.stg_process_table_budni_hdl
where rank_tag ='BUDNI_HDL_Power_Test' and rank=3)
where dummy_f='dummy';
update mmt_staging2.budni_hdl_power_test_block
set Pressure_at_maximum_hydraulic_power_MPa= (select column9
from mmt_staging2.stg_process_table_budni_hdl
where rank_tag ='BUDNI_HDL_Power_Test' and rank=3)
where dummy_f='dummy';
update mmt_staging2.budni_hdl_power_test_block
set Sustained_pressure_of_the_open_relief_valve_MPa= (select column11
from mmt_staging2.stg_process_table_budni_hdl
where rank_tag ='BUDNI_HDL_Power_Test' and rank=3)
where dummy_f='dummy';
update mmt_staging2.budni_hdl_power_test_block
set tapping_point_relief_valve_test = (select column4
from mmt_staging2.stg_process_table_budni_hdl
where rank_tag ='BUDNI_HDL_Lifting_Capacity_Test' and rank=2)
where dummy_f='dummy';
update mmt_staging2.budni_hdl_power_test_block
set tapping_point_Pump_performance_test= (select column4
from mmt_staging2.stg_process_table_budni_hdl
where rank_tag ='BUDNI_HDL_Lifting_Capacity_Test' and rank=3)
where dummy_f='dummy';
update mmt_staging2.budni_hdl_power_test_block
set tapping_point_Temperature_of_hydraulic_fluid_C= (select column4
from mmt_staging2.stg_process_table_budni_hdl
where rank_tag ='BUDNI_HDL_Lifting_Capacity_Test' and rank=4)
where dummy_f='dummy';
update mmt_staging2.BUDNI_HDL_Power_Test_Block set make=__make,model=__model;
execute 'update mmt_staging2.BUDNI_HDL_Power_Test_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
update mmt_staging2.BUDNI_HDL_Power_Test_Block
set ods_record=0 where
rank in (1,2);
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_HDL_Power_Test_Block');
/* blocks data loading - budni_hdl_Lifting_Capacity_Test_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'budni_hdl_Lifting_Capacity_Test_Block',__file_format,__sheet_mnemonic,3);
insert into mmt_staging2.budni_hdl_Lifting_Capacity_Test_Block
(
column5,column6,column7,
column8,column9,column10,column11,rank
)
select
column5,column6,column7,
column8,column9,column10,column11,rank
from mmt_staging2.stg_process_table_budni_hdl a
where rank_tag='BUDNI_HDL_Lifting_Capacity_Test';
update mmt_staging2.budni_hdl_Lifting_Capacity_Test_Block set make=__make,model=__model;
execute 'update mmt_staging2.budni_hdl_Lifting_Capacity_Test_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
update mmt_staging2.budni_hdl_Lifting_Capacity_Test_Block
set ods_record=0 where
rank in (1,2);
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'budni_hdl_Lifting_Capacity_Test_Block');
insert into mmt_staging2.budni_hdl_Maintenance_of_lift_load_int
(
column3,column4,column5,column6,column7,
column8,column9,column10,column11,column12,rank
)
select
column3,column4,column5,column6,column7,
column8,column9,column10,column11,column12,rank
from mmt_staging2.stg_process_table_budni_hdl a
where rank_tag='BUDNI_HDL_Maintenance_Of_Lift_Load';
update mmt_staging2.budni_hdl_Maintenance_of_lift_load_int
set ods_record=0 where
rank=1;
/* blocks data loading - PTOBST_RPT_PTO_performance_report_block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'budni_hdl_Maintenance_of_lift_load_Block',__file_format,__sheet_mnemonic,4);
insert into mmt_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 mmt_staging2.budni_hdl_Maintenance_of_lift_load_int where rank in (2,3)
ORDER BY generate_series(1,15),rank,2'
) t (col text,a_1 text,a_2 text);
update mmt_staging2.budni_hdl_Maintenance_of_lift_load_block
set Force_applied_at_the_frame_kN =(select column5
from mmt_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 mmt_staging2.budni_hdl_Maintenance_of_lift_load_block
set Temperature_of_hydraulic_fluid_at_the_start_of_test_C =(select column5
from mmt_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 mmt_staging2.budni_hdl_Maintenance_of_lift_load_block where dummy_f is null;
update mmt_staging2.budni_hdl_Maintenance_of_lift_load_block set make=__make,model=__model;
execute 'update mmt_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_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'budni_hdl_Maintenance_of_lift_load_block');
/* blocks data loading - budni_hdl_Test_Obs_Summary_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'budni_hdl_Test_Obs_Summary_Block',__file_format,__sheet_mnemonic,5);
insert into mmt_staging2.budni_hdl_Test_Obs_Summary_Block
(
column3,column4,column5,column6,column7,
column8,column9,column10,column11,column12,rank
)
select
column3,column4,column5,column6,column7,
column8,column9,column10,column11,column12,rank
from mmt_staging2.stg_process_table_budni_hdl a
where rank_tag='BUDNI_HDL_Test_Obs_Summary' and rank not in (8,9);
update mmt_staging2.budni_hdl_Test_Obs_Summary_Block a
set column3= b.first_value from (SELECT
rank, column3, value_partition, first_value(column3) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column3,
sum(case when column3 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.budni_hdl_Test_Obs_Summary_Block
ORDER BY rank ASC
) as q) b where a.rank = b.rank;
update mmt_staging2.budni_hdl_Test_Obs_Summary_Block a
set column4= b.first_value from (SELECT
rank, column4, value_partition, first_value(column4) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column4,
sum(case when column4 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.budni_hdl_Test_Obs_Summary_Block
ORDER BY rank ASC
) as q) b where a.rank = b.rank;
update mmt_staging2.budni_hdl_Test_Obs_Summary_Block a
set column5= b.first_value from (SELECT
rank, column5, value_partition, first_value(column5) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column5,
sum(case when column5 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.budni_hdl_Test_Obs_Summary_Block
ORDER BY rank ASC
) as q) b where a.rank = b.rank;
update mmt_staging2.budni_hdl_Test_Obs_Summary_Block a
set column7= b.first_value from (SELECT
rank, column7, value_partition, first_value(column7) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column7,
sum(case when column7 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.budni_hdl_Test_Obs_Summary_Block
ORDER BY rank ASC
) as q) b where a.rank = b.rank;
update mmt_staging2.budni_hdl_Test_Obs_Summary_Block a
set column8= b.first_value from (SELECT
rank, column8, value_partition, first_value(column8) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column8,
sum(case when column8 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.budni_hdl_Test_Obs_Summary_Block
ORDER BY rank ASC
) as q) b where a.rank = b.rank;
update mmt_staging2.budni_hdl_Test_Obs_Summary_Block a
set column11= b.first_value from (SELECT
rank, column11, value_partition, first_value(column11) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column11,
sum(case when column11 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.budni_hdl_Test_Obs_Summary_Block
ORDER BY rank ASC
) as q) b where a.rank = b.rank;
update mmt_staging2.budni_hdl_Test_Obs_Summary_Block a
set column12= b.first_value from (SELECT
rank, column12, value_partition, first_value(column12) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column12,
sum(case when column12 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.budni_hdl_Test_Obs_Summary_Block
ORDER BY rank ASC
) as q) b where a.rank = b.rank;
select column4 into __characteristic_A
from mmt_staging2.budni_hdl_Test_Obs_Summary_Block where rank=3;
update mmt_staging2.budni_hdl_Test_Obs_Summary_Block
set column4=concat(column4,'. ',__characteristic_A,' -',column5) where ods_record =1;
update mmt_staging2.budni_hdl_Test_Obs_Summary_Block set make=__make,model=__model;
execute 'update mmt_staging2.budni_hdl_Test_Obs_Summary_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
update mmt_staging2.budni_hdl_Test_Obs_Summary_Block
set ods_record=0 where
rank in (1,2,3);
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'budni_hdl_Test_Obs_Summary_Block');
end
$$ LANGUAGE plpgsql;

View File

@@ -0,0 +1,418 @@
drop function if exists mmt_staging2.fn_BUDNI_HLG_Block ;
CREATE OR REPLACE FUNCTION mmt_staging2.fn_BUDNI_HLG_Block(p_client_id int,p_function_id int, p_file_format text,
p_sheet_mnemonic text, p_file_syspk int)
RETURNS void AS $$
declare __make text;
declare __model text;
declare __characteristic_1 text;
declare __characteristic_2 text;
declare __characteristic_3 text;
declare __client_id int :=p_client_id;
declare __function_id int :=p_function_id;
declare __file_format text :=p_file_format;
declare __sheet_mnemonic text :=p_sheet_mnemonic;
declare __file_syspk int :=p_file_syspk;
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 mmt_staging2.fn_BUDNI_HLG_Block(20,1,'BUDNI','BUDNI_HLG',261);
************************************************************************************/
SET search_path TO mmt_staging2;
/* rerunnability - delete block tables and update config tables to null */
truncate table mmt_staging2.BUDNI_HLG_Spec_H1_Block;
truncate table mmt_staging2.BUDNI_HLG_Perf_Test_int;
truncate table mmt_staging2.BUDNI_HLG_Perf_Test_block;
truncate table mmt_staging2.BUDNI_HLG_Test_Obs_Summary_Block;
truncate table mmt_staging2.stg_specific_table_BUDNI_HLG;
truncate table mmt_staging2.stg_process_table_BUDNI_HLG;
execute 'delete from mmt_ods.fw_jobctrl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=null,
row_previous_number=null,
row_read_end=null,
run_time=null
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* transfer data from generic to specific for BUDNI */
execute 'insert into mmt_staging2.stg_specific_table_BUDNI_HLG
select * from mmt_staging1.mmt_staging_generic_table a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.file_syspk='||p_file_syspk||'';
/* trimming data */
update mmt_staging2.stg_specific_table_BUDNI_HLG set column3 = TRIM (TRAILING FROM column3 );
update mmt_staging2.stg_specific_table_BUDNI_HLG set column3 = TRIM (LEADING FROM column3 );
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified);
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified) ;
update mmt_ods.mmt_config set F1_source=F1_modified;
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source);
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source) ;
/* keyword match in config table*/
execute 'update mmt_ods.mmt_config a set f1_source = replace(f1_source,''_1'','''')
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* reverese update in process table for match*/
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* update config files for row numbers start, end */
execute 'update mmt_staging2.stg_specific_table_BUDNI_HLG a
set is_rownumber_fetched=1
from mmt_ods.mmt_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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a set f1_source = replace(f1_source,''_2'','''')
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_staging2.stg_specific_table_BUDNI_HLG a
set is_rownumber_fetched=1
from mmt_ods.mmt_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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_read_end= (select b.row_number_start
from mmt_ods.mmt_config b
where b.syspk=a.syspk+1 )
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* config file last field update as null otherwise it picks up next format row number*/
execute 'update mmt_ods.mmt_config a
set row_read_end = null
where f1_modified =''Haulage Performance Test Observations Summary''
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set run_time=current_timestamp
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* tagging ranks for each block in process table*/
execute 'insert into mmt_staging2.stg_process_table_BUDNI_HLG
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_BUDNI_HLG a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_BUDNI_HLG
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_BUDNI_HLG a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_BUDNI_HLG
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_BUDNI_HLG a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
/* fetching tractor model and make */
select column3 into __make from mmt_staging2.stg_process_table_BUDNI_HLG a
where rank_tag='BUDNI_HLG_Spec_H1' and rank=3;
select column4 into __model from mmt_staging2.stg_process_table_BUDNI_HLG a
where rank_tag='BUDNI_HLG_Spec_H1' and rank=3;
/* blocks data loading start - BUDNI_HLG_Spec_H1_block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_HLG_Spec_H1_block',__file_format,__sheet_mnemonic,1);
insert into mmt_staging2.BUDNI_HLG_Spec_H1_block
(
make,model,tractor_HP,rated_rpm,configuration,transmission_type,wheel_drive_type,rank)
select column3,column4,column5,column6,column7,column8,column9,rank
from mmt_staging2.stg_process_table_BUDNI_HLG where rank_tag='BUDNI_HLG_Spec_H1'
and rank=3;
execute 'update mmt_staging2.BUDNI_HLG_Spec_H1_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
update mmt_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 mmt_staging2.stg_process_table_BUDNI_HLG b
where b.rank_tag='BUDNI_HLG_Spec_H1'
and b.rank=5
and a.file_syspk=b.file_syspk;
update mmt_staging2.BUDNI_HLG_Spec_H1_Block
set ods_record=0 where rank in(1,2);
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_HLG_Spec_H1_Block');
insert into mmt_staging2.BUDNI_HLG_Perf_Test_int
(
column3,column6,column8,rank
)
select
column3,column6,column8,rank
from mmt_staging2.stg_process_table_BUDNI_HLG a
where rank_tag ='BUDNI_HLG_Perf_Test'
order by rank,column3;
update mmt_staging2.BUDNI_HLG_Perf_Test_int set ods_record=0 where rank =1;
update mmt_staging2.BUDNI_HLG_Perf_Test_int set make=__make,model=__model;
execute 'update mmt_staging2.BUDNI_HLG_Perf_Test_int set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* blocks data loading - budni_hlg_perf_test_block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'budni_hlg_perf_test_block',__file_format,__sheet_mnemonic,2);
insert into mmt_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 mmt_staging2.BUDNI_HLG_Perf_Test_int where ods_record=1
ORDER BY generate_series(1,15),rank,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 mmt_staging2.BUDNI_HLG_Perf_Test_block where dummy_f is null;
update mmt_staging2.BUDNI_HLG_Perf_Test_block set make=__make,model=__model;
execute 'update mmt_staging2.BUDNI_HLG_Perf_Test_block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_HLG_Perf_Test_block');
/* blocks data loading - BUDNI_HLG_Perf_Test_block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_HLG_Perf_Test_block',__file_format,__sheet_mnemonic,3);
insert into mmt_staging2.BUDNI_HLG_Test_Obs_Summary_Block
(
column3,column4,column5,column6,column7,
column8,column9,rank
)
select
column3,column4,column5,column6,column7,
column8,column9,rank
from mmt_staging2.stg_process_table_BUDNI_HLG a
where rank_tag='BUDNI_HLG_Test_Obs_Summary' and rank <=11
order by rank;
update mmt_staging2.BUDNI_HLG_Test_Obs_Summary_Block
set ods_record=0 where
rank in
(select distinct first_value(b.rank)
over (partition by b.column3 order by b.syspk) from mmt_staging2.BUDNI_HLG_Test_Obs_Summary_Block b);
update mmt_staging2.BUDNI_HLG_Test_Obs_Summary_Block a
set column3= b.first_value from (SELECT
rank, column3, value_partition, first_value(column3) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column3,
sum(case when column3 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_HLG_Test_Obs_Summary_Block
ORDER BY rank ASC
) as q) b where a.rank = b.rank ;
update mmt_staging2.BUDNI_HLG_Test_Obs_Summary_Block a
set column5= b.first_value from (SELECT
rank, column5, value_partition, first_value(column5) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column5,
sum(case when column5 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_HLG_Test_Obs_Summary_Block
ORDER BY rank ASC
) as q) b where a.rank = b.rank ;
update mmt_staging2.BUDNI_HLG_Test_Obs_Summary_Block a
set column7= b.first_value from (SELECT
rank, column7, value_partition, first_value(column7) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column7,
sum(case when column7 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_HLG_Test_Obs_Summary_Block
ORDER BY rank ASC
) as q) b where a.rank = b.rank ;
update mmt_staging2.BUDNI_HLG_Test_Obs_Summary_Block a
set column8= b.first_value from (SELECT
rank, column8, value_partition, first_value(column8) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column8,
sum(case when column8 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_HLG_Test_Obs_Summary_Block
ORDER BY rank ASC
) as q) b where a.rank = b.rank ;
update mmt_staging2.BUDNI_HLG_Test_Obs_Summary_Block a
set column9= b.first_value from (SELECT
rank, column9, value_partition, first_value(column9) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column9,
sum(case when column9 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_HLG_Test_Obs_Summary_Block
ORDER BY rank ASC
) as q) b where a.rank = b.rank ;
select column4 into __characteristic_1 from mmt_staging2.BUDNI_HLG_Test_Obs_Summary_Block
where rank=3;
select column4 into __characteristic_2 from mmt_staging2.BUDNI_HLG_Test_Obs_Summary_Block
where rank=6;
select column4 into __characteristic_3 from mmt_staging2.BUDNI_HLG_Test_Obs_Summary_Block
where rank=9;
update mmt_staging2.BUDNI_HLG_Test_Obs_Summary_Block
set column4=concat(__characteristic_1,'-',column4) where rank=4;
update mmt_staging2.BUDNI_HLG_Test_Obs_Summary_Block
set column4=concat(__characteristic_1,'-',column4) where rank=5;
update mmt_staging2.BUDNI_HLG_Test_Obs_Summary_Block
set column4=concat(__characteristic_2,'-',column4) where rank=7;
update mmt_staging2.BUDNI_HLG_Test_Obs_Summary_Block
set column4=concat(__characteristic_2,'-',column4) where rank=8;
update mmt_staging2.BUDNI_HLG_Test_Obs_Summary_Block
set column4=concat(__characteristic_3,'-',column4) where rank=10;
update mmt_staging2.BUDNI_HLG_Test_Obs_Summary_Block
set column4=concat(__characteristic_3,'-',column4) where rank=11;
update mmt_staging2.BUDNI_HLG_Test_Obs_Summary_Block set make=__make,model=__model;
execute 'update mmt_staging2.BUDNI_HLG_Test_Obs_Summary_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_HLG_Test_Obs_Summary_Block');
end
$$ LANGUAGE plpgsql;

View File

@@ -0,0 +1,227 @@
drop function if exists mmt_staging2.fn_BUDNI_LCG_Block ;
CREATE OR REPLACE FUNCTION mmt_staging2.fn_BUDNI_LCG_Block(p_client_id int,p_function_id int, p_file_format text,
p_sheet_mnemonic text, p_file_syspk int)
RETURNS void AS $$
declare __make text;
declare __model text;
declare __client_id int :=p_client_id;
declare __function_id int :=p_function_id;
declare __file_format text :=p_file_format;
declare __sheet_mnemonic text :=p_sheet_mnemonic;
declare __file_syspk int :=p_file_syspk;
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 mmt_staging2.fn_BUDNI_LCG_Block(20,1,'BUDNI','BUDNI_LCG',261);
************************************************************************************/
SET search_path TO mmt_staging2;
/* rerunnability - delete block tables and update config tables to null */
truncate table mmt_staging2.BUDNI_LCG_Spec_H1_Block;
truncate table mmt_staging2.BUDNI_LCG_Gravity_Test_Block;
truncate table mmt_staging2.stg_specific_table_BUDNI_LCG;
truncate table mmt_staging2.stg_process_table_BUDNI_LCG;
execute 'delete from mmt_ods.fw_jobctrl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=null,
row_previous_number=null,
row_read_end=null,
run_time=null
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* transfer data from generic to specific for BUDNI */
execute 'insert into mmt_staging2.stg_specific_table_BUDNI_LCG
select * from mmt_staging1.mmt_staging_generic_table a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.file_syspk='||p_file_syspk||'';
/* trimming data */
update mmt_staging2.stg_specific_table_BUDNI_LCG set column3 = TRIM (TRAILING FROM column3 );
update mmt_staging2.stg_specific_table_BUDNI_LCG set column3 = TRIM (LEADING FROM column3 );
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified);
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified) ;
update mmt_ods.mmt_config set F1_source=F1_modified;
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source);
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source) ;
/* keyword match in config table*/
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_staging2.stg_specific_table_BUDNI_LCG 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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* reverese update in process table for match*/
execute 'update mmt_staging2.stg_specific_table_BUDNI_LCG a
set is_rownumber_fetched=1
from mmt_ods.mmt_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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* update config files for row numbers start, end */
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_read_end= (select b.row_number_start
from mmt_ods.mmt_config b
where b.syspk=a.syspk+1 )
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* config file last field update as null otherwise it picks up next format row number*/
execute 'update mmt_ods.mmt_config a
set row_read_end = null
where f1_modified =''Location of centre of Gravity Test''
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set run_time=current_timestamp
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* tagging ranks for each block in process table*/
execute 'insert into mmt_staging2.stg_process_table_BUDNI_LCG
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_BUDNI_LCG a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_BUDNI_LCG
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_BUDNI_LCG a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
/* fetching tractor model and make */
select column3 into __make from mmt_staging2.stg_process_table_BUDNI_LCG a
where rank_tag='BUDNI_LCG_Spec_H1' and rank=3;
select column4 into __model from mmt_staging2.stg_process_table_BUDNI_LCG a
where rank_tag='BUDNI_LCG_Spec_H1' and rank=3;
/* blocks data loading start - BUDNI_LCG_Spec_H1_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_LCG_Spec_H1_Block',__file_format,__sheet_mnemonic,1);
insert into mmt_staging2.BUDNI_LCG_Spec_H1_Block
(
make,model,Tractor_HP, Rated_RPM,configuration,Transmission_type,
Wheel_Drive_type,rank
)
select
column3,column4,column5,column6,column7,column8,column9,rank
from mmt_staging2.stg_process_table_BUDNI_LCG
where rank_tag='BUDNI_LCG_Spec_H1' and rank=3;
execute 'update mmt_staging2.BUDNI_LCG_Spec_H1_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
update mmt_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 mmt_staging2.stg_process_table_budni_lcg b
where b.rank_tag='BUDNI_LCG_Spec_H1'
and b.rank=6
and a.file_syspk=b.file_syspk;
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_LCG_Spec_H1_block');
/* blocks data loading -BUDNI_LCG_Gravity_Test_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_LCG_Gravity_Test_Block',__file_format,__sheet_mnemonic,2);
insert into mmt_staging2.BUDNI_LCG_Gravity_Test_Block
(
column2,column3,column4,column5,column6,column7,
column8,rank
)
select
column2,column3,column4,column5,column6,column7,
column8,rank
from mmt_staging2.stg_process_table_BUDNI_LCG a
where rank_tag='BUDNI_LCG_Gravity_Test' and rank <=5
order by rank;
update mmt_staging2.BUDNI_LCG_Gravity_Test_Block set make=__make,model=__model;
execute 'update mmt_staging2.BUDNI_LCG_Gravity_Test_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
update mmt_staging2.BUDNI_LCG_Gravity_Test_Block a
set column3= b.first_value from (SELECT
rank, column3, value_partition, first_value(column3) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column3,
sum(case when column3 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_LCG_Gravity_Test_Block
ORDER BY rank ASC
) as q) b where a.rank = b.rank ;
update mmt_staging2.BUDNI_LCG_Gravity_Test_Block
set ods_record=0 where
rank in (1,2);
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_LCG_Gravity_Test_Block');
end
$$ LANGUAGE plpgsql;

View File

@@ -0,0 +1,483 @@
drop function if exists mmt_staging2.fn_BUDNI_NMT_Block ;
CREATE OR REPLACE FUNCTION mmt_staging2.fn_BUDNI_NMT_Block(p_client_id int,p_function_id int, p_file_format text,
p_sheet_mnemonic text, p_file_syspk int)
RETURNS void AS $$
declare __make text;
declare __model text;
declare __client_id int :=p_client_id;
declare __function_id int :=p_function_id;
declare __file_format text :=p_file_format;
declare __sheet_mnemonic text :=p_sheet_mnemonic;
declare __file_syspk int :=p_file_syspk;
begin
SET search_path TO mmt_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 mmt_staging2.fn_BUDNI_NMT_Block(20,1,'BUDNI','BUDNI_NMT',261);
************************************************************************************/
/* rerunnability - delete block tables and update config tables to null */
truncate table mmt_staging2.BUDNI_NMT_Spec_H1_Block;
truncate table mmt_staging2.budni_nmt_noise_at_bystander_position_block;
truncate table mmt_staging2.BUDNI_NMT_Atmos_Cond_1_Block;
truncate table mmt_staging2.BUDNI_NMT_Meas_Results_1_Block;
truncate table mmt_staging2.budni_nmt_noise_at_operator_ear_level_block;
truncate table mmt_staging2.BUDNI_NMT_Atmos_Cond_2_Block;
truncate table mmt_staging2.BUDNI_NMT_Meas_Results_2_Block;
truncate table mmt_staging2.BUDNI_NMT_Test_Obs_Summary_Block;
truncate table mmt_staging2.stg_specific_table_BUDNI_NMT;
truncate table mmt_staging2.stg_process_table_BUDNI_NMT;
execute 'delete from mmt_ods.fw_jobctrl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=null,
row_previous_number=null,
row_read_end=null,
run_time=null
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* transfer data from generic to specific for BUDNI */
execute 'insert into mmt_staging2.stg_specific_table_BUDNI_NMT
select * from mmt_staging1.mmt_staging_generic_table a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.file_syspk='||p_file_syspk||'';
/* trimming data */
update mmt_staging2.stg_specific_table_BUDNI_LCG set column3 = TRIM (TRAILING FROM column3 );
update mmt_staging2.stg_specific_table_BUDNI_LCG set column3 = TRIM (LEADING FROM column3 );
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified);
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified) ;
update mmt_ods.mmt_config set F1_source=F1_modified;
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source);
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source) ;
/* keyword match in config table*/
execute 'update mmt_ods.mmt_config a set f1_source = replace(f1_source,''_1'','''')
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_staging2.stg_specific_table_BUDNI_NMT 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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* reverese update in process table for match*/
execute 'update mmt_staging2.stg_specific_table_BUDNI_NMT a
set is_rownumber_fetched=1
from mmt_ods.mmt_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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a set f1_source = replace(f1_source,''_2'','''')
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_staging2.stg_specific_table_BUDNI_NMT 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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_staging2.stg_specific_table_BUDNI_NMT a
set is_rownumber_fetched=1
from mmt_ods.mmt_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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_read_end= (select b.row_number_start
from mmt_ods.mmt_config b
where b.syspk=a.syspk+1 )
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* config file last field update as null otherwise it picks up next format row number*/
execute 'update mmt_ods.mmt_config a
set row_read_end = null
where f1_modified =''Noise Measurement Test Observations Summary''
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set run_time=current_timestamp
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* tagging ranks for each block in process table*/
execute 'insert into mmt_staging2.stg_process_table_BUDNI_NMT
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_BUDNI_NMT a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_BUDNI_NMT
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_BUDNI_NMT a
join mmt_ods.mmt_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 bystanders position: Noise Measurement Test''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_BUDNI_NMT
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_BUDNI_NMT a
join mmt_ods.mmt_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 operators ear level: Noise Measurement Test''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_BUDNI_NMT
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_BUDNI_NMT a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
/* fetching tractor model and make */
select column3 into __make from mmt_staging2.stg_process_table_BUDNI_NMT a
where rank_tag='BUDNI_NMT_Spec_H1' and rank=3;
select column4 into __model from mmt_staging2.stg_process_table_BUDNI_NMT a
where rank_tag='BUDNI_NMT_Spec_H1' and rank=3;
/* blocks data loading start - budni_nmt_Spec_H1_block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'budni_nmt_Spec_H1_block',__file_format,__sheet_mnemonic,1);
insert into mmt_staging2.budni_nmt_Spec_H1_block
(
make,model,tractor_HP,rated_rpm,configuration,transmission_type,wheel_drive_type,rank)
select column3,column4,column5,column6,column7,column8,column9,rank
from mmt_staging2.stg_process_table_budni_nmt where rank_tag='BUDNI_NMT_Spec_H1'
and rank=3;
execute 'update mmt_staging2.BUDNI_NMT_Spec_H1_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
update mmt_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 mmt_staging2.stg_process_table_budni_nmt b
where b.rank_tag='BUDNI_NMT_Spec_H1'
and b.rank=5
and a.file_syspk=b.file_syspk;
update mmt_staging2.BUDNI_NMT_Spec_H1_Block
set ods_record=0 where rank in(1,2);
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_NMT_Spec_H1_Block');
/* blocks data loading - budni_nmt_noise_at_bystander_position_block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'budni_nmt_noise_at_bystander_position_block',__file_format,__sheet_mnemonic,2);
insert into mmt_staging2.budni_nmt_noise_at_bystander_position_block
(
column2,column3,column4,column5,column6,column7,
column8,column9,rank
)
select
column2,column3,column4,column5,column6,column7,
column8,column9,rank
from mmt_staging2.stg_process_table_BUDNI_NMT a
where rank_tag ='BUDNI_NMT_Noise_at_bystander_position';
update mmt_staging2.budni_nmt_noise_at_bystander_position_block
set column2=column3 where rank=1;
update mmt_staging2.budni_nmt_noise_at_bystander_position_block a
set column2= b.first_value from (SELECT
rank, column2, value_partition, first_value(column2) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column2,
sum(case when column2 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.budni_nmt_noise_at_bystander_position_block
ORDER BY rank ASC
) as q) b where a.rank = b.rank ;
update mmt_staging2.budni_nmt_noise_at_bystander_position_Block
set ods_record=0 where rank in(1,2);
update mmt_staging2.budni_nmt_noise_at_bystander_position_block set make=__make,model=__model;
execute 'update mmt_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_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'budni_nmt_noise_at_bystander_position_block');
/* blocks data loading - BUDNI_NMT_Atmos_Cond_1_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_NMT_Atmos_Cond_1_Block',__file_format,__sheet_mnemonic,3);
insert into mmt_staging2.BUDNI_NMT_Atmos_Cond_1_Block
(
column2,column3,column4,column5,column6,column7,
column8,column9,rank
)
select
column2,column3,column4,column5,column6,column7,
column8,column9,rank
from mmt_staging2.budni_nmt_noise_at_bystander_position_block a
where rank <=4;
update mmt_staging2.BUDNI_NMT_Atmos_Cond_1_Block set make=__make,model=__model;
execute 'update mmt_staging2.BUDNI_NMT_Atmos_Cond_1_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
update mmt_staging2.BUDNI_NMT_Atmos_Cond_1_Block
set ods_record=0 where
rank in (1,2,3);
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_NMT_Atmos_Cond_1_Block ');
/* blocks data loading - BUDNI_NMT_Meas_Results_1_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_NMT_Meas_Results_1_Block',__file_format,__sheet_mnemonic,4);
insert into mmt_staging2.BUDNI_NMT_Meas_Results_1_Block
(
column2,column3,column4,column5,column6,column7,
column8,rank
)
select
column2,column3,column4,column5,column6,column7,
column8,rank
from mmt_staging2.budni_nmt_noise_at_bystander_position_block a
where rank>4;
update mmt_staging2.BUDNI_NMT_Meas_Results_1_Block
set ods_record=0 where
rank=5;
update mmt_staging2.BUDNI_NMT_Meas_Results_1_Block
set column3=column4 where column3 is null ;
update mmt_staging2.BUDNI_NMT_Meas_Results_1_Block set make=__make,model=__model;
execute 'update mmt_staging2.BUDNI_NMT_Meas_Results_1_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_NMT_Meas_Results_1_Block ');
/* blocks data loading - BUDNI_NMT_Noise_at_operator_ear_level_block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_NMT_Noise_at_operator_ear_level_block',__file_format,__sheet_mnemonic,5);
insert into mmt_staging2.BUDNI_NMT_Noise_at_operator_ear_level_block
(
column2,column3,column4,column5,column6,column7,
column8,column9,rank
)
select
column2,column3,column4,column5,column6,column7,
column8,column9,rank
from mmt_staging2.stg_process_table_BUDNI_NMT a
where rank_tag ='BUDNI_NMT_Noise_at_operator_ear_level';
update mmt_staging2.BUDNI_NMT_Noise_at_operator_ear_level_block set make=__make,model=__model;
execute 'update mmt_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_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
update mmt_staging2.BUDNI_NMT_Noise_at_operator_ear_level_block
set column2=column3 where rank=1;
update mmt_staging2.BUDNI_NMT_Noise_at_operator_ear_level_block a
set column2= b.first_value from (SELECT
rank, column2, value_partition, first_value(column2) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column2,
sum(case when column2 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_NMT_Noise_at_operator_ear_level_block
ORDER BY rank ASC
) as q) b where a.rank = b.rank ;
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_NMT_Noise_at_operator_ear_level_block');
/* blocks data loading -BUDNI_NMT_Atmos_Cond_2_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_NMT_Atmos_Cond_2_Block',__file_format,__sheet_mnemonic,6);
insert into mmt_staging2.BUDNI_NMT_Atmos_Cond_2_Block
(
column2,column3,column4,column5,column6,column7,
column8,rank
)
select
column2,column3,column4,column5,column6,column7,
column8,rank
from mmt_staging2.BUDNI_NMT_Noise_at_operator_ear_level_block a
where rank<=4;
update mmt_staging2.BUDNI_NMT_Atmos_Cond_2_Block set make=__make,model=__model;
execute 'update mmt_staging2.BUDNI_NMT_Atmos_Cond_2_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
update mmt_staging2.BUDNI_NMT_Atmos_Cond_2_Block
set ods_record=0 where
rank in (1,2,3);
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_NMT_Atmos_Cond_2_Block');
/* blocks data loading -BUDNI_NMT_Meas_Results_2_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_NMT_Meas_Results_2_Block',__file_format,__sheet_mnemonic,7);
insert into mmt_staging2.BUDNI_NMT_Meas_Results_2_Block
(
column2,column3,column4,column5,column6,column7,
column8,rank
)
select
column2,column3,column4,column5,column6,column7,
column8,rank
from mmt_staging2.BUDNI_NMT_Noise_at_operator_ear_level_block a
where rank>4;
update mmt_staging2.BUDNI_NMT_Meas_Results_2_Block
set ods_record=0 where
rank =5;
update BUDNI_NMT_Meas_Results_2_Block set column3=column4 where column3 is null;
update mmt_staging2.BUDNI_NMT_Meas_Results_2_Block set make=__make,model=__model;
execute 'update mmt_staging2.BUDNI_NMT_Meas_Results_2_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_NMT_Meas_Results_2_Block');
/* blocks data loading -BUDNI_NMT_Test_Obs_Summary_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_NMT_Test_Obs_Summary_Block',__file_format,__sheet_mnemonic,8);
insert into mmt_staging2.BUDNI_NMT_Test_Obs_Summary_Block
(
column2,column3,column4,column5,column6,column7,
column8,column9,rank
)
select
column2,column3,column4,column5,column6,column7,
column8,column9,rank
from mmt_staging2.stg_process_table_BUDNI_NMT a
where rank_tag='BUDNI_NMT_Test_Obs_Summary' and rank in (1,2,3,4);
update mmt_staging2.BUDNI_NMT_Test_Obs_Summary_Block
set ods_record=0 where
rank in (1,2);
update mmt_staging2.BUDNI_NMT_Test_Obs_Summary_Block set make=__make,model=__model;
execute 'update mmt_staging2.BUDNI_NMT_Test_Obs_Summary_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_NMT_Test_Obs_Summary_Block');
end
$$ LANGUAGE plpgsql;

View File

@@ -0,0 +1,338 @@
drop function if exists mmt_staging2.fn_BUDNI_PTO_block;
CREATE OR REPLACE FUNCTION mmt_staging2.fn_BUDNI_PTO_block(p_client_id int,p_function_id int, p_file_format text,
p_sheet_mnemonic text, p_file_syspk int)
RETURNS text AS $$
declare __make text;
declare __model text;
declare __client_id int :=p_client_id;
declare __function_id int :=p_function_id;
declare __file_format text :=p_file_format;
declare __sheet_mnemonic text :=p_sheet_mnemonic;
declare __file_syspk int :=p_file_syspk;
begin
SET search_path TO mmt_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 mmt_staging2.fn_BUDNI_PTO_Block(20,1,'BUDNI','BUDNI_PTO',261);
************************************************************************************/
/* rerunnability - delete block tables and update config tables to null */
truncate table mmt_staging2.stg_specific_table_BUDNI_PTO;
truncate table mmt_staging2.stg_process_table_BUDNI_PTO;
truncate table mmt_staging2.BUDNI_PTO_Spec_H1_Block;
truncate table mmt_staging2.BUDNI_PTO_Perf_Report_block;
truncate table mmt_staging2.BUDNI_PTO_MMTKeyword1_Block;
truncate table mmt_staging2.BUDNI_PTO_MMTKeyword2_Block;
truncate table mmt_staging2.BUDNI_PTO_Summary_Block;
execute 'delete from mmt_ods.fw_jobctrl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=null,
row_previous_number=null,
row_read_end=null,
run_time=null
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* transfer data from generic to specific for BUDNI */
execute 'insert into mmt_staging2.stg_specific_table_budni_pto
select * from mmt_staging1.mmt_staging_generic_table a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.file_syspk='||p_file_syspk||'';
/* trimming data */
update mmt_staging2.stg_specific_table_budni_pto set column3 = TRIM (TRAILING FROM column3 );
update mmt_staging2.stg_specific_table_budni_pto set column3 = TRIM (LEADING FROM column3 );
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified) ;
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified) ;
update mmt_ods.mmt_config set F1_source=F1_modified ;
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source);
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source);
/* keyword match */
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* reverese update */
execute 'update mmt_staging2.stg_specific_table_budni_pto a
set is_rownumber_fetched=1
from mmt_ods.mmt_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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_read_end= (select b.row_number_start
from mmt_ods.mmt_config b
where b.syspk=a.syspk+1 and file_format='''||p_file_format||''' and sheet_mnemonic='''||p_sheet_mnemonic||''' )
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* config file last field update as null otherwise it picks up next format row number*/
execute 'update mmt_ods.mmt_config a
set row_read_end = null ,run_time=current_timestamp
where f1_modified =''PTO Performance Test Observations Summary''
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* tagging ranks for each block in process table*/
execute 'insert into mmt_staging2.stg_process_table_budni_pto
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_budni_pto a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'insert into mmt_staging2.stg_process_table_budni_pto
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_budni_pto a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'insert into mmt_staging2.stg_process_table_budni_pto
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag from mmt_staging2.stg_specific_table_budni_pto a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'insert into mmt_staging2.stg_process_table_budni_pto
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag from mmt_staging2.stg_specific_table_budni_pto a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'insert into mmt_staging2.stg_process_table_budni_pto
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_budni_pto a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* fetching tractor model and make */
select column3 into __make from mmt_staging2.stg_process_table_budni_pto a
where rank_tag='BUDNI_PTO_Spec_H1' and rank=3 ;
select column4 into __model from mmt_staging2.stg_process_table_budni_pto a
where rank_tag='BUDNI_PTO_Spec_H1' and rank=3;
/* blocks data loading start - BUDNI_PTO_Spec_H1_block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_PTO_Spec_H1_block',__file_format,__sheet_mnemonic,1);
insert into mmt_staging2.BUDNI_PTO_Spec_H1_block
(make,model,tractor_HP,rated_rpm,configuration,transmission_type,wheel_drive_type,FIP_type,rank)
select column3,column4,column5,column6,column7,column8,column9,column10,rank
from mmt_staging2.stg_process_table_budni_pto where rank_tag='BUDNI_PTO_Spec_H1'
and rank=3;
execute 'update mmt_staging2.BUDNI_PTO_Spec_H1_block set file_syspk='||p_file_syspk||'';
update mmt_staging2.BUDNI_PTO_Spec_H1_block a
set date= date '1899-12-30' + column12::int * interval '1' day
from mmt_staging2.stg_process_table_budni_pto b
where b.rank_tag='BUDNI_PTO_Spec_H1'
and b.rank=1
and a.file_syspk=b.file_syspk ;
update mmt_staging2.BUDNI_PTO_Spec_H1_block a
set steering_type=column3,Engine_to_PTO_ratio= column4
from mmt_staging2.stg_process_table_budni_pto b
where b.rank_tag='BUDNI_PTO_Spec_H1'
and b.rank=5
and a.file_syspk=b.file_syspk;
update mmt_staging2.BUDNI_PTO_Spec_H1_block set make=__make, model=__model;
execute 'update mmt_staging2.BUDNI_PTO_Spec_H1_block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||''',
file_syspk='||p_file_syspk||'';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_PTO_Spec_H1_block');
/* blocks data loading -BUDNI_PTO_Perf_Report_block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_PTO_Perf_Report_block',__file_format,__sheet_mnemonic,2);
insert into mmt_staging2.BUDNI_PTO_Perf_Report_block
( column2,column3,column4,column5,column6,column7,column8,column9,column10,rank)
select column2,column3,column4,column5,column6,column7,column8,column9,column10,rank
from mmt_staging2.stg_process_table_budni_pto
where rank_tag='BUDNI_PTO_Perf_Report';
update mmt_staging2.BUDNI_PTO_Perf_Report_block
set column2=column3 where column2 is null;
update mmt_staging2.BUDNI_PTO_Perf_Report_block
set column2=null
where column2 like 'i%';
update mmt_staging2.BUDNI_PTO_Perf_Report_block
set column2=null
where column2 like 'v%';
update mmt_staging2.BUDNI_PTO_Perf_Report_block a
set column2= b.first_value from (SELECT
rank, column2, value_partition, first_value(column2) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column2,
sum(case when column2 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_PTO_Perf_Report_block
ORDER BY rank ASC
) as q) b where a.rank = b.rank ;
update mmt_staging2.BUDNI_PTO_Perf_Report_block
set column3 =null
where column2=column3;
update mmt_staging2.BUDNI_PTO_Perf_Report_block
set ods_record=0 where rank in (1,2,3);
update mmt_staging2.BUDNI_PTO_Perf_Report_block set ods_record=0 where column3 is null
and column2 in(
select column2 from mmt_staging2.BUDNI_PTO_Perf_Report_block group by column2 having count(*)>1
);
update mmt_staging2.BUDNI_PTO_Perf_Report_block set make=__make,model=__model;
execute 'update mmt_staging2.BUDNI_PTO_Perf_Report_block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||''',
file_syspk='||p_file_syspk||'';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_PTO_Perf_Report_block');
/* blocks data loading - BUDNI_PTO_MMTKeyword1_block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_PTO_MMTKeyword1_block',__file_format,__sheet_mnemonic,3);
insert into mmt_staging2.BUDNI_PTO_MMTKeyword1_block
( column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,rank)
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,rank
from mmt_staging2.stg_process_table_budni_pto
where rank_tag='BUDNI_PTO_MMTKeyword1';
update mmt_staging2.BUDNI_PTO_MMTKeyword1_block set ods_record=0 where rank in (1,2);
update mmt_staging2.BUDNI_PTO_MMTKeyword1_block set make=__make,model=__model;
execute 'update mmt_staging2.BUDNI_PTO_MMTKeyword1_block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||''',
file_syspk='||p_file_syspk||'';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_PTO_MMTKeyword1_block');
/* blocks data loading - BUDNI_PTO_MMTKeyword2_block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_PTO_MMTKeyword2_block',__file_format,__sheet_mnemonic,4);
insert into mmt_staging2.BUDNI_PTO_MMTKeyword2_block
( column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,rank)
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,rank
from mmt_staging2.stg_process_table_budni_pto
where rank_tag='BUDNI_PTO_MMTKeyword2';
update mmt_staging2.BUDNI_PTO_MMTKeyword2_block set ods_record=0 where rank in (1,2);
update mmt_staging2.BUDNI_PTO_MMTKeyword2_block set make=__make,model=__model;
execute 'update mmt_staging2.BUDNI_PTO_MMTKeyword2_block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||''',
file_syspk='||p_file_syspk||'';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_PTO_MMTKeyword2_block');
/* blocks data loading -BUDNI_PTO_Summary_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_PTO_Summary_Block',__file_format,__sheet_mnemonic,5);
insert into mmt_staging2.BUDNI_PTO_Summary_Block
( column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,rank)
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,rank
from mmt_staging2.stg_process_table_budni_pto
where rank_tag='BUDNI_PTO_Summary';
update mmt_staging2.BUDNI_PTO_Summary_block
set ods_record=0 where rank in (1,2);
update mmt_staging2.BUDNI_PTO_Summary_block set make=__make, model=__model;
execute 'update mmt_staging2.BUDNI_PTO_Summary_block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||''',
file_syspk='||p_file_syspk||'';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'mmt_staging2.BUDNI_PTO_Summary_block');
return __model;
end
$$ LANGUAGE plpgsql;

View File

@@ -0,0 +1,349 @@
drop function if exists mmt_staging2.fn_BUDNI_VMT_Block ;
CREATE OR REPLACE FUNCTION mmt_staging2.fn_BUDNI_VMT_Block(p_client_id int,p_function_id int, p_file_format text,
p_sheet_mnemonic text, p_file_syspk int)
RETURNS void AS $$
declare __make text;
declare __model text;
declare __client_id int :=p_client_id;
declare __function_id int :=p_function_id;
declare __file_format text :=p_file_format;
declare __sheet_mnemonic text :=p_sheet_mnemonic;
declare __file_syspk int :=p_file_syspk;
begin
SET search_path TO mmt_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 mmt_staging2.fn_BUDNI_VMT_Block(20,1,'BUDNI','BUDNI_VMT',261);
************************************************************************************/
/* rerunnability - delete block tables and update config tables to null */
truncate table mmt_staging2.BUDNI_VMT_Spec_H1_Block;
truncate table mmt_staging2.BUDNI_VMT_Perf_Meas_Test_Block;
truncate table mmt_staging2.BUDNI_VMT_Test_Obs_Summary_Block;
truncate table mmt_staging2.stg_specific_table_BUDNI_VMT;
truncate table mmt_staging2.stg_process_table_BUDNI_VMT;
execute 'delete from mmt_ods.fw_jobctrl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=null,
row_previous_number=null,
row_read_end=null,
run_time=null
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* transfer data from generic to specific for BUDNI */
execute 'insert into mmt_staging2.stg_specific_table_BUDNI_VMT
select * from mmt_staging1.mmt_staging_generic_table a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.file_syspk='||p_file_syspk||'';
/* trimming data */
update mmt_staging2.stg_specific_table_BUDNI_LCG set column3 = TRIM (TRAILING FROM column3 );
update mmt_staging2.stg_specific_table_BUDNI_LCG set column3 = TRIM (LEADING FROM column3 );
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified);
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified) ;
update mmt_ods.mmt_config set F1_source=F1_modified;
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source);
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source) ;
/* keyword match in config table*/
execute 'update mmt_ods.mmt_config a set f1_source = replace(f1_source,''_1'','''')
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_staging2.stg_specific_table_BUDNI_VMT 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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* reverese update in process table for match*/
execute 'update mmt_staging2.stg_specific_table_BUDNI_VMT a
set is_rownumber_fetched=1
from mmt_ods.mmt_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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a set f1_source = replace(f1_source,''_2'','''')
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_staging2.stg_specific_table_BUDNI_VMT 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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* reverese update in process table for match*/
execute 'update mmt_staging2.stg_specific_table_BUDNI_VMT a
set is_rownumber_fetched=1
from mmt_ods.mmt_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_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* update config files for row numbers start, end */
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_read_end= (select b.row_number_start
from mmt_ods.mmt_config b
where b.syspk=a.syspk+1 )
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* config file last field update as null otherwise it picks up next format row number*/
execute 'update mmt_ods.mmt_config a
set row_read_end = null
where f1_modified =''AIR CLEANER OIL PULL OVER TEST Observations Summary''
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set run_time=current_timestamp
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* tagging ranks for each block in process table*/
execute 'insert into mmt_staging2.stg_process_table_BUDNI_VMT
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_BUDNI_VMT a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_BUDNI_VMT
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_BUDNI_VMT a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_BUDNI_VMT
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_BUDNI_VMT a
join mmt_ods.mmt_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_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
/* fetching tractor model and make */
select column3 into __make from mmt_staging2.stg_process_table_BUDNI_VMT a
where rank_tag='BUDNI_VMT_Spec_H1' and rank=3;
select column4 into __model from mmt_staging2.stg_process_table_BUDNI_VMT a
where rank_tag='BUDNI_VMT_Spec_H1' and rank=3;
/* blocks data loading start - BUDNI_VMT_Spec_H1_block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_VMT_Spec_H1_Block',__file_format,__sheet_mnemonic,1);
insert into mmt_staging2.BUDNI_VMT_Spec_H1_block
(
make,model,tractor_HP,rated_rpm,configuration,transmission_type,wheel_drive_type,rank)
select column3,column4,column5,column6,column7,column8,column9,rank
from mmt_staging2.stg_process_table_BUDNI_VMT where rank_tag='BUDNI_VMT_Spec_H1'
and rank=3;
execute 'update mmt_staging2.BUDNI_VMT_Spec_H1_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
update mmt_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 mmt_staging2.stg_process_table_BUDNI_VMT b
where b.rank_tag='BUDNI_VMT_Spec_H1'
and b.rank=5
and a.file_syspk=b.file_syspk;
update mmt_staging2.BUDNI_VMT_Spec_H1_Block
set ods_record=0 where rank in(1,2);
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_VMT_Spec_H1_block');
/* blocks data loading -BUDNI_VMT_Perf_Meas_Test_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_VMT_Perf_Meas_Test_Block',__file_format,__sheet_mnemonic,2);
insert into mmt_staging2.BUDNI_VMT_Perf_Meas_Test_Block
(
column3,
column4,
column5,
column6,
column7,
column8,
column9,
rank
)
select
column3,column4,column5,column6,column7,column8,column9,rank
from mmt_staging2.stg_process_table_BUDNI_VMT a
where rank_tag ='BUDNI_VMT_Perf_Meas_Test'
order by rank;
update mmt_staging2.BUDNI_VMT_Perf_Meas_Test_Block a
set column3= b.first_value from (SELECT
rank, column3, value_partition, first_value(column3) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column3,
sum(case when column3 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_VMT_Perf_Meas_Test_Block
ORDER BY rank ASC
) as q) b where a.rank = b.rank and a.rank not in(1,2,3,4);
update mmt_staging2.BUDNI_VMT_Perf_Meas_Test_Block a
set column4= b.first_value from (SELECT
rank, column4, value_partition, first_value(column4) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column4,
sum(case when column4 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_VMT_Perf_Meas_Test_Block
ORDER BY rank ASC
) as q) b where a.rank = b.rank and a.rank not in(1,2,3,4);
update mmt_staging2.BUDNI_VMT_Perf_Meas_Test_Block
set column4=concat(column4,'-',column5) where rank not in(1,2,3,4) and column5 is not null;
update mmt_staging2.BUDNI_VMT_Perf_Meas_Test_Block
set ods_record=0 where rank in(1,2,3,4);
update mmt_staging2.BUDNI_VMT_Perf_Meas_Test_Block set make=__make,model=__model;
execute 'update mmt_staging2.BUDNI_VMT_Perf_Meas_Test_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_VMT_Perf_Meas_Test_Block');
/* blocks data loading -BUDNI_VMT_Test_Obs_Summary_Block */
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'BUDNI_VMT_Test_Obs_Summary_Block',__file_format,__sheet_mnemonic,3);
insert into mmt_staging2.BUDNI_VMT_Test_Obs_Summary_Block
(
column3,column4,column5,column6,column7,
column8,column9,rank
)
select
column3,column4,column5,column6,column7,
column8,column9,rank
from mmt_staging2.stg_process_table_BUDNI_VMT a
where rank_tag='BUDNI_VMT_Test_Obs_Summary' and rank <=6
order by rank;
update mmt_staging2.BUDNI_VMT_Test_Obs_Summary_Block a
set column5= b.first_value from (SELECT
rank, column5, value_partition, first_value(column5) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column5,
sum(case when column5 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_VMT_Test_Obs_Summary_Block
ORDER BY rank ASC
) as q) b where a.rank = b.rank;
update mmt_staging2.BUDNI_VMT_Test_Obs_Summary_Block a
set column6= b.first_value from (SELECT
rank, column6, value_partition, first_value(column6) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column6,
sum(case when column6 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_VMT_Test_Obs_Summary_Block
ORDER BY rank ASC
) as q) b where a.rank = b.rank;
update mmt_staging2.BUDNI_VMT_Test_Obs_Summary_Block a
set column7= b.first_value from (SELECT
rank, column7, value_partition, first_value(column7) over (partition by value_partition order by rank)
FROM (
SELECT
rank,
column7,
sum(case when column7 is null then 0 else 1 end) over (order by rank) as value_partition
FROM mmt_staging2.BUDNI_VMT_Test_Obs_Summary_Block
ORDER BY rank ASC
) as q) b where a.rank = b.rank;
update mmt_staging2.BUDNI_VMT_Test_Obs_Summary_Block
set ods_record=0 where
rank in(1,2);
update mmt_staging2.BUDNI_VMT_Test_Obs_Summary_Block set make=__make,model=__model;
execute 'update mmt_staging2.BUDNI_VMT_Test_Obs_Summary_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'BUDNI_VMT_Test_Obs_Summary_Block');
end
$$ LANGUAGE plpgsql;

View File

@@ -0,0 +1,480 @@
drop function if exists mmt_staging2.fn_FTDRY_SUM_Block ;
CREATE OR REPLACE FUNCTION mmt_staging2.fn_FTDRY_SUM_Block(p_client_id int,p_function_id int, p_file_format text,
p_sheet_mnemonic text, p_file_syspk int)
RETURNS void AS $$
declare __client_id int :=p_client_id;
declare __function_id int :=p_function_id;
declare __file_format text :=p_file_format;
declare __sheet_mnemonic text :=p_sheet_mnemonic;
declare __file_syspk int :=p_file_syspk;
begin
/***********************************************************************************
Function Name:fn_FTDRY_SUM_Block
Function Desc: This function populates data into staging2 blocks
File Format: FTDRY
Sheet Format: FTDRY_SUM
Creation Date:
Updation Date:
Author: compegence team
Function Call: select mmt_staging2.fn_FTDRY_SUM_Block (20,1,'FTDRY','FTDRY_SUM',258);
************************************************************************************/
SET search_path TO mmt_staging2;
truncate mmt_staging2.ftdry_sum_trac_h1_block;
truncate mmt_staging2.ftdry_sum_implement_block;
truncate mmt_staging2.ftdry_sum_test_condition_1_block;
truncate mmt_staging2.ftdry_sum_test_condition_2_block;
truncate mmt_staging2.ftdry_sum_comments_by_block;
truncate mmt_staging2.stg_specific_table_ftdry_sum;
truncate mmt_staging2.stg_process_table_ftdry_sum;
execute 'delete from mmt_ods.fw_jobctrl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=null,
row_previous_number=null,
row_read_end=null,
run_time=null
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* transfer data from generic to specific for ftdry*/
execute 'insert into mmt_staging2.stg_specific_table_ftdry_sum
select * from mmt_staging1.mmt_staging_generic_table a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.file_syspk='||p_file_syspk||'';
/* trimming data */
update mmt_staging2.stg_specific_table_ftdry_sum set column2 = TRIM (TRAILING FROM column2 );
update mmt_staging2.stg_specific_table_ftdry_sum set column2 = TRIM (LEADING FROM column2 );
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified);
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified) ;
update mmt_ods.mmt_config set F1_source=F1_modified ;
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source);
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source) ;
/* keyword match in config table*/
execute 'update mmt_ods.mmt_config a set f1_source = replace(f1_source,''_1'','''')
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* update config files for row numbers start, end */
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_staging2.stg_specific_table_ftdry_sum b
where F1_source=column2
and b.is_rownumber_fetched is null)
where a.row_number_start is null and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* reverese update in process table for match*/
execute 'update mmt_staging2.stg_specific_table_ftdry_sum a
set is_rownumber_fetched=1
from mmt_ods.mmt_config b
where F1_source=column2
and b.row_number_start=a.row_number
and is_rownumber_fetched is null and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a set f1_source = replace(f1_source,''_2'','''')
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* update config files for row numbers start, end */
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_staging2.stg_specific_table_ftdry_sum b
where F1_source=column2
and b.is_rownumber_fetched is null)
where a.row_number_start is null and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_staging2.stg_specific_table_ftdry_sum a
set is_rownumber_fetched=1
from mmt_ods.mmt_config b
where F1_source=column2
and b.row_number_start=a.row_number
and is_rownumber_fetched is null and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_read_end= (select b.row_number_start
from mmt_ods.mmt_config b
where b.syspk=a.syspk+1 )
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* config file last field update as null otherwise it picks up next format row number*/
execute 'update mmt_ods.mmt_config a
set row_read_end = null where f1_modified =''Test Manager Comments_2'' and
a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/*inserting run_time in config*/
execute 'update mmt_ods.mmt_config a
set run_time=current_timestamp where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* tagging ranks for each block in process table*/
execute 'insert into mmt_staging2.stg_process_table_ftdry_sum
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_ftdry_sum a
join mmt_ods.mmt_config b
on a.row_number >=row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Tractor Model''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_ftdry_sum
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_ftdry_sum a
join mmt_ods.mmt_config b
on a.row_number >=row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Make of Implement''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_ftdry_sum
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_ftdry_sum a
join mmt_ods.mmt_config b
on a.row_number >=row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Test Condition_1:''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_ftdry_sum
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_ftdry_sum a
join mmt_ods.mmt_config b
on a.row_number >=row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Test Engineer Comments_1''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_ftdry_sum
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_ftdry_sum a
join mmt_ods.mmt_config b
on a.row_number >=row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Test Manager Comments_1''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_ftdry_sum
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_ftdry_sum a
join mmt_ods.mmt_config b
on a.row_number >=row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Test Condition_2:''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_ftdry_sum
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_ftdry_sum a
join mmt_ods.mmt_config b
on a.row_number >=row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Test Engineer Comments_2''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_ftdry_sum
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_ftdry_sum a
join mmt_ods.mmt_config b
on a.row_number >=row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Test Manager Comments_2''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
/* blocks data loading start - FTDRY_SUM_Trac_H1_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTDRY_SUM_Trac_H1_Block',__file_format,__sheet_mnemonic,1);
insert into mmt_staging2.FTDRY_SUM_Trac_H1_Block
(
Tractor_Model,
Tractor_Make,
Tractor_Engine_HP,
Rated_RPM,
Transmission_Type,
Wheel_Drive_Type,
FIP_Type,
Steering_Type,
Tractor_Weight_kg_Front,
Tractor_Weight_kg_Rear,
Tractor_Weight_kg_Total,
rank
)
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,rank
from mmt_staging2.stg_process_table_ftdry_sum
where rank_tag='FTDRY_SUM_Trac_H1'
order by rank;
update mmt_staging2.FTDRY_SUM_Trac_H1_Block
set ods_record=0 where rank=1;
execute 'update mmt_staging2.FTDRY_SUM_Trac_H1_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTDRY_SUM_Trac_H1_Block');
/* blocks data loading start -FTDRY_SUM_Implement_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTDRY_SUM_Implement_Block',__file_format,__sheet_mnemonic,2);
insert into mmt_staging2.FTDRY_SUM_Implement_Block
(
Make_of_Implement,
Implement_Type,
Implement_Size,
Hitch_Category,
Implement_Weight,
Soil_Type,
Moisture_Content ,
Bulk_Density_g_cc ,
Soil_Cone_index,
Field_Condition ,
Season,
rank
)
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,rank
from mmt_staging2.stg_process_table_ftdry_sum
where rank_tag='FTDRY_SUM_Implement';
update mmt_staging2.FTDRY_SUM_Implement_Block
set ods_record=0 where rank in(1,3);
execute 'update mmt_staging2.FTDRY_SUM_Implement_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTDRY_SUM_Implement_Block');
/* blocks data loading start -FTDRY_SUM_Test_Condition_1_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTDRY_SUM_Test_Condition_1_Block',__file_format,__sheet_mnemonic,3);
insert into mmt_staging2.FTDRY_SUM_Test_Condition_1_Block
(
dummy_f,
Test_Condition,
Test_Date,
Tractor_Model,
Engine_RPM_set,
PTO_RPM_set,
Gear_Used,
Nominal_Speed_KMPH,
Engine_RPM_Drop_on_straight,
Engine_RPM_Drop_on_turn,
Depth_of_cut_cm,
No_load_speed_kmph,
On_load_speed_kmph,
wheel_slippage_,
Fuel_consumption_lit_hr,
Area_covered_acr_hr,
Fuel_consumption_lit_Acr,
M_M_Performance_in_compared_to_respective_competitor_tractors,
Fuel_consumption_lit_hr_2,
Area_covered_acr_hr_2,
Fuel_consumption_lit_Acr_2,
Trail_Observations,
Engine_Smoke_on_Load,
Engine_acceleration_smoke,
Draft_Response,
Tractor_Steer_ability,
Tractor_braking_performance,
Front_Visibility,
Implement_Accessibility,
Front_Wheel_dragging_at_turning,
Front_end_lifting_during_operation,
RPM_Recovery_Time,
Engine_Vibration,
Engine_Sound,
Implement_Lifting_Lowering_response,
Pulverization_Quality,
Pulverization_Index
)
SELECT *
FROM crosstab(
'SELECT unnest(''{column3,column4,column5,column6,column7,column8,column9,column10,column11,column12}''::text[]) AS col
, row_number() OVER ()
, unnest(ARRAY[column3::text,
column4::text,column5::text,column6::text,column7::text,column8::text,
column9::text,column10::text,column11::text,column12::text]) AS val
FROM mmt_staging2.stg_process_table_ftdry_sum where rank_tag=''FTDRY_SUM_Test_Condition_1''
ORDER BY generate_series(1,15),rank,2'
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text,
a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text
,a_21 text,a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text,
a_31 text,a_32 text,a_33 text,a_34 text,a_35 text,a_36 text);
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTDRY_SUM_Test_Condition_1_Block');
delete from mmt_staging2.FTDRY_SUM_Test_Condition_1_Block where dummy_f is null ;
execute 'update mmt_staging2.FTDRY_SUM_Test_Condition_1_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* blocks data loading start -FTDRY_SUM_Test_Condition_2_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTDRY_SUM_Test_Condition_2_Block',__file_format,__sheet_mnemonic,4);
insert into mmt_staging2.FTDRY_SUM_Test_Condition_2_Block
(
dummy_f,
Test_Condition,
Test_Date,
Tractor_Model,
Engine_RPM_set,
PTO_RPM_set,
Gear_Used,
Nominal_Speed_KMPH,
Engine_RPM_Drop_on_straight,
Engine_RPM_Drop_on_turn,
Depth_of_cut_cm,
No_load_speed_kmph,
On_load_speed_kmph,
wheel_slippage_,
Fuel_consumption_lit_hr,
Area_covered_acr_hr,
Fuel_consumption_lit_Acr,
M_M_Performance_in_compared_to_respective_competitor_tractors,
Fuel_consumption_lit_hr_2,
Area_covered_acr_hr_2,
Fuel_consumption_lit_Acr_2,
Trail_Observations,
Engine_Smoke_on_Load,
Engine_acceleration_smoke,
Draft_Response,
Tractor_Steer_ability,
Tractor_braking_performance,
Front_Visibility,
Implement_Accessibility,
Front_Wheel_dragging_at_turning,
Front_end_lifting_during_operation,
RPM_Recovery_Time,
Engine_Vibration,
Engine_Sound,
Implement_Lifting_Lowering_response,
Pulverization_Quality,
Pulverization_Index
)
SELECT *
FROM crosstab(
'SELECT unnest(''{column3,column4,column5,column6,column7,column8,column9,column10,column11,column12}''::text[]) AS col
, row_number() OVER ()
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text,column8::text,column9::text,column10::text,column11::text,column12::text]) AS val
FROM mmt_staging2.stg_process_table_ftdry_sum where rank_tag=''FTDRY_SUM_Test_Condition_2''
ORDER BY generate_series(1,15),rank,2'
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,
a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text,a_21 text,
a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text,a_31 text,
a_32 text,a_33 text,a_34 text,a_35 text,a_36 text);
delete from mmt_staging2.FTDRY_SUM_Test_Condition_2_Block where dummy_f is null ;
execute 'update mmt_staging2.FTDRY_SUM_Test_Condition_2_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTDRY_SUM_Test_Condition_2_Block');
/* blocks data loading start -FTDRY_SUM_Comments_By_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTDRY_SUM_Comments_By_Block',__file_format,__sheet_mnemonic,5);
insert into mmt_staging2.FTDRY_SUM_Comments_By_Block (dummy_f) values ('dummy');
execute 'update mmt_staging2.FTDRY_SUM_Comments_By_Block set Test_Engineer_Comments_1=
(select column3 from mmt_staging2.stg_process_table_ftdry_sum a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.rank_tag=''FTDRY_SUM_Engineer_Comments_1''
and a.rank=1 ) where dummy_f=''dummy''';
execute 'update mmt_staging2.FTDRY_SUM_Comments_By_Block set test_engineer_comments_2=
(select column3 from mmt_staging2.stg_process_table_ftdry_sum a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.rank_tag=''FTDRY_SUM_Engineer_Comments_2''
and a.rank=1 ) where dummy_f=''dummy''';
execute 'update mmt_staging2.FTDRY_SUM_Comments_By_Block set test_manager_comments_1=
(select column3 from mmt_staging2.stg_process_table_ftdry_sum a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.rank_tag=''FTDRY_SUM_Manager_Comments_1''
and a.rank=1 ) where dummy_f=''dummy''';
execute 'update mmt_staging2.FTDRY_SUM_Comments_By_Block set test_manager_comments_2=
(select column3 from mmt_staging2.stg_process_table_ftdry_sum a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.rank_tag=''FTDRY_SUM_Manager_Comments_2''
and a.rank=1 ) where dummy_f=''dummy''';
delete from mmt_staging2.FTDRY_SUM_Comments_By_Block where dummy_f is null ;
execute 'update mmt_staging2.FTDRY_SUM_Comments_By_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTDRY_SUM_Comments_By_Block');
end
$$ LANGUAGE plpgsql;

View File

@@ -0,0 +1,416 @@
/*FTDRY_starts*/
drop function if exists mmt_staging2.fn_FTDRY_TRS_Block ;
CREATE OR REPLACE FUNCTION mmt_staging2.fn_FTDRY_TRS_Block(p_client_id int,p_function_id int, p_file_format text,
p_sheet_mnemonic text, p_file_syspk int)
RETURNS void AS $$
declare __client_id int :=p_client_id;
declare __function_id int :=p_function_id;
declare __file_format text :=p_file_format;
declare __sheet_mnemonic text :=p_sheet_mnemonic;
declare __file_syspk int :=p_file_syspk;
begin
/***********************************************************************************
Function Name:fn_FTDRY_TRS_Block
Function Desc: This function populates data into staging2 blocks
File Format: FTDRY
Sheet Format: FTDRY_TRS
Creation Date:
Updation Date:
Author: compegence team
Function Call: select mmt_staging2.fn_FTDRY_TRS_Block(20,1,'FTDRY','FTDRY_TRS',257);
************************************************************************************/
SET search_path TO mmt_staging2;
truncate mmt_staging2.FTDRY_TRS_H1_INT;
truncate mmt_staging2.ftdry_trs_h1_block ;
truncate mmt_staging2.ftdry_trs_implement_block ;
truncate mmt_staging2.ftdry_trs_spec_block;
truncate mmt_staging2.ftdry_trs_engine_rpm_block;
truncate mmt_staging2.stg_specific_table_ftdry_trs;
truncate mmt_staging2.stg_process_table_ftdry_trs;
execute 'delete from mmt_ods.fw_jobctrl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=null,
row_previous_number=null,
row_read_end=null,
run_time=null
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* transfer data from generic to specific for ftdry*/
execute 'insert into mmt_staging2.stg_specific_table_ftdry_trs
select * from mmt_staging1.mmt_staging_generic_table a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.file_syspk='||p_file_syspk||'';
/* trimming data */
update mmt_staging2.stg_specific_table_ftdry_trs set column2 = TRIM (TRAILING FROM column2 );
update mmt_staging2.stg_specific_table_ftdry_trs set column2 = TRIM (LEADING FROM column2 );
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified);
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified);
update mmt_ods.mmt_config set F1_source=F1_modified;
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source) ;
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source);
/* keyword match in config table*/
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_staging2.stg_specific_table_ftdry_trs b
where trim(upper(F1_source))= trim(upper(column2))
and b.is_rownumber_fetched is null)
where a.row_number_start is null and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* reverese update in process table for match*/
execute 'update mmt_staging2.stg_specific_table_ftdry_trs a
set is_rownumber_fetched=1
from mmt_ods.mmt_config b
where trim(upper(F1_source))= trim(upper(column2))
and b.row_number_start=a.row_number
and is_rownumber_fetched is null and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* update config files for row numbers start, end */
execute 'update mmt_ods.mmt_config a
set row_read_end= (select b.row_number_start
from mmt_ods.mmt_config b
where b.syspk=a.syspk+1 )
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* config file last field update as null otherwise it picks up next format row number*/
execute 'update mmt_ods.mmt_config a set row_read_end = null
where f1_modified =''Implement Details'' and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/*inserting run_time in config*/
execute 'update mmt_ods.mmt_config a
set run_time=current_timestamp
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* tagging ranks for each block in process table*/
execute 'insert into mmt_staging2.stg_process_table_ftdry_trs
select a.* , RANK () OVER ( ORDER BY row_number) as rank,b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_ftdry_trs a
join mmt_ods.mmt_config b
on a.row_number >row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Tractor Specifications Sheet''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_ftdry_trs
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_ftdry_trs a
join mmt_ods.mmt_config b
on a.row_number >row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Tractor Specifications'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_ftdry_trs
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_ftdry_trs a
join mmt_ods.mmt_config b
on a.row_number >row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Engine RPM Data:'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_ftdry_trs
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_ftdry_trs a
join mmt_ods.mmt_config b
on a.row_number >row_number_start
and a.column2 <> ''''
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Implement Details'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
/*insert data into h1_int */
insert into mmt_staging2.FTDRY_TRS_H1_INT(
column2,column3,column4,column5,column6,column7,rank)
select column2,column3,column4,column5,column6,column7,rank
from mmt_staging2.stg_process_table_ftdry_trs a where rank_tag='FTDRY_TRS_H1'
order by rank;
insert into mmt_staging2.FTDRY_TRS_H1_INT(column2) values ('Date of Test');
insert into mmt_staging2.FTDRY_TRS_H1_INT(column2) values ('Report Date');
insert into mmt_staging2.FTDRY_TRS_H1_INT(column2) values ('Season');
insert into mmt_staging2.FTDRY_TRS_H1_INT (column2) values ('Type of Soil');
insert into mmt_staging2.FTDRY_TRS_H1_INT (column2) values ('Soil Cone Index (kPa)');
insert into mmt_staging2.FTDRY_TRS_H1_INT (column2) values ('Field Condition');
update mmt_staging2.FTDRY_TRS_H1_INT a
set column3=(select column5 from mmt_staging2.FTDRY_TRS_H1_INT b
where trim(a.column2)=trim(b.column4)
and b.column4='Date of Test')
where a.column2='Date of Test';
update mmt_staging2.FTDRY_TRS_H1_INT a
set column3=(select column7 from mmt_staging2.FTDRY_TRS_H1_INT b
where trim(a.column2)=trim(b.column6)
and b.column6='Report Date')
where a.column2='Report Date';
update mmt_staging2.FTDRY_TRS_H1_INT a
set column3=(select column6 from mmt_staging2.FTDRY_TRS_H1_INT b
where trim(a.column2)=trim(b.column5)
and b.column5='Season')
where a.column2='Season';
update mmt_staging2.FTDRY_TRS_H1_INT a
set column3=(select column6 from mmt_staging2.FTDRY_TRS_H1_INT b
where trim(a.column2)=trim(b.column5)
and b.column5='Type of Soil')
where a.column2='Type of Soil';
update mmt_staging2.FTDRY_TRS_H1_INT a
set column3=(select column6 from mmt_staging2.FTDRY_TRS_H1_INT b
where trim(a.column2)=trim(b.column5)
and b.column5='Soil Cone Index (kPa)')
where a.column2='Soil Cone Index (kPa)';
update mmt_staging2.FTDRY_TRS_H1_INT a
set column3=(select column6 from mmt_staging2.FTDRY_TRS_H1_INT b
where trim(a.column2)=trim(b.column5)
and b.column5='Field Condition')
where a.column2='Field Condition';
/*inserting data into block -FTDRY_TRS_H1_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTDRY_TRS_H1_Block',__file_format,__sheet_mnemonic,1);
insert into mmt_staging2.FTDRY_TRS_H1_Block
(
dummy_f,
Report_Reference_No,
Objective_Of_Test,
Background_of_Test,
Job_Order_No,
Test_Location,
Soil_Moisture_Content_,
Soil_Bulk_Density_g_cc,
Test_Engineer,
Test_Operator,
Date_of_Test,
Report_Date,
Season,
Type_of_Soil,
Soil_Cone_Index_kPa,
Field_Condition
)
SELECT *
FROM crosstab(
'SELECT unnest(''{column3}''::text[]) AS col
, row_number() OVER ()
, unnest(ARRAY[column3::text]) AS val
FROM mmt_staging2.FTDRY_TRS_H1_INT
ORDER BY generate_series(1,15),rank,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 mmt_staging2.FTDRY_TRS_H1_Block where dummy_f is null ;
execute 'update mmt_staging2.FTDRY_TRS_H1_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTDRY_TRS_H1_Block');
/*inserting data into block -FTDRY_TRS_SPEC_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTDRY_TRS_SPEC_Block',__file_format,__sheet_mnemonic,2);
insert into mmt_staging2.FTDRY_TRS_SPEC_Block
(
dummy_f,
Tractor_Model,
Tractor_Make,
Tractor_Sr_No,
Tractor_Engine_HP,
FIP_Type,
hour_Meter_Reading,
Steering_Type,
Transmission_Type,
Wheel_Drive_Type_WD,
EGR_Yes_No,
Brake_Type,
PTO_Type,
Standard_PTO_Speed_RPM,
EPTO_Speed_RPM,
Front_Tyre_Make,
Front_Tyre_Size,
Front_Tyre_Pressure_psi,
Rear_Tyre_Make,
Rear_Tyre_Size,
Rear_Tyre_Pressure_psi ,
Tractor_Weight_kg_Front ,
Tractor_Weight_kg_Rear ,
Tractor_Weight_kg_Total,
Ballasted_Tractor_Accessories,
Mechanical_Ballast_Rear,
Mechanical_Ballast_Rear_in_KG ,
Water_Ballast_Rear,
Mechanical_Ballast_Front,
Mechanical_Ballast_Front_in_Kg,
Total_Ballast_Weight
)
SELECT *
FROM crosstab(
'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col
, row_number() OVER ()
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val
FROM mmt_staging2.stg_process_table_ftdry_trs where rank_tag=''FTDRY_TRS_SPEC''
ORDER BY generate_series(1,15),rank,2'
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,
a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text,a_21 text,
a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text);
delete from mmt_staging2.FTDRY_TRS_SPEC_Block where dummy_f is null ;
execute 'update mmt_staging2.FTDRY_TRS_SPEC_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTDRY_TRS_SPEC_Block');
/*inserting data into block -FTDRY_TRS_Engine_RPM_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTDRY_TRS_Engine_RPM_Block',__file_format,__sheet_mnemonic,3);
insert into mmt_staging2.FTDRY_TRS_Engine_RPM_Block
(
dummy_f,
tractor_model,
tractor_make,
Low_Idle,
High_Idle,
Rated_RPM,
Engine_to_PTO_Ratio_540_PTO,
Engine_to_PTO_Ratio_540E_PTO
)
SELECT *
FROM crosstab(
'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col
, row_number() OVER ()
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val
FROM mmt_staging2.stg_process_table_ftdry_trs where rank_tag=''FTDRY_TRS_Engine_RPM''
or (rank_tag=''FTDRY_TRS_SPEC'' and rank in (1,2))
ORDER BY generate_series(1,15),2'
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text);
delete from mmt_staging2.FTDRY_TRS_Engine_RPM_Block where dummy_f is null ;
execute 'update mmt_staging2.FTDRY_TRS_Engine_RPM_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTDRY_TRS_Engine_RPM_Block');
/*inserting data into block -FTDRY_TRS_Implement_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTDRY_TRS_Implement_Block',__file_format,__sheet_mnemonic,4);
insert into mmt_staging2.FTDRY_TRS_Implement_Block
(
dummy_f,
Name_of_Implement,
Type_of_Implement,
Make_of_Implement,
No_of_bottoms_Tyne_Disc_Blade,
Cutting_Width_m,
Implement_Weight_Kg,
Hitch_Category,
Span_cm_For_Mounted_Implement,
Mast_Height_cm_For_Mounted_Implement
)
SELECT *
FROM crosstab(
'SELECT unnest(''{column3,column4,column5,column6}''::text[]) AS col
, row_number() OVER ()
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text]) AS val
FROM mmt_staging2.stg_process_table_ftdry_trs where rank_tag=''FTDRY_TRS_Implement''
ORDER BY generate_series(1,15),rank,2'
) t ( col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text);
update mmt_staging2.FTDRY_TRS_Implement_Block set dummy_f='dummy' where dummy_f is null;
update mmt_staging2.FTDRY_TRS_Implement_Block set report_template_no= (select column2 from mmt_staging2.stg_process_table_ftdry_trs where rank=10 and rank_tag='FTDRY_TRS_Implement');
update mmt_staging2.FTDRY_TRS_Implement_Block set report_template_rev_no= (select column4 from mmt_staging2.stg_process_table_ftdry_trs where rank=10 and rank_tag='FTDRY_TRS_Implement');
update mmt_staging2.FTDRY_TRS_Implement_Block set report_template_rev_date= (select column6 from mmt_staging2.stg_process_table_ftdry_trs where rank=10 and rank_tag='FTDRY_TRS_Implement');
execute 'update mmt_staging2.FTDRY_TRS_Implement_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTDRY_TRS_Implement_Block');
end
$$ LANGUAGE plpgsql;

View File

@@ -0,0 +1,485 @@
drop function if exists mmt_staging2.fn_FTHLG_SUM_Block ;
CREATE OR REPLACE FUNCTION mmt_staging2.fn_FTHLG_SUM_Block(p_client_id int,p_function_id int, p_file_format text,
p_sheet_mnemonic text, p_file_syspk int)
RETURNS void AS $$
declare __client_id int :=p_client_id;
declare __function_id int :=p_function_id;
declare __file_format text :=p_file_format;
declare __sheet_mnemonic text :=p_sheet_mnemonic;
declare __file_syspk int :=p_file_syspk;
begin
/***********************************************************************************
Function Name:fn_FTHLG_SUM_Block
Function Desc: This function populates data into staging2 blocks
File Format: FTHLG
Sheet Format: FTHLG_SUM
Creation Date:
Updation Date:
Author: compegence team
Function Call: select mmt_staging2.fn_fthlg_sum_block(20,1,'FTHLG','FTHLG_SUM',109);
************************************************************************************/
SET search_path TO mmt_staging2;
truncate mmt_staging2.FTHLG_SUM_Trac_H1_Block;
truncate mmt_staging2.FTHLG_SUM_Trail_Type_Block;
truncate mmt_staging2.FTHLG_SUM_Test_Condition_1_Block;
truncate mmt_staging2.FTHLG_SUM_Test_Condition_2_Block;
truncate mmt_staging2.FTHLG_SUM_Comments_By_Block;
truncate mmt_staging2.stg_specific_table_fthlg_sum;
truncate mmt_staging2.stg_process_table_fthlg_sum;
execute 'delete from mmt_ods.fw_jobctrl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=null,
row_previous_number=null,
row_read_end=null,
run_time=null
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* transfer data from generic to specific for fthlg*/
execute 'insert into mmt_staging2.stg_specific_table_fthlg_sum
select * from mmt_staging1.mmt_staging_generic_table a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.file_syspk='||p_file_syspk||'';
/* trimming data */
update mmt_staging2.stg_specific_table_fthlg_sum set column2 = TRIM (TRAILING FROM column2 );
update mmt_staging2.stg_specific_table_fthlg_sum set column2 = TRIM (LEADING FROM column2 );
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified);
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified) ;
update mmt_ods.mmt_config set F1_source=F1_modified ;
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source) ;
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source) ;
/* keyword match in config table*/
execute 'update mmt_ods.mmt_config a set f1_source = replace(f1_source,''_1'','''')
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_staging2.stg_specific_table_fthlg_sum b
where F1_source=column2
and b.is_rownumber_fetched is null)
where a.row_number_start is null
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* reverese update in process table for match*/
execute 'update mmt_staging2.stg_specific_table_fthlg_sum a
set is_rownumber_fetched=1
from mmt_ods.mmt_config b
where F1_source=column2
and b.row_number_start=a.row_number
and is_rownumber_fetched is null
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* keyword match in config table*/
execute 'update mmt_ods.mmt_config a set f1_source = replace(f1_source,''_2'','''')
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_staging2.stg_specific_table_fthlg_sum b
where F1_source=column2
and b.is_rownumber_fetched is null)
where a.row_number_start is null
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* reverese update in process table for match*/
execute 'update mmt_staging2.stg_specific_table_fthlg_sum a
set is_rownumber_fetched=1
from mmt_ods.mmt_config b
where F1_source=column2
and b.row_number_start=a.row_number
and is_rownumber_fetched is null and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* update config files for row numbers start, end */
execute 'update mmt_ods.mmt_config a
set row_read_end= (select b.row_number_start
from mmt_ods.mmt_config b
where b.syspk=a.syspk+1 )
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* config file last field update as null otherwise it picks up next format row number*/
execute 'update mmt_ods.mmt_config a set row_read_end = null where f1_modified =''Test Manager Comments_2'' and
a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/*inserting run_time in config*/
execute 'update mmt_ods.mmt_config a
set run_time=current_timestamp
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* tagging ranks for each block in process table*/
execute 'insert into mmt_staging2.stg_process_table_fthlg_sum
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_fthlg_sum a
join mmt_ods.mmt_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=''Objective Of Test''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_fthlg_sum
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_fthlg_sum a
join mmt_ods.mmt_config b
on a.row_number >=row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Trailer Type''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_fthlg_sum
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_fthlg_sum a
join mmt_ods.mmt_config b
on a.row_number >=row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Test Condition_1:''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_fthlg_sum
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_fthlg_sum a
join mmt_ods.mmt_config b
on a.row_number >=row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Test Engineer Comments_1''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_fthlg_sum
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_fthlg_sum a
join mmt_ods.mmt_config b
on a.row_number >=row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Test Manager Comments_1''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_fthlg_sum
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_fthlg_sum a
join mmt_ods.mmt_config b
on a.row_number >=row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Test Condition_2:''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_fthlg_sum
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_fthlg_sum a
join mmt_ods.mmt_config b
on a.row_number >=row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Test Engineer Comments_2''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_fthlg_sum
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_fthlg_sum a
join mmt_ods.mmt_config b
on a.row_number >=row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Test Manager Comments_2''
and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
/*inserting data into block -FTHLG_SUM_Trac_H1_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTHLG_SUM_Trac_H1_Block',__file_format,__sheet_mnemonic,1);
insert into mmt_staging2.FTHLG_SUM_Trac_H1_Block
(
tractor_model,
tractor_make ,
tractor_engine_hp,
rated_rpm,
transmission_type,
wheel_drive_type,
fip_type,
steering_type,
tractor_weight_kg_front,
tractor_weight_kg_rear,
tractor_weight_kg_total,
rank
)
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,rank
from mmt_staging2.stg_process_table_fthlg_sum
where rank_tag='FTHLG_SUM_Trac_H1'
order by rank;
update mmt_staging2.FTHLG_SUM_Trac_H1_Block set ods_record=0 where rank in (1,2);
execute 'update mmt_staging2.FTHLG_SUM_Trac_H1_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTHLG_SUM_Trac_H1_Block');
/*inserting data into block -FTHLG_SUM_Trail_Type_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTHLG_SUM_Trail_Type_Block',__file_format,__sheet_mnemonic,2);
insert into mmt_staging2.FTHLG_SUM_Trail_Type_Block
(
Trailer_Type,
Tire_size_and_inflation_pressure_psi,
No_Of_Axle,
No_Of_Wheels,
Trailer_Gross_Weight_Kg,
Tractor_Rear_Wheel_Center_to_Hitch_Point_Center_Distance_mm,
Tractor_Hitch_Height_from_Ground_mm,
Trailer_hitch_Height_above_ground_level_mm,
Gradient_Slope_1_Degree,
Gradient_Slope_2_degree,
Tractor_Hitch_Type,
rank
)
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,rank
from mmt_staging2.stg_process_table_fthlg_sum
where rank_tag='FTHLG_SUM_Trail_Type'
order by rank;
update mmt_staging2.FTHLG_SUM_Trail_Type_Block set ods_record=0 where rank=1;
execute 'update mmt_staging2.FTHLG_SUM_Trail_Type_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTHLG_SUM_Trail_Type_Block');
/*inserting data into block -FTHLG_SUM_Test_Condition_1_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTHLG_SUM_Test_Condition_1_Block',__file_format,__sheet_mnemonic,3);
insert into mmt_staging2.FTHLG_SUM_Test_Condition_1_Block
(
dummy_f,
Test_Condition,
Test_Date,
Tractor_Model,
Fuel_consumption_Ltr_hr,
Mileage_Km_Ltr,
Average_speed_of_travel_kmph,
Total_distance_travelled_km,
Gear_used_on_Straight_Road,
Straight_road_RPM_Drop,
Gear_used_on_Up_Slope_1,
Up_Slope_RPM_Drop_1,
Gear_used_on_Up_Slope_2,
Up_Slope_RPM_Drop_2,
Gear_used_on_Down_Slope,
Down_Slope_RPM_Shoot_up,
M_M_Performance_compared_to_respective_competitor_tractors_is_better_and_is_poor_than_competitor,
Fuel_consumption_lit_hr_2,
Mileage_Km_Ltr_2,
M_M_Performance_in_compared_to_respective_competitor_tractors,
Fuel_consumption_lit_hr_3,
Mileage_Km_Ltr_3,
Engine_Smoke_on_Load,
Engine_acceleration_smoke,
Range_Gear_Shifting,
Speed_Gear_Shifting,
Tractor_Steer_ability,
Tractor_braking_performance,
Front_Visibility,
Implement_Accessibility,
Front_end_lifting_during_operation,
RPM_Recovery_Time,
Engine_Vibration,
Engine_Sound
)
SELECT *
FROM crosstab(
'SELECT unnest(''{column3,column4,column5,column6,column7,column8,column9,column10,column11,column12}''::text[]) AS col
, row_number() OVER ()
, unnest(ARRAY[column3::text,
column4::text,column5::text,column6::text,column7::text,column8::text,
column9::text,column10::text,column11::text,column12::text]) AS val
FROM mmt_staging2.stg_process_table_fthlg_sum where rank_tag=''FTHLG_SUM_Test_Condition_1''
ORDER BY generate_series(1,15),rank,2'
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text,
a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text
,a_21 text,a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text,
a_31 text,a_32 text,a_33 text);
delete from mmt_staging2.FTHLG_SUM_Test_Condition_1_Block where dummy_f is null ;
execute 'update mmt_staging2.FTHLG_SUM_Test_Condition_1_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTHLG_SUM_Test_Condition_1_Block');
/*inserting data into block -FTHLG_SUM_Test_Condition_2_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTHLG_SUM_Test_Condition_2_Block',__file_format,__sheet_mnemonic,4);
insert into mmt_staging2.FTHLG_SUM_Test_Condition_2_Block
(
dummy_f,
Test_Condition,
Test_Date,
Tractor_Model,
Fuel_consumption_Ltr_hr,
Mileage_Km_Ltr,
Average_speed_of_travel_kmph,
Total_distance_travelled_km,
Gear_used_on_Straight_Road,
Straight_road_RPM_Drop,
Gear_used_on_Up_Slope_1,
Up_Slope_RPM_Drop_1,
Gear_used_on_Up_Slope_2,
Up_Slope_RPM_Drop_2,
Gear_used_on_Down_Slope,
Down_Slope_RPM_Shoot_up,
M_M_Performance_compared_to_respective_competitor_tractors_is_better_and_is_poor_than_competitor,
Fuel_consumption_lit_hr_2,
Mileage_Km_Ltr_2,
M_M_Performance_in_compared_to_respective_competitor_tractors,
Fuel_consumption_lit_hr_3,
Mileage_Km_Ltr_3,
Engine_Smoke_on_Load,
Engine_acceleration_smoke,
Range_Gear_Shifting,
Speed_Gear_Shifting,
Tractor_Steer_ability,
Tractor_braking_performance,
Front_Visibility,
Implement_Accessibility,
Front_end_lifting_during_operation,
RPM_Recovery_Time,
Engine_Vibration,
Engine_Sound
)
SELECT *
FROM crosstab(
'SELECT unnest(''{column3,column4,column5,column6,column7,column8,column9,column10,column11,column12}''::text[]) AS col
, row_number() OVER ()
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text,column8::text,column9::text,column10::text,column11::text,column12::text]) AS val
FROM mmt_staging2.stg_process_table_fthlg_sum where rank_tag=''FTHLG_SUM_Test_Condition_2''
ORDER BY generate_series(1,15),rank,2'
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,
a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text,a_21 text,
a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text,a_31 text
,a_32 text,a_33 text);
delete from mmt_staging2.FTHLG_SUM_Test_Condition_2_Block where dummy_f is null ;
execute 'update mmt_staging2.FTHLG_SUM_Test_Condition_2_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTHLG_SUM_Test_Condition_2_Block');
/*inserting data into block -FTHLG_SUM_Comments_By_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTHLG_SUM_Comments_By_Block',__file_format,__sheet_mnemonic,5);
insert into mmt_staging2.FTHLG_SUM_Comments_By_Block (dummy_f) values
('dummy');
execute 'update mmt_staging2.FTHLG_SUM_Comments_By_Block set test_engineer_comments_1=
(select column3 from mmt_staging2.stg_process_table_fthlg_sum a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.rank_tag=''FTHLG_SUM_Engineer_Comments_1''
and rank=1 ) where dummy_f=''dummy''' ;
execute 'update mmt_staging2.FTHLG_SUM_Comments_By_Block set test_engineer_comments_2=
(select column3 from mmt_staging2.stg_process_table_fthlg_sum a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.rank_tag=''FTHLG_SUM_Engineer_Comments_2''
and rank=1 ) where dummy_f=''dummy''';
execute 'update mmt_staging2.FTHLG_SUM_Comments_By_Block set test_manager_comments_1=
(select column3 from mmt_staging2.stg_process_table_fthlg_sum a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.rank_tag=''FTHLG_SUM_Manager_Comments_1''
and rank=1 ) where dummy_f=''dummy''';
execute 'update mmt_staging2.FTHLG_SUM_Comments_By_Block set test_manager_comments_2=
(select column3 from mmt_staging2.stg_process_table_fthlg_sum a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.rank_tag=''FTHLG_SUM_Manager_Comments_2''
and rank=1 ) where dummy_f=''dummy''';
delete from mmt_staging2.FTHLG_SUM_Comments_By_Block where dummy_f is null ;
execute 'update mmt_staging2.FTHLG_SUM_Comments_By_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTHLG_SUM_Comments_By_Block');
end
$$ LANGUAGE plpgsql;

View File

@@ -0,0 +1,414 @@
drop function if exists mmt_staging2.fn_fthlg_trs_block;
CREATE OR REPLACE FUNCTION mmt_staging2.fn_fthlg_trs_block(p_client_id int,p_function_id int, p_file_format text,
p_sheet_mnemonic text, p_file_syspk int)
RETURNS void AS $$
declare __client_id int :=p_client_id;
declare __function_id int :=p_function_id;
declare __file_format text :=p_file_format;
declare __sheet_mnemonic text :=p_sheet_mnemonic;
declare __file_syspk int :=p_file_syspk;
begin
/***********************************************************************************
Function Name:fn_FTHLG_TRS_Block
Function Desc: This function populates data into staging2 blocks
File Format: FTHLG
Sheet Format: FTHLG_TRS
Creation Date:
Updation Date:
Author: compegence team
Function Call: select mmt_staging2.fn_fthlg_trs_block(20,1,'FTHLG','FTHLG_TRS',259);
************************************************************************************/
SET search_path TO mmt_staging2;
truncate mmt_staging2.FTHLG_TRS_H1_INT;
truncate mmt_staging2.FTHLG_TRS_H1_Block;
truncate mmt_staging2.FTHLG_TRS_SPEC_Block;
truncate mmt_staging2.FTHLG_TRS_Engine_RPM_Block;
truncate mmt_staging2.FTHLG_TRS_Trailer_Block;
truncate mmt_staging2.stg_specific_table_fthlg_trs;
truncate mmt_staging2.stg_process_table_fthlg_trs;
execute 'delete from mmt_ods.fw_jobctrl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=null,
row_previous_number=null,
row_read_end=null,
run_time=null
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* transfer data from generic to specific for ftdry*/
execute 'insert into mmt_staging2.stg_specific_table_fthlg_trs
select * from mmt_staging1.mmt_staging_generic_table a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.file_syspk='||p_file_syspk||'';
/* trimming data */
update mmt_staging2.stg_specific_table_fthlg_trs set column2 = TRIM (TRAILING FROM column2 );
update mmt_staging2.stg_specific_table_fthlg_trs set column2 = TRIM (LEADING FROM column2 );
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified);
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified);
update mmt_ods.mmt_config set F1_source=F1_modified;
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source);
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source);
/* keyword match in config table*/
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_staging2.stg_specific_table_fthlg_trs b
where F1_source=column2
and b.is_rownumber_fetched is null)
where a.row_number_start is null and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* reverese update in process table for match*/
execute 'update mmt_staging2.stg_specific_table_fthlg_trs a
set is_rownumber_fetched=1
from mmt_ods.mmt_config b
where F1_source=column2
and b.row_number_start=a.row_number
and is_rownumber_fetched is null and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* update config files for row numbers start, end */
execute 'update mmt_ods.mmt_config a
set row_read_end= (select b.row_number_start
from mmt_ods.mmt_config b
where b.syspk=a.syspk+1 )
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* config file last field update as null otherwise it picks up next format row number*/
execute 'update mmt_ods.mmt_config a set row_read_end = null where f1_modified =''Trailer Details'' and
a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/*inserting run_time in config*/
execute 'update mmt_ods.mmt_config a
set run_time=current_timestamp where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* tagging ranks for each block in process table*/
execute 'insert into mmt_staging2.stg_process_table_fthlg_trs
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_fthlg_trs a
join mmt_ods.mmt_config b
on a.row_number >row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Tractor specifications sheet'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_fthlg_trs
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_fthlg_trs a
join mmt_ods.mmt_config b
on a.row_number >row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Tractor Specifications'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_fthlg_trs
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_fthlg_trs a
join mmt_ods.mmt_config b
on a.row_number >row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Engine RPM Data:'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_fthlg_trs
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_fthlg_trs a
join mmt_ods.mmt_config b
on a.row_number >row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Trailer Details'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
/*inserting data into FTHLG_TRS_H1_INT*/
insert into mmt_staging2.FTHLG_TRS_H1_INT
(column2,column3,column4,column5,column6,column7,rank)
select column2,column3,column4,column5,column6,column7,rank from mmt_staging2.stg_process_table_fthlg_trs a
where rank_tag='FTHLG_TRS_H1' order by rank;
insert into mmt_staging2.FTHLG_TRS_H1_INT(column2) values ('Date of Test');
insert into mmt_staging2.FTHLG_TRS_H1_INT(column2) values ('Report Date');
insert into mmt_staging2.FTHLG_TRS_H1_INT(column2) values ('Type of Road');
insert into mmt_staging2.FTHLG_TRS_H1_INT (column2) values ('Tractor Hitch Height from Ground, mm');
insert into mmt_staging2.FTHLG_TRS_H1_INT (column2) values ('Tractor Rear Wheel Center to Hitch Point Center Distance, mm');
update mmt_staging2.FTHLG_TRS_H1_INT a
set column3=(select column5 from mmt_staging2.FTHLG_TRS_H1_INT b
where trim(a.column2)=trim(b.column4)
and b.column4='Date of Test')
where a.column2='Date of Test';
update mmt_staging2.FTHLG_TRS_H1_INT a
set column3=(select column7 from mmt_staging2.FTHLG_TRS_H1_INT b
where trim(a.column2)=trim(b.column6)
and b.column6='Report Date')
where a.column2='Report Date';
update mmt_staging2.FTHLG_TRS_H1_INT a
set column3=(select column6 from mmt_staging2.FTHLG_TRS_H1_INT b
where trim(a.column2)=trim(b.column5)
and b.column5='Type of Road')
where a.column2='Type of Road';
update mmt_staging2.FTHLG_TRS_H1_INT a
set column3=(select column6 from mmt_staging2.FTHLG_TRS_H1_INT b
where trim(a.column2)=trim(b.column5)
and b.column5='Tractor Hitch Height from Ground, mm')
where a.column2='Tractor Hitch Height from Ground, mm';
update mmt_staging2.FTHLG_TRS_H1_INT a
set column3=(select column6 from mmt_staging2.FTHLG_TRS_H1_INT b
where trim(a.column2)=trim(b.column5)
and b.column5='Tractor Rear Wheel Center to Hitch Point Center Distance, mm')
where a.column2='Tractor Rear Wheel Center to Hitch Point Center Distance, mm';
/*inserting data into block -.FTHLG_TRS_H1_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTHLG_TRS_H1_Block',__file_format,__sheet_mnemonic,1);
insert into mmt_staging2.FTHLG_TRS_H1_Block
(
dummy_f,
Report_Reference_No,
Objective_Of_Test,
Background_of_Test,
Job_Order_No,
Test_Location,
Gradient_Slope_1_Degree,
Gradient_Slope_2_Degree,
Tractor_Hitch_Type,
Test_Engineer,
Test_Operator,
Date_of_Test,
Report_Date,
Type_of_Road,
Tractor_Hitch_Height_from_Ground_mm,
Tractor_Rear_Wheel_Center_to_Hitch_Point_Center_Distance_mm
)
SELECT *
FROM crosstab(
'SELECT unnest(''{column3}''::text[]) AS col
, row_number() OVER ()
, unnest(ARRAY[column3::text]) AS val
FROM mmt_staging2.FTHLG_TRS_H1_INT
ORDER BY generate_series(1,15),rank,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 mmt_staging2.FTHLG_TRS_H1_Block where dummy_f is null ;
execute 'update mmt_staging2.FTHLG_TRS_H1_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTHLG_TRS_H1_Block');
/*inserting data into block -FTHLG_TRS_SPEC_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTHLG_TRS_SPEC_Block',__file_format,__sheet_mnemonic,2);
insert into mmt_staging2.FTHLG_TRS_SPEC_Block
(
dummy_f,
Tractor_Model,
Tractor_Make,
Tractor_Sr_No,
Tractor_Engine_HP,
FIP_Type,
hour_Meter_Reading,
Steering_Type,
Transmission_Type,
Wheel_Drive_Type_WD,
EGR_Yes_No,
Brake_Type,
PTO_Type,
Standard_PTO_Speed_RPM,
EPTO_Speed_RPM,
Front_Tyre_Make,
Front_Tyre_Size,
Front_Tyre_Pressure_psi,
Rear_Tyre_Make,
Rear_Tyre_Size,
Rear_Tyre_Pressure_psi ,
Tractor_Weight_kg_Front ,
Tractor_Weight_kg_Rear ,
Tractor_Weight_kg_Total,
Ballasted_Tractor_Accessories,
Mechanical_Ballast_Rear,
Mechanical_Ballast_Rear_in_KG ,
Water_Ballast_Rear_75,
Mechanical_Ballast_Front_in_Kg,
Mechanical_Ballast_Front,
Total_Ballast_Weight
)
SELECT *
FROM crosstab(
'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col
, row_number() OVER ()
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val
FROM mmt_staging2.stg_process_table_fthlg_trs where rank_tag=''FTHLG_TRS_SPEC''
ORDER BY generate_series(1,15),rank,2'
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,
a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text,a_21 text,
a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text);
delete from mmt_staging2.FTHLG_TRS_SPEC_Block where dummy_f is null ;
execute 'update mmt_staging2.FTHLG_TRS_SPEC_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTHLG_TRS_SPEC_Block');
/*inserting data into block -FTHLG_TRS_Engine_RPM_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTHLG_TRS_Engine_RPM_Block',__file_format,__sheet_mnemonic,3);
insert into mmt_staging2.FTHLG_TRS_Engine_RPM_Block
(
dummy_f,
Tractor_model,
Tractor_make,
Low_Idle,
High_Idle,
Rated_RPM,
Engine_to_PTO_Ratio_540_PTO,
Engine_to_PTO_Ratio_540E_PTO
)
SELECT *
FROM crosstab(
'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col
, row_number() OVER ()
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val
FROM mmt_staging2.stg_process_table_fthlg_trs where rank_tag=''FTHLG_TRS_Engine_RPM''
or (rank_tag=''FTHLG_TRS_SPEC'' and rank in (1,2))
ORDER BY generate_series(1,15),2'
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text);
delete from mmt_staging2.FTHLG_TRS_Engine_RPM_Block where dummy_f is null ;
execute 'update mmt_staging2.FTHLG_TRS_Engine_RPM_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTHLG_TRS_Engine_RPM_Block');
/*inserting data into block -FTHLG_TRS_Trailer_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTHLG_TRS_Trailer_Block',__file_format,__sheet_mnemonic,4);
insert into mmt_staging2.FTHLG_TRS_Trailer_Block
(
dummy_f,
Type_Of_Trailer,
No_Of_Axle,
No_Of_Wheels,
Trailer_hitch_Height_above_ground_level_mm,
Make_model_of_trailer,
Trailer_platform_length_mm,
Trailer_platform_Width_mm,
Trailer_platform_Height_mm,
Tire_size,
Inflation_pressure_psi,
Track_width_of_trailer_mm,
Horizontal_distance_of_hitch_point_from_trailer_front_face_mm,
Tractor_Rear_Wheel_Center_to_Hitch_Point_Center_Distance_mm,
Distance_from_Trailerfront_axle_distance_from_hitch_point_mm,
Distance_from_tractor_rear_wheel_center_to_tractor_rear_wheel_center_mm,
Trailer_empty_weight_Kg,
Trailer_Gross_Weight_Kg
)
SELECT *
FROM crosstab(
'SELECT unnest(''{column3,column4,column5,column6}''::text[]) AS col
, row_number() OVER ()
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text]) AS val
FROM mmt_staging2.stg_process_table_fthlg_trs where rank_tag=''FTHLG_TRS_Trailer'' and rank <=17
ORDER BY generate_series(1,15),rank,2'
) t ( col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text
,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text);
update mmt_staging2.FTHLG_TRS_Trailer_Block set report_template_no=
(select column2 from mmt_staging2.stg_process_table_fthlg_trs where rank=18
and rank_tag='FTHLG_TRS_Trailer')where make_model_of_trailer is not null;
update mmt_staging2.FTHLG_TRS_Trailer_Block set report_template_rev_no=
(select column4 from mmt_staging2.stg_process_table_fthlg_trs where rank=18
and rank_tag='FTHLG_TRS_Trailer')where make_model_of_trailer is not null;
update mmt_staging2.FTHLG_TRS_Trailer_Block set report_template_rev_date=
(select column6 from mmt_staging2.stg_process_table_fthlg_trs where rank=18 and
rank_tag='FTHLG_TRS_Trailer')where make_model_of_trailer is not null;
execute 'update mmt_staging2.FTHLG_TRS_Trailer_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTHLG_TRS_Trailer_Block');
end
$$ LANGUAGE plpgsql;

View File

@@ -0,0 +1,368 @@
drop function if exists mmt_staging2.fn_FTWET_SUM_Block ;
CREATE OR REPLACE FUNCTION mmt_staging2.fn_FTWET_SUM_Block(p_client_id int,p_function_id int, p_file_format text,
p_sheet_mnemonic text, p_file_syspk int)
RETURNS void AS $$
declare __client_id int :=p_client_id;
declare __function_id int :=p_function_id;
declare __file_format text :=p_file_format;
declare __sheet_mnemonic text :=p_sheet_mnemonic;
declare __file_syspk int :=p_file_syspk;
begin
/***********************************************************************************
Function Name:fn_FTWET_SUM_Block
Function Desc: This function populates data into staging2 blocks
File Format: FTWET
Sheet Format: FTWET_SUM
Creation Date:
Updation Date:
Author: compegence team
Function Call: select mmt_staging2.fn_fthlg_sum_block(20,1,'FTWET','FTWET_SUM',119);
************************************************************************************/
SET search_path TO mmt_staging2;
truncate mmt_staging2.FTWET_SUM_Trac_H1_Block;
truncate mmt_staging2.FTWET_SUM_Implement_Block;
truncate mmt_staging2.FTWET_SUM_Cage_Wheel_Block;
truncate mmt_staging2.FTWET_SUM_Test_Condition_Block;
truncate mmt_staging2.FTWET_SUM_Comments_By_Block;
truncate mmt_staging2.stg_specific_table_ftwet_sum;
truncate mmt_staging2.stg_process_table_ftwet_sum;
execute 'delete from mmt_ods.fw_jobctrl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=null,
row_previous_number=null,
row_read_end=null,
run_time=null
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* transfer data from generic to specific for ftwet*/
execute 'insert into mmt_staging2.stg_specific_table_ftwet_sum
select * from mmt_staging1.mmt_staging_generic_table a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.file_syspk='||p_file_syspk||'';
/* trimming data */
update mmt_staging2.stg_specific_table_ftwet_sum set column2 = TRIM (TRAILING FROM column2 );
update mmt_staging2.stg_specific_table_ftwet_sum set column2 = TRIM (LEADING FROM column2 );
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified);
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified) ;
update mmt_ods.mmt_config set F1_source=F1_modified;
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source);
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source);
/* keyword match in config table*/
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_staging2.stg_specific_table_ftwet_sum b
where F1_source=column2
and b.is_rownumber_fetched is null)
where a.row_number_start is null
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* reverese update in process table for match*/
execute 'update mmt_staging2.stg_specific_table_ftwet_sum a
set is_rownumber_fetched=1
from mmt_ods.mmt_config b
where F1_source=column2
and b.row_number_start=a.row_number
and is_rownumber_fetched is null and
a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* keyword match in config table*/
execute 'update mmt_ods.mmt_config a
set row_read_end= (select b.row_number_start
from mmt_ods.mmt_config b
where b.syspk=a.syspk+1 )
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* config file last field update as null otherwise it picks up next format row number*/
execute 'update mmt_ods.mmt_config a set row_read_end = null where f1_modified =''Test Manager Comments'' and
a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/*inserting run_time in config*/
execute 'update mmt_ods.mmt_config a
set run_time=current_timestamp
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* tagging ranks for each block in process table*/
execute 'insert into mmt_staging2.stg_process_table_ftwet_sum
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_ftwet_sum a
join mmt_ods.mmt_config b
on a.row_number >=row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Tractor Model'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_ftwet_sum
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_ftwet_sum a
join mmt_ods.mmt_config b
on a.row_number >=row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Make of Implement'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_ftwet_sum
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_ftwet_sum a
join mmt_ods.mmt_config b
on a.row_number >=row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Type of Cage Wheel'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_ftwet_sum
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_ftwet_sum a
join mmt_ods.mmt_config b
on a.row_number >=row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Test Condition:'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_ftwet_sum
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_ftwet_sum a
join mmt_ods.mmt_config b
on a.row_number >=row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Test Manager Comments'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
/*inserting data into block -FTWET_SUM_Trac_H1_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTWET_SUM_Trac_H1_Block',__file_format,__sheet_mnemonic,1);
insert into mmt_staging2.FTWET_SUM_Trac_H1_Block
(
Tractor_Model,
Tractor_Make,
Tractor_Engine_HP,
Rated_RPM,
Transmission_Type,
Wheel_Drive_Type,
FIP_Type,
Steering_Type,
Tractor_Weight_kg_Front,
Tractor_Weight_kg_Rear,
Tractor_Weight_kg_Total,
rank
)
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,rank
from mmt_staging2.stg_process_table_FTWET_sum
where rank_tag='FTWET_SUM_Trac_H1'
order by rank;
update mmt_staging2.FTWET_SUM_Trac_H1_Block set ods_record=0 where rank=1;
execute 'update mmt_staging2.FTWET_SUM_Trac_H1_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTWET_SUM_Trac_H1_Block');
/*inserting data into block -FTWET_SUM_Implement_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTWET_SUM_Implement_Block',__file_format,__sheet_mnemonic,2);
insert into mmt_staging2.FTWET_SUM_Implement_Block
(
Make_of_Implement,
Implement_Type,
Implement_Size,
Hitch_Category,
Implement_Weight,
Soil_Type,
Moisture_Content ,
Bulk_Density_g_cc ,
Soil_Cone_index,
Field_Condition ,
Season,
rank
)
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,rank
from mmt_staging2.stg_process_table_FTWET_sum
where rank_tag='FTWET_SUM_Impement'
order by rank;
execute 'update mmt_staging2.FTWET_SUM_Implement_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
update mmt_staging2.FTWET_SUM_Implement_Block set ods_record=0 where rank=1;
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTWET_SUM_Implement_Block');
/*inserting data into block -FTWET_SUM_Cage_Wheel_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTWET_SUM_Cage_Wheel_Block',__file_format,__sheet_mnemonic,3);
insert into mmt_staging2.FTWET_SUM_Cage_Wheel_Block
(
Type_of_Cage_Wheel,
Cage_Wheel_Width_mm,
Cage_wheel_Weight,
Cage_Wheel_inner_Outer_Ring_Dia_mm,
Cage_Wheel_Center_Ring_Dia_mm,
Distance_between_RHS_LHS_cage_wheel_Inner_Ring_mm,
No_of_angles_on_cage_wheel,
rank
)
select column2,column3,column4,column5,column6,column7,column8,rank
from mmt_staging2.stg_process_table_FTWET_sum
where rank_tag='FTWET_SUM_Cage_Wheel'
order by rank;
update mmt_staging2.FTWET_SUM_Cage_Wheel_Block
set ods_record=0 where rank in (1,3);
execute 'update mmt_staging2.FTWET_SUM_Cage_Wheel_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTWET_SUM_Cage_Wheel_Block');
/*inserting data into block -FTWET_SUM_Test_Condition_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTWET_SUM_Test_Condition_Block',__file_format,__sheet_mnemonic,4);
insert into mmt_staging2.FTWET_SUM_Test_Condition_Block
(
dummy_f,
Test_Condition,
Test_Date,
Tractor_Model,
Engine_RPM_set,
PTO_RPM_set,
Gear_Used,
Nominal_Speed_KMPH,
Engine_RPM_Drop_on_straight_1st_Pass,
Engine_RPM_Drop_on_straight_2nd_Pass,
Engine_RPM_Drop_on_straight_3rd_Pass,
Engine_RPM_Drop_on_turn_1st_Pass,
Engine_RPM_Drop_on_turn_2nd_Pass,
Engine_RPM_Drop_on_turn_3rd_Pass,
No_of_passes,
Avg_Depth_of_cut_cm,
Fuel_consumption_lit_hr,
Area_covered_acr_hr,
Fuel_consumption_lit_Acr,
M_M_Performance_in_compared_to_respective_competitor_tractors,
Fuel_consumption_lit_hr_2,
Area_covered_acr_hr_2,
Fuel_consumption_lit_Acr_2,
Trail_Observations,
Engine_Smoke_on_Load,
Engine_acceleration_smoke,
Draft_Response,
Tractor_Steer_ability,
Tractor_braking_performance,
Front_Visibility,
Implement_Accessibility,
Front_Wheel_dragging_at_turning,
Front_end_lifting_during_operation,
RPM_Recovery_Time,
Engine_Vibration,
Engine_Sound,
Implement_Lifting_Lowering_response,
Pulverization_Quality,
Pulverization_Index
)
SELECT *
FROM crosstab(
'SELECT unnest(''{column3,column4,column5,column6,column7,column8,column9,column10,column11,column12}''::text[]) AS col
, row_number() OVER ()
, unnest(ARRAY[column3::text,
column4::text,column5::text,column6::text,column7::text,column8::text,
column9::text,column10::text,column11::text,column12::text]) AS val
FROM mmt_staging2.stg_process_table_ftwet_sum where rank_tag=''FTWET_SUM_Test_Condition''
ORDER BY generate_series(1,15),rank,2'
) t (ccol text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text,
a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text
,a_21 text,a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text,
a_31 text,a_32 text,a_33 text,a_34 text,a_35 text,a_36 text,a_37 text,a_38 text);
delete from mmt_staging2.FTWET_SUM_Test_Condition_Block where dummy_f is null ;
execute 'update mmt_staging2.FTWET_SUM_Test_Condition_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTWET_SUM_Test_Condition_Block');
/*inserting data into block -FTWET_SUM_Comments_By_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTWET_SUM_Comments_By_Block',__file_format,__sheet_mnemonic,5);
insert into mmt_staging2.FTWET_SUM_Comments_By_Block (dummy_f) values ('dummy');
execute 'update mmt_staging2.FTWET_SUM_Comments_By_Block set test_manager_comments=
(select column3 from mmt_staging2.stg_process_table_FTWET_sum a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.rank_tag=''FTWET_SUM_Manager_Comments''
and a.rank=1 ) where dummy_f=''dummy''';
delete from mmt_staging2.FTWET_SUM_Comments_By_Block where dummy_f is null ;
execute 'update mmt_staging2.FTWET_SUM_Comments_By_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTWET_SUM_Comments_By_Block');
end
$$ LANGUAGE plpgsql;

View File

@@ -0,0 +1,415 @@
/*FTWET_TRS starts*/
drop function if exists mmt_staging2.fn_FTWET_TRS_Block ;
CREATE OR REPLACE FUNCTION mmt_staging2.fn_FTWET_TRS_Block(p_client_id int,p_function_id int, p_file_format text,
p_sheet_mnemonic text, p_file_syspk int)
RETURNS void AS $$
declare __client_id int :=p_client_id;
declare __function_id int :=p_function_id;
declare __file_format text :=p_file_format;
declare __sheet_mnemonic text :=p_sheet_mnemonic;
declare __file_syspk int :=p_file_syspk;
begin
/***********************************************************************************
Function Name:fn_FTWET_TRS_Block
Function Desc: This function populates data into staging2 blocks
File Format: FTWET
Sheet Format: FTWET_TRS
Creation Date:
Updation Date:
Author: compegence team
Function Call: select mmt_staging2.fn_fthlg_trs_block(20,1,'FTHLG','FTWET_TRS',260);
************************************************************************************/
SET search_path TO mmt_staging2;
truncate mmt_staging2.FTWET_TRS_H1_INT;
truncate mmt_staging2.FTWET_TRS_H1_Block;
truncate mmt_staging2.FTWET_TRS_Engine_RPM_Block;
truncate mmt_staging2.FTWET_TRS_Implement_Block;
truncate mmt_staging2.stg_specific_table_ftwet_trs;
truncate mmt_staging2.stg_process_table_ftwet_trs;
execute 'delete from mmt_ods.fw_jobctrl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a
set row_number_start=null,
row_previous_number=null,
row_read_end=null,
run_time=null
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* transfer data from generic to specific for ftdry*/
execute 'insert into mmt_staging2.stg_specific_table_ftwet_trs
select * from mmt_staging1.mmt_staging_generic_table a
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''
and a.file_syspk='||p_file_syspk||'';
update mmt_staging2.stg_specific_table_ftwet_trs set column2 = TRIM (TRAILING FROM column2 );
update mmt_staging2.stg_specific_table_ftwet_trs set column2 = TRIM (LEADING FROM column2 );
/* trimming data */
update mmt_ods.mmt_config set F1_modified = TRIM (TRAILING FROM F1_modified);
update mmt_ods.mmt_config set F1_modified = TRIM (LEADING FROM F1_modified);
update mmt_ods.mmt_config set F1_source=F1_modified ;
update mmt_ods.mmt_config set F1_source = TRIM (TRAILING FROM F1_source);
update mmt_ods.mmt_config set F1_source = TRIM (LEADING FROM F1_source);
/* keyword match in config table*/
execute 'update mmt_ods.mmt_config a
set row_number_start=(select min(b.row_number)
from mmt_staging2.stg_specific_table_ftwet_trs b
where upper(trim(F1_source))=upper(trim(column2))
and b.is_rownumber_fetched is null)
where a.row_number_start is null
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* reverese update in process table for match*/
execute 'update mmt_staging2.stg_specific_table_ftwet_trs a
set is_rownumber_fetched=1
from mmt_ods.mmt_config b
where upper(trim(F1_source))=upper(trim(column2))
and b.row_number_start=a.row_number
and is_rownumber_fetched is null
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
execute 'update mmt_ods.mmt_config a set row_previous_number=row_number_start-1
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* update config files for row numbers start, end */
execute 'update mmt_ods.mmt_config a
set row_read_end= (select b.row_number_start
from mmt_ods.mmt_config b
where b.syspk=a.syspk+1 )
where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* config file last field update as null otherwise it picks up next format row number*/
execute 'update mmt_ods.mmt_config a set row_read_end = null where f1_modified =''Implement Details''
and a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/*inserting run_time in config*/
execute 'update mmt_ods.mmt_config a
set run_time=current_timestamp where a.file_format='''||p_file_format||''' and a.sheet_mnemonic='''||p_sheet_mnemonic||'''';
/* tagging ranks for each block in process table*/
execute 'insert into mmt_staging2.stg_process_table_ftwet_trs
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_ftwet_trs a
join mmt_ods.mmt_config b
on a.row_number >row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Tractor Specifications Sheet'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_ftwet_trs
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_ftwet_trs a
join mmt_ods.mmt_config b
on a.row_number >row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Tractor Specifications'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_ftwet_trs
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_ftwet_trs a
join mmt_ods.mmt_config b
on a.row_number >row_number_start
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Engine RPM Data:'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
execute 'insert into mmt_staging2.stg_process_table_ftwet_trs
select a.* , RANK () OVER ( ORDER BY row_number),b.rank_tag as rank_tag
from mmt_staging2.stg_specific_table_ftwet_trs a
join mmt_ods.mmt_config b
on a.row_number >row_number_start
and a.column2 <> ''''
and (a.row_number< row_read_end or row_read_end is null)
and f1_modified=''Implement Details'' and b.file_format='''||p_file_format||''' and b.sheet_mnemonic='''||p_sheet_mnemonic||'''
order by a.row_number';
/*inserting data into FTHLG_TRS_H1_INT*/
insert into mmt_staging2.FTWET_TRS_H1_INT(column2,column3,column4,column5,column6,column7,rank)
select column2,column3,column4,column5,column6,column7,rank from mmt_staging2.stg_process_table_ftwet_trs a
where rank_tag='FTWET_TRS_H1';
insert into mmt_staging2.FTWET_TRS_H1_INT(column2) values ('Date of Test');
insert into mmt_staging2.FTWET_TRS_H1_INT(column2) values ('Report Date');
insert into mmt_staging2.FTWET_TRS_H1_INT(column2) values ('Season');
insert into mmt_staging2.FTWET_TRS_H1_INT (column2) values ('Type of Soil');
insert into mmt_staging2.FTWET_TRS_H1_INT (column2) values ('Soil Cone Index (kPa)');
insert into mmt_staging2.FTWET_TRS_H1_INT (column2) values ('Field Condition');
update mmt_staging2.FTWET_TRS_H1_INT a
set column3=(select column5 from mmt_staging2.FTWET_TRS_H1_INT b
where trim(a.column2)=trim(b.column4)
and b.column4='Date of Test')
where a.column2='Date of Test';
update mmt_staging2.FTWET_TRS_H1_INT a
set column3=(select column7 from mmt_staging2.FTWET_TRS_H1_INT b
where trim(a.column2)=trim(b.column6)
and b.column6='Report Date')
where a.column2='Report Date';
update mmt_staging2.FTWET_TRS_H1_INT a
set column3=(select column6 from mmt_staging2.FTWET_TRS_H1_INT b
where trim(a.column2)=trim(b.column5)
and b.column5='Season')
where a.column2='Season';
update mmt_staging2.FTWET_TRS_H1_INT a
set column3=(select column6 from mmt_staging2.FTWET_TRS_H1_INT b
where trim(a.column2)=trim(b.column5)
and b.column5='Type of Soil')
where a.column2='Type of Soil';
update mmt_staging2.FTWET_TRS_H1_INT a
set column3=(select column6 from mmt_staging2.FTWET_TRS_H1_INT b
where trim(a.column2)=trim(b.column5)
and b.column5='Soil Cone Index (kPa)')
where a.column2='Soil Cone Index (kPa)';
update mmt_staging2.FTWET_TRS_H1_INT a
set column3=(select column6 from mmt_staging2.FTWET_TRS_H1_INT b
where trim(a.column2)=trim(b.column5)
and b.column5='Field Condition')
where a.column2='Field Condition';
/*inserting data into block -.FTWET_TRS_H1_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTWET_TRS_H1_Block',__file_format,__sheet_mnemonic,1);
insert into mmt_staging2.FTWET_TRS_H1_Block
(
dummy_f,
Report_Reference_No,
Objective_Of_Test,
Background_of_Test,
Job_Order_No,
Test_Location,
Soil_Moisture_Content_,
Soil_Bulk_Density_g_cc,
Test_Engineer,
Test_Operator,
Date_of_Test,
Report_Date,
Season,
Type_of_Soil,
Soil_Cone_Index_kPa,
Field_Condition
)
SELECT *
FROM crosstab(
'SELECT unnest(''{column3}''::text[]) AS col
, row_number() OVER ()
, unnest(ARRAY[column3::text]) AS val
FROM mmt_staging2.FTWET_TRS_H1_INT
ORDER BY generate_series(1,15),rank,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 mmt_staging2.FTWET_TRS_H1_Block where dummy_f is null ;
execute 'update mmt_staging2.FTWET_TRS_H1_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTWET_TRS_H1_Block');
/*inserting data into block -FTWET_TRS_SPEC_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTWET_TRS_SPEC_Block',__file_format,__sheet_mnemonic,2);
insert into mmt_staging2.FTWET_TRS_SPEC_Block
(
dummy_f,
Tractor_Model,
Tractor_Make,
Tractor_Sr_No,
Tractor_Engine_HP,
FIP_Type,
hour_Meter_Reading,
Steering_Type,
Transmission_Type,
Wheel_Drive_Type_WD,
EGR_Yes_No,
Brake_Type,
PTO_Type,
Standard_PTO_Speed_RPM,
EPTO_Speed_RPM,
Front_Tyre_Make,
Front_Tyre_Size,
Front_Tyre_Pressure_psi,
Rear_Tyre_Make,
Rear_Tyre_Size,
Rear_Tyre_Pressure_psi ,
Tractor_Weight_kg_Front ,
Tractor_Weight_kg_Rear ,
Tractor_Weight_kg_Total,
Ballasted_Tractor_Accessories,
Mechanical_Ballast_Rear_in_KG ,
Water_Ballast_Rear,
Mechanical_Ballast_Front,
Mechanical_Ballast_Front_in_Kg,
Total_Ballast_Weight
)
SELECT *
FROM crosstab(
'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col
, row_number() OVER ()
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val
FROM mmt_staging2.stg_process_table_ftwet_trs where rank_tag=''FTWET_TRS_SPEC''
ORDER BY generate_series(1,15),rank,2'
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,
a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text,a_21 text,
a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text);
delete from mmt_staging2.FTWET_TRS_SPEC_Block where dummy_f is null ;
execute 'update mmt_staging2.FTWET_TRS_SPEC_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTWET_TRS_SPEC_Block');
/*inserting data into block -FTWET_TRS_SPEC_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTWET_TRS_Engine_RPM_Block',__file_format,__sheet_mnemonic,3);
insert into mmt_staging2.FTWET_TRS_Engine_RPM_Block
(
dummy_f,
Tractor_model,
Tractor_make,
Low_Idle,
High_Idle,
Rated_RPM,
Engine_to_PTO_Ratio_540_PTO,
Engine_to_PTO_Ratio_540E_PTO
)
SELECT *
FROM crosstab(
'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col
, row_number() OVER ()
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val
FROM mmt_staging2.stg_process_table_ftwet_trs where rank_tag=''FTWET_TRS_Engine_RPM''
or (rank_tag=''FTWET_TRS_SPEC'' and rank in (1,2))
ORDER BY generate_series(1,15),2'
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text);
delete from mmt_staging2.FTWET_TRS_Engine_RPM_Block where dummy_f is null ;
execute 'update mmt_staging2.FTWET_TRS_Engine_RPM_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTWET_TRS_Engine_RPM_Block');
/*inserting data into block -FTWET_TRS_Implement_Block*/
perform mmt_staging2.fn_jobctrl_block_begin(__client_id,__function_id,__file_syspk,
'FTWET_TRS_Implement_Block',__file_format,__sheet_mnemonic,4);
insert into mmt_staging2.FTWET_TRS_Implement_Block
(
dummy_f,
Name_of_Implement,
Type_of_Implement,
Make_of_Implement,
No_of_bottoms_Tyne_Disc_Blade,
Cutting_Width_m,
Implement_Weight_Kg,
Hitch_Category,
Span_cm_For_Mounted_Implement,
Mast_Height_cm_For_Mounted_Implement,
Type_of_Cage_Wheel_Half_Cage_wheel_Full_Cage_Wheel,
Cage_Wheel_Width_mm,
Cage_wheel_Weight,
Cage_Wheel_inner_Outer_Ring_Dia_mm,
Cage_Wheel_Center_Ring_Dia_mm,
Distance_between_RHS_LHS_cage_wheel_Inner_Ring_mm_For_Full_Cage_wheel,
No_of_angles_on_cage_wheel,
No_of_days_of_water_logging,
Depth_of_water_mm ,
)
SELECT *
FROM crosstab(
'SELECT unnest(''{column3,column4,column5,column6}''::text[]) AS col
, row_number() OVER ()
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text]) AS val
FROM mmt_staging2.stg_process_table_ftwet_trs where rank_tag=''FTWET_TRS_Implement''
ORDER BY generate_series(1,15),rank,2'
) t ( col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text
,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text);
update mmt_staging2.FTWET_TRS_Implement_Block set report_template_no= (select column2 from mmt_staging2.stg_process_table_ftwet_trs where rank=19 and rank_tag='FTWET_TRS_Implement');
update mmt_staging2.FTWET_TRS_Implement_Block set report_template_rev_no= (select column4 from mmt_staging2.stg_process_table_ftwet_trs where rank=19 and rank_tag='FTWET_TRS_Implement');
update mmt_staging2.FTWET_TRS_Implement_Block set report_template_rev_date= (select column6 from mmt_staging2.stg_process_table_ftwet_trs where rank=19 and rank_tag='FTWET_TRS_Implement');
execute 'update mmt_staging2.FTWET_TRS_Implement_Block set
client_id='||p_client_id||',
function_id='||p_function_id||',
file_syspk='||p_file_syspk||',
file_format='''||p_file_format||''',
sheet_mnemonic='''||p_sheet_mnemonic||'''';
perform mmt_staging2.fn_jobctrl_block_end(__file_syspk,'FTWET_TRS_Implement_Block');
end
$$ LANGUAGE plpgsql;