From 45a9892ef0ff33afdf541311d348a74e9437ebd4 Mon Sep 17 00:00:00 2001 From: Harish Date: Tue, 22 Mar 2022 10:17:30 +0530 Subject: [PATCH] core_table_population script updated based on observation made during testing, New file for metric calculation added. --- .../script/core_table_population_v3.sql | 651 ++++++++++++++++++ retail_model/script/metric_query.sql | 85 +++ 2 files changed, 736 insertions(+) create mode 100644 retail_model/script/core_table_population_v3.sql create mode 100644 retail_model/script/metric_query.sql diff --git a/retail_model/script/core_table_population_v3.sql b/retail_model/script/core_table_population_v3.sql new file mode 100644 index 0000000..3e37520 --- /dev/null +++ b/retail_model/script/core_table_population_v3.sql @@ -0,0 +1,651 @@ +/*************** tmp_config_new_client ***************************/ + +truncate table fw_core.tmp_config_new_client; + +INSERT INTO fw_core.tmp_config_new_client +(base_client_id, base_function_id, new_client_id, new_function_id, new_created_by, new_updated_by, ods_table_name) +VALUES(200, 1, 500, 1, 'HK', 'HK', 'fw_ods_monthly'); + +/******************* fw_config_table_metadata *************************/ + +INSERT INTO fw_config_table_metadata +(client_id, function_id, table_name, table_type, table_description, created_by, updated_by, create_timestamp, update_timestamp) + +SELECT t.new_client_id, t.new_function_id, table_name, table_type, table_description, +t.new_created_by, t.new_updated_by, current_timestamp , current_timestamp +FROM fw_config_table_metadata a, tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +and a.table_name = t.ods_table_name +and table_name not in (select distinct table_name FROM fw_config_table_metadata a, tmp_config_new_client t ---- to avoid duplicate data insertion +where a.client_id = t.new_client_id and a.function_id = t.new_function_id); + +/* +INSERT INTO fw_core.fw_config_table_metadata +(client_id, function_id, table_name, table_type, table_description, created_by, updated_by, create_timestamp, update_timestamp) +VALUES(500, 1, 'fw_core.fw_datagov_dq_sumary_monthly', 'ods', 'Monthly summary', 'postgres', 'postgres', now(), now()); +*/ + +----------------------------------------------------------------------------------------------------------- +/******************* fw_config_column_metadata *************************/ + +INSERT INTO fw_config_column_metadata +(client_id, function_id, table_name, column_name, data_type, column_sequence_order, column_description, +created_by, updated_by, create_timestamp, update_timestamp, biz_name, field_criticality) + +SELECT t.new_client_id, t.new_function_id, table_name, column_name, data_type, column_sequence_order, column_description, +t.new_created_by, t.new_updated_by, current_timestamp, current_timestamp, biz_name, field_criticality +FROM fw_config_column_metadata a, tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +and a.table_name = t.ods_table_name +and table_name not in (select distinct table_name FROM fw_config_column_metadata a, tmp_config_new_client t ---- to avoid duplicate data insertion +where a.client_id = t.new_client_id and a.function_id = t.new_function_id); + +/* +INSERT INTO fw_core.fw_config_column_metadata +(client_id, function_id, table_name, column_name, data_type, column_sequence_order, column_description, created_by, updated_by, create_timestamp, update_timestamp, biz_name, field_criticality) +VALUES(500, 1, 'fw_core.fw_datagov_dq_sumary_monthly', 'error_type', 'fw_text', 2, 'Error Type', 'postgres', 'postgres', now(), now(), 'Error Type', NULL); +*/ + +/* update the biz_name and column_description if they are different from the what exists */ + +----------------------------------------------------------------------------------------------------------- +******************* fw_config_menu_master *************************/ + +INSERT INTO fw_config_menu_master +(client_id, function_id, menu_id, menu_name, parent_menu_id, menu_level, menu_position, menu_path, menu_icon, +menu_display_order, menu_display_flag, in_prod_flag, created_by, updated_by, create_timestamp, update_timestamp) + +SELECT distinct t.new_client_id, t.new_function_id, menu_id, menu_name, parent_menu_id, menu_level, menu_position, menu_path, menu_icon, +menu_display_order, menu_display_flag, in_prod_flag, t.new_created_by, t.new_updated_by, current_timestamp , current_timestamp +FROM fw_core.fw_config_menu_master a, tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +and case + when (select count(1) from tmp_config_new_client_menu) <> 0 + then a.menu_id in (select distinct menu_id from tmp_config_new_client_menu) + else + true + end +and a.menu_id not in (select distinct menu_id from fw_core.fw_config_menu_master a, tmp_config_new_client t ---- to avoid duplicate data insertion +where a.client_id = t.new_client_id and a.function_id = t.new_function_id); + +----------------------------------------------------------------------------------------------------------- +/******************* fw_config_m_datasql *************************/ + +INSERT INTO fw_config_m_datasql +(client_id, function_id, datasql_id, datasql, sql_desc, created_by, updated_by, create_timestamp, update_timestamp) + +select distinct t.new_client_id, t.new_function_id, +concat(t.new_client_id, t.new_function_id, SUBSTRING (c.datasql_id, position('SQL' in c.datasql_id), length(c.datasql_id))) datasql_id, +datasql, sql_desc, t.new_created_by, t.new_updated_by, current_timestamp , current_timestamp +from fw_config_menu_screen_render a, fw_config_screenlet_instance b, fw_config_m_datasql c, tmp_config_new_client t +where a.client_id = c.client_id and a.function_id = c.function_id +and a.screenlet_instance_id = b.screenlet_instance_id and b.datasql_id = c.datasql_id -- For datasql_id +and a.client_id = t.base_client_id and a.function_id = t.base_function_id +and c.datasql_id is not null and c.datasql is not null and c.datasql <> '' +and case + when (select count(1) from tmp_config_new_client_menu) <> 0 + then a.menu_id in (select distinct menu_id from tmp_config_new_client_menu) + else + true + end +and concat(t.new_client_id, t.new_function_id, SUBSTRING (c.datasql_id, position('SQL' in c.datasql_id), length(c.datasql_id))) not in +(select distinct datasql_id from fw_config_m_datasql a, tmp_config_new_client t ---- to avoid duplicate data insertion +where a.client_id = t.new_client_id and a.function_id = t.new_function_id); + +/* loading data sql related to downloadsql_id */ + + +INSERT INTO fw_config_m_datasql +(client_id, function_id, datasql_id, datasql, sql_desc, created_by, updated_by, create_timestamp, update_timestamp) + +select distinct t.new_client_id, t.new_function_id, +concat(t.new_client_id, t.new_function_id, SUBSTRING (c.datasql_id, position('SQL' in c.datasql_id), length(c.datasql_id))) datasql_id, +datasql, sql_desc, t.new_created_by, t.new_updated_by, current_timestamp , current_timestamp +from fw_config_menu_screen_render a, fw_config_screenlet_instance b, fw_config_m_datasql c, tmp_config_new_client t +where a.client_id = c.client_id and a.function_id = c.function_id +and a.screenlet_instance_id = b.screenlet_instance_id and b.downloadsql_id = c.datasql_id --- for downloadsql_id +and a.client_id = t.base_client_id and a.function_id = t.base_function_id +and c.datasql_id is not null +and c.datasql is not null and c.datasql <> '' +and case + when (select count(1) from tmp_config_new_client_menu) <> 0 + then a.menu_id in (select distinct menu_id from tmp_config_new_client_menu) + else + true + end +and concat(t.new_client_id, t.new_function_id, SUBSTRING (c.datasql_id, position('SQL' in c.datasql_id), length(c.datasql_id))) not in +(select distinct datasql_id from fw_config_m_datasql a, tmp_config_new_client t ---- to avoid duplicate data insertion +where a.client_id = t.new_client_id and a.function_id = t.new_function_id); + + +----------------------------------------------------------------------------------------------------------- + +/******************* fw_config_m_listbox *************************/ + +/* Run the query below for the required base client ID to chcek maximum number of listbox used in a visulization + Based on this number the below query needs to be run that many number of time after making corresponding changes in + "and a.screenlet_listbox_syspk_array[1] = b.syspk" + "and a.screenlet_listbox_syspk_array[1] is not null" + in the query. + For example considering number of listbox is 5 the query given for 5 listbox below + */ +select max(array_length(screenlet_listbox_syspk_array,1)) from fw_core.fw_config_menu_screen_render where client_id =10; + +/* to take care of listbox 1 */ + +INSERT INTO fw_config_m_listbox +(client_id, function_id, listbox_dim_name, listbox_sql_id, created_by, updated_by, create_timestamp, update_timestamp) + +SELECT distinct t.new_client_id, t.new_function_id, b.listbox_dim_name, +case when listbox_sql_id is null then null else +concat(t.new_client_id, t.new_function_id, SUBSTRING (b.listbox_sql_id, position('LSQL' in b.listbox_sql_id), length(b.listbox_sql_id))) end listbox_sql_id, +t.new_created_by, t.new_updated_by, current_timestamp , current_timestamp +from fw_config_menu_screen_render a, fw_config_m_listbox b, tmp_config_new_client t +where a.client_id = b.client_id and a.function_id = b.function_id +and a.screenlet_listbox_syspk_array[1] = b.syspk +and a.screenlet_listbox_syspk_array[1] is not null +and a.client_id = t.base_client_id and a.function_id = t.base_function_id +and case + when (select count(1) from tmp_config_new_client_menu) <> 0 + then a.menu_id in (select distinct menu_id from tmp_config_new_client_menu) + else + true + end +and b.listbox_dim_name not in +(select distinct listbox_dim_name from fw_config_m_listbox a, tmp_config_new_client t ---- to avoid duplicate data insertion +where a.client_id = t.new_client_id and a.function_id = t.new_function_id); + + +/* to take care of listbox 2 */ + +INSERT INTO fw_config_m_listbox +(client_id, function_id, listbox_dim_name, listbox_sql_id, created_by, updated_by, create_timestamp, update_timestamp) + +SELECT distinct t.new_client_id, t.new_function_id, b.listbox_dim_name, +case when listbox_sql_id is null then null else +concat(t.new_client_id, t.new_function_id, SUBSTRING (b.listbox_sql_id, position('LSQL' in b.listbox_sql_id), length(b.listbox_sql_id))) end listbox_sql_id, +t.new_created_by, t.new_updated_by, current_timestamp , current_timestamp +from fw_config_menu_screen_render a, fw_config_m_listbox b, tmp_config_new_client t +where a.client_id = b.client_id and a.function_id = b.function_id +and a.screenlet_listbox_syspk_array[2] = b.syspk +and a.screenlet_listbox_syspk_array[2] is not null +and a.client_id = t.base_client_id and a.function_id = t.base_function_id +and case + when (select count(1) from tmp_config_new_client_menu) <> 0 + then a.menu_id in (select distinct menu_id from tmp_config_new_client_menu) + else + true + end +and b.listbox_dim_name not in +(select distinct listbox_dim_name from fw_config_m_listbox a, tmp_config_new_client t ---- to avoid duplicate data insertion +where a.client_id = t.new_client_id and a.function_id = t.new_function_id); + +/* to take care of listbox 3 */ + +INSERT INTO fw_config_m_listbox +(client_id, function_id, listbox_dim_name, listbox_sql_id, created_by, updated_by, create_timestamp, update_timestamp) + +SELECT distinct t.new_client_id, t.new_function_id, b.listbox_dim_name, +case when listbox_sql_id is null then null else +concat(t.new_client_id, t.new_function_id, SUBSTRING (b.listbox_sql_id, position('LSQL' in b.listbox_sql_id), length(b.listbox_sql_id))) end listbox_sql_id, +t.new_created_by, t.new_updated_by, current_timestamp , current_timestamp +from fw_config_menu_screen_render a, fw_config_m_listbox b, tmp_config_new_client t +where a.client_id = b.client_id and a.function_id = b.function_id +and a.screenlet_listbox_syspk_array[3] = b.syspk +and a.screenlet_listbox_syspk_array[3] is not null +and a.client_id = t.base_client_id and a.function_id = t.base_function_id +and case + when (select count(1) from tmp_config_new_client_menu) <> 0 + then a.menu_id in (select distinct menu_id from tmp_config_new_client_menu) + else + true + end +and b.listbox_dim_name not in +(select distinct listbox_dim_name from fw_config_m_listbox a, tmp_config_new_client t ---- to avoid duplicate data insertion +where a.client_id = t.new_client_id and a.function_id = t.new_function_id); + +/* to take care of listbox 4 */ + +INSERT INTO fw_config_m_listbox +(client_id, function_id, listbox_dim_name, listbox_sql_id, created_by, updated_by, create_timestamp, update_timestamp) + +SELECT distinct t.new_client_id, t.new_function_id, b.listbox_dim_name, +case when listbox_sql_id is null then null else +concat(t.new_client_id, t.new_function_id, SUBSTRING (b.listbox_sql_id, position('LSQL' in b.listbox_sql_id), length(b.listbox_sql_id))) end listbox_sql_id, +t.new_created_by, t.new_updated_by, current_timestamp , current_timestamp +from fw_config_menu_screen_render a, fw_config_m_listbox b, tmp_config_new_client t +where a.client_id = b.client_id and a.function_id = b.function_id +and a.screenlet_listbox_syspk_array[4] = b.syspk +and a.screenlet_listbox_syspk_array[4] is not null +and a.client_id = t.base_client_id and a.function_id = t.base_function_id +and case + when (select count(1) from tmp_config_new_client_menu) <> 0 + then a.menu_id in (select distinct menu_id from tmp_config_new_client_menu) + else + true + end +and b.listbox_dim_name not in +(select distinct listbox_dim_name from fw_config_m_listbox a, tmp_config_new_client t ---- to avoid duplicate data insertion +where a.client_id = t.new_client_id and a.function_id = t.new_function_id); + +/* to take care of listbox 5 */ + +INSERT INTO fw_config_m_listbox +(client_id, function_id, listbox_dim_name, listbox_sql_id, created_by, updated_by, create_timestamp, update_timestamp) + +SELECT distinct t.new_client_id, t.new_function_id, b.listbox_dim_name, +case when listbox_sql_id is null then null else +concat(t.new_client_id, t.new_function_id, SUBSTRING (b.listbox_sql_id, position('LSQL' in b.listbox_sql_id), length(b.listbox_sql_id))) end listbox_sql_id, +t.new_created_by, t.new_updated_by, current_timestamp , current_timestamp +from fw_config_menu_screen_render a, fw_config_m_listbox b, tmp_config_new_client t +where a.client_id = b.client_id and a.function_id = b.function_id +and a.screenlet_listbox_syspk_array[5] = b.syspk +and a.screenlet_listbox_syspk_array[5] is not null +and a.client_id = t.base_client_id and a.function_id = t.base_function_id +and case + when (select count(1) from tmp_config_new_client_menu) <> 0 + then a.menu_id in (select distinct menu_id from tmp_config_new_client_menu) + else + true + end +and b.listbox_dim_name not in +(select distinct listbox_dim_name from fw_config_m_listbox a, tmp_config_new_client t ---- to avoid duplicate data insertion +where a.client_id = t.new_client_id and a.function_id = t.new_function_id); + + +/* Note: screen_listbox1_sql_id and screen_listbox2_sql_id is not considered as they no longer needed */ + +----------------------------------------------------------------------------------------------------------- +/******************* fw_config_m_listbox_sql *************************/ + +/* to take care of screenlet_listbox1_sql_id need to execute this query first then the below query */ +INSERT INTO fw_config_m_listbox_sql +(client_id, function_id, listbox_sql_id, listbox_sql, listbox_sql_desc, created_by, updated_by, create_timestamp, update_timestamp) + +select distinct t.new_client_id, t.new_function_id, +case when listbox_sql_id is null then null else +concat(t.new_client_id, t.new_function_id, SUBSTRING (b.listbox_sql_id, position('LSQL' in b.listbox_sql_id), length(b.listbox_sql_id))) end listbox_sql_id, +listbox_sql, listbox_sql_desc, t.new_created_by, t.new_updated_by, current_timestamp, current_timestamp +FROM fw_config_menu_screen_render a, fw_config_m_listbox_sql b, tmp_config_new_client t +where a.client_id = b.client_id and a.function_id = b.function_id +and a.screenlet_listbox1_sql_id = b.listbox_sql_id +and a.client_id = t.base_client_id and a.function_id = t.base_function_id +and case + when (select count(1) from tmp_config_new_client_menu) <> 0 + then a.menu_id in (select distinct menu_id from tmp_config_new_client_menu) + else + true + end +and concat(t.new_client_id, t.new_function_id, SUBSTRING (b.listbox_sql_id, position('LSQL' in b.listbox_sql_id), length(b.listbox_sql_id))) +not in +(select distinct listbox_sql_id from fw_config_m_listbox_sql a, tmp_config_new_client t ---- to avoid duplicate data insertion +where a.client_id = t.new_client_id and a.function_id = t.new_function_id); + +/************ No more required +----------to take care of screenlet_listbox2_sql_id --------- + +INSERT INTO fw_config_m_listbox_sql +(client_id, function_id, listbox_sql_id, listbox_sql, listbox_sql_desc, created_by, updated_by, create_timestamp, update_timestamp) + +select distinct t.new_client_id, t.new_function_id, +case when listbox_sql_id is null then null else +concat(t.new_client_id, t.new_function_id, SUBSTRING (b.listbox_sql_id, position('LSQL' in b.listbox_sql_id), length(b.listbox_sql_id))) end listbox_sql_id, +listbox_sql, listbox_sql_desc, t.new_created_by, t.new_updated_by, current_timestamp, current_timestamp +FROM fw_config_menu_screen_render a, fw_config_m_listbox_sql b, tmp_config_new_client t +where a.client_id = b.client_id and a.function_id = b.function_id +and a.screenlet_listbox2_sql_id = b.listbox_sql_id +and a.client_id = t.base_client_id and a.function_id = t.base_function_id +and case + when (select count(1) from tmp_config_new_client_menu) <> 0 + then a.menu_id in (select distinct menu_id from tmp_config_new_client_menu) + else + true + end +and concat(t.new_client_id, t.new_function_id, SUBSTRING (b.listbox_sql_id, position('LSQL' in b.listbox_sql_id), length(b.listbox_sql_id))) +not in +(select distinct listbox_sql_id from fw_config_m_listbox_sql a, tmp_config_new_client t ---- to avoid duplicate data insertion +where a.client_id = t.new_client_id and a.function_id = t.new_function_id); +************/ +----------------------------------------------------------------------------------------------------------- + +/******************* fw_config_screenlet_instance *************************/ + +INSERT INTO fw_config_screenlet_instance +(screenlet_instance_id, screen_type_id, screenlet_id, screenlet_sequence, fw_appconfig_m_screenlet_vizlet_syspk, +datasql_id, vizlet_size_id, visible_flag, created_by, updated_by, create_timestamp, update_timestamp, downloadsql_id, +vizlet_card_disable_flag, vizlet_card_style, vizlet_action_icons_syspk_array) + +SELECT distinct +concat(t.new_client_id, t.new_function_id, SUBSTRING (b.screenlet_instance_id, position('SLI' in b.screenlet_instance_id), length(b.screenlet_instance_id))) screenlet_instance_id, +b.screen_type_id, b.screenlet_id, screenlet_sequence, fw_appconfig_m_screenlet_vizlet_syspk, +case when b.datasql_id is null then null else +concat(t.new_client_id, t.new_function_id, SUBSTRING (b.datasql_id, position('SQL' in b.datasql_id), length(b.datasql_id))) end datasql_id, +vizlet_size_id, visible_flag, +t.new_created_by, t.new_updated_by, current_timestamp, current_timestamp, +case when b.downloadsql_id is null then null else +concat(t.new_client_id, t.new_function_id, SUBSTRING (b.downloadsql_id, position('SQL' in b.downloadsql_id), length(b.downloadsql_id))) end downloadsql_id, +vizlet_card_disable_flag, b.vizlet_card_style, b.vizlet_action_icons_syspk_array +FROM fw_core.fw_config_menu_screen_render a, fw_core.fw_config_screenlet_instance b, tmp_config_new_client t +where a.screenlet_instance_id = b.screenlet_instance_id +and a.client_id = t.base_client_id and a.function_id = t.base_function_id +and b.screenlet_instance_id is not null +and case + when (select count(1) from tmp_config_new_client_menu) <> 0 + then a.menu_id in (select distinct menu_id from tmp_config_new_client_menu) + else + true + end +and +concat(concat(t.new_client_id, t.new_function_id, SUBSTRING (b.screenlet_instance_id, position('SLI' in b.screenlet_instance_id), length(b.screenlet_instance_id))), +concat(t.new_client_id, t.new_function_id, SUBSTRING (b.datasql_id, position('SQL' in b.datasql_id), length(b.datasql_id))), +fw_appconfig_m_screenlet_vizlet_syspk) +not in +(select distinct +concat(b.screenlet_instance_id, datasql_id, fw_appconfig_m_screenlet_vizlet_syspk) +from fw_config_menu_screen_render a, fw_core.fw_config_screenlet_instance b, tmp_config_new_client t ---- to avoid duplicate data insertion +where a.screenlet_instance_id = b.screenlet_instance_id +and a.client_id = t.new_client_id and a.function_id = t.new_function_id); + +--Note ---- Considered combination of b.screenlet_instance_id, datasql_id, fw_appconfig_m_screenlet_vizlet_syspk as unique in fw_config_screenlet_instance + +----------------------------------------------------------------------------------------------------------- + +/******************* fw_config_menu_screen_render *************************/ + +INSERT INTO fw_config_menu_screen_render +(client_id, function_id, menu_id, screen_type_id, screenlet_id, screenlet_instance_id, screen_title_dp_name, +screenlet_title_dp_name, screenlet_default_count, screenlet_max_count, screenlet_addition_flag, screen_listbox1_dim, screen_listbox2_dim, +screenlet_listbox1_dim, screenlet_listbox2_dim, created_by, updated_by, create_timestamp, update_timestamp, +screen_listbox1_sql_id, screen_listbox2_sql_id, screenlet_listbox1_sql_id, screenlet_listbox2_sql_id, screen_listbox_syspk_array, +screenlet_listbox_syspk_array, screen_action_icons_syspk_array, screenlet_action_icons_syspk_array, date_range_filter_display_flag, +vizlet_action_icons_syspk_array, vizlet_card_style, orderby_text_json, date_range_filter_shortcuts, +screenlet_listbox_type, screen_listbox_type) + +SELECT distinct t.new_client_id, t.new_function_id, menu_id, screen_type_id, screenlet_id, +case when screenlet_instance_id is null then null else +concat(t.new_client_id, t.new_function_id, SUBSTRING (a.screenlet_instance_id, position('SLI' in a.screenlet_instance_id), length(a.screenlet_instance_id))) end screenlet_instance_id, +screen_title_dp_name, screenlet_title_dp_name, screenlet_default_count, screenlet_max_count, screenlet_addition_flag, screen_listbox1_dim, +screen_listbox2_dim, screenlet_listbox1_dim, screenlet_listbox2_dim, t.new_created_by, t.new_updated_by, current_timestamp, current_timestamp, +null screen_listbox1_sql_id, null screen_listbox2_sql_id, +case when screenlet_listbox1_sql_id is null then null else +concat(t.new_client_id, t.new_function_id, SUBSTRING (screenlet_listbox1_sql_id, position('LSQL' in screenlet_listbox1_sql_id), length(screenlet_listbox1_sql_id))) end screenlet_listbox1_sql_id, +case when screenlet_listbox2_sql_id is null then null else +concat(t.new_client_id, t.new_function_id, SUBSTRING (a.screenlet_listbox2_sql_id, position('LSQL' in a.screenlet_listbox2_sql_id), length(a.screenlet_listbox2_sql_id))) end screenlet_listbox2_sql_id, +screen_listbox_syspk_array, screenlet_listbox_syspk_array, screen_action_icons_syspk_array, screenlet_action_icons_syspk_array, +date_range_filter_display_flag, vizlet_action_icons_syspk_array, vizlet_card_style, orderby_text_json::jsonb, +date_range_filter_shortcuts::jsonb, screenlet_listbox_type, screen_listbox_type +FROM fw_config_menu_screen_render a, tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +and case + when (select count(1) from tmp_config_new_client_menu) <> 0 + then a.menu_id in (select distinct menu_id from tmp_config_new_client_menu) + else + true + end +and menu_id not in (select distinct menu_id +from fw_config_menu_screen_render a, tmp_config_new_client t ---- to avoid duplicate data insertion +where a.client_id = t.new_client_id and a.function_id = t.new_function_id); + + +-- menu_syspk is not considered in insertion if needed it hast be updated. + +----------------------------------------------------------------------------------------------------------- + +/******************* fw_config_screenlet_vizlet_datasql_axis_tooltips *************************/ + +INSERT INTO fw_config_screenlet_vizlet_datasql_axis_tooltips +(client_id, function_id, vizlet_id, datasql_id, x1_axis_display_name, x2_axis_display_name, y1_axis_display_name, +y2_axis_display_name, vizlet_title_dp_name, title_tooltip, x1_metric_tooltip, x2_metric_tooltip, y1_metric_tooltip, y2_metric_tooltip, +x1_metric_unit, x2_metric_unit, y1_metric_unit, y2_metric_unit, +created_by, updated_by, create_timestamp, update_timestamp, +viz_specific1, viz_specific2, viz_specific3, viz_specific4, viz_specific5, x1_data_field_name, x2_data_field_name, +y1_data_field_name, y2_data_field_name, y1_metric_divisor, y2_metric_divisor, report_header_column_dp, high_low_better, +axis_label_distance, json_file, top_label_length, bottom_label_length, left_label_length, right_label_length, +x_axistitle_position, y_axistitle_position) + +SELECT distinct t.new_client_id, t.new_function_id, f.vizlet_id, +concat(t.new_client_id, t.new_function_id, SUBSTRING (f.datasql_id, position('SQL' in f.datasql_id), length(f.datasql_id))) datasql_id, +x1_axis_display_name, x2_axis_display_name, y1_axis_display_name, +y2_axis_display_name, vizlet_title_dp_name, title_tooltip, x1_metric_tooltip, x2_metric_tooltip, y1_metric_tooltip, y2_metric_tooltip, +x1_metric_unit, x2_metric_unit, y1_metric_unit, y2_metric_unit, +t.new_created_by, t.new_updated_by, current_timestamp, current_timestamp, +viz_specific1, viz_specific2, viz_specific3, viz_specific4, viz_specific5, x1_data_field_name, x2_data_field_name, +y1_data_field_name, y2_data_field_name, y1_metric_divisor, y2_metric_divisor, report_header_column_dp::jsonb, high_low_better, +axis_label_distance, json_file, top_label_length, bottom_label_length, left_label_length, right_label_length, +x_axistitle_position::jsonb, y_axistitle_position::jsonb +FROM fw_core.fw_config_menu_screen_render a, fw_core.fw_config_screenlet_instance b, +fw_core.fw_appconfig_m_screenlet_vizlet c, fw_core.fw_config_screenlet_vizlet_datasql_axis_tooltips f, tmp_config_new_client t +where a.screenlet_instance_id = b.screenlet_instance_id +and b.fw_appconfig_m_screenlet_vizlet_syspk = c.syspk +and c.vizlet_id = f.vizlet_id +and b.datasql_id = f.datasql_id and a.client_id = f.client_id and a.function_id = f.function_id +and a.client_id = t.base_client_id and a.function_id = t.base_function_id +and c.vizlet_id is not null and b.datasql_id is not null +and case + when (select count(1) from tmp_config_new_client_menu) <> 0 + then a.menu_id in (select distinct menu_id from tmp_config_new_client_menu) + else + true + end +and concat(c.vizlet_id,concat(t.new_client_id, t.new_function_id, SUBSTRING (f.datasql_id, position('SQL' in f.datasql_id), length(f.datasql_id)))) +not in +(select distinct concat(vizlet_id,datasql_id) +from fw_config_screenlet_vizlet_datasql_axis_tooltips a, tmp_config_new_client t ---- to avoid duplicate data insertion +where a.client_id = t.new_client_id and a.function_id = t.new_function_id); + + +----------------------------------------------------------------------------------------------------------- + +/******************* fw_config_report_column_master *************************/ + +INSERT INTO fw_config_report_column_master +(client_id, function_id, menu_id, report_id, menu_name, report_name, report_title_display, drilldown_level, +header_column_display, header_tootip, header_column_display_order, datasql_query, report_metadata_row, visible_flag, +created_by, updated_by, create_timestamp, update_timestamp, action_icons_syspk_array) + +SELECT distinct t.new_client_id, t.new_function_id, menu_id, report_id, menu_name, report_name, report_title_display, drilldown_level, +header_column_display, header_tootip, header_column_display_order, datasql_query, report_metadata_row, visible_flag, +t.new_created_by, t.new_updated_by, current_timestamp, current_timestamp, action_icons_syspk_array +FROM fw_config_report_column_master a, tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +and case + when (select count(1) from tmp_config_new_client_menu) <> 0 + then a.menu_id in (select distinct menu_id from tmp_config_new_client_menu) + else + true + end +and a.menu_id not in +(select distinct menu_id from fw_core.fw_config_report_column_master a, tmp_config_new_client t ---- to avoid duplicate data insertion +where a.client_id = t.new_client_id and a.function_id = t.new_function_id); + +----------------------------------------------------------------------------------------------------------- +/******************* Update of screenlet_listbox_syspk_array in fw_config_menu_screen_render *************************/ +/* Run the query below for the required base client ID to chcek maximum number of listbox used in a visulization + Based on this number the below query needs to be run that many number of time after making corresponding changes in + "set screenlet_listbox_syspk_array[1] = tbl.new_syspk" + "and ren.screenlet_listbox_syspk_array[1] = tbl.base_syspk;" + in the query. + For example considering number of listbox is 5 the query given for 5 listbox update below + */ +select max(array_length(screenlet_listbox_syspk_array,1)) from fw_core.fw_config_menu_screen_render where client_id =10; + + +update fw_core.fw_config_menu_screen_render ren +set screenlet_listbox_syspk_array[1] = tbl.new_syspk +from ( +with syspk_tbl as ( +select distinct t.base_client_id, t.new_client_id, t.base_function_id, t.new_function_id, screenlet_listbox_syspk_array[1] base_syspk +from fw_core.fw_config_menu_screen_render a, fw_core.tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +union +select distinct t.base_client_id, t.new_client_id, t.base_function_id, t.new_function_id, screenlet_listbox_syspk_array[2] base_syspk +from fw_core.fw_config_menu_screen_render a, fw_core.tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +union +select distinct t.base_client_id, t.new_client_id, t.base_function_id, t.new_function_id, screenlet_listbox_syspk_array[3] base_syspk +from fw_core.fw_config_menu_screen_render a, fw_core.tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +union +select distinct t.base_client_id, t.new_client_id, t.base_function_id, t.new_function_id, screenlet_listbox_syspk_array[4] base_syspk +from fw_core.fw_config_menu_screen_render a, fw_core.tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +union +select distinct t.base_client_id, t.new_client_id, t.base_function_id, t.new_function_id, screenlet_listbox_syspk_array[5] base_syspk +from fw_core.fw_config_menu_screen_render a, fw_core.tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +) +select new_client_id, new_function_id, base_syspk, b.syspk new_syspk +from fw_core.fw_config_m_listbox a, fw_core.fw_config_m_listbox b, syspk_tbl +where a.listbox_dim_name = b.listbox_dim_name +and a.client_id = base_client_id and a.function_id = base_function_id +and b.client_id = new_client_id and b.function_id = new_function_id +and a.syspk = base_syspk and base_syspk is not null +) tbl +where ren.client_id = tbl.new_client_id and ren.function_id = tbl.new_function_id +and ren.screenlet_listbox_syspk_array[1] = tbl.base_syspk; + +--------------- + +update fw_core.fw_config_menu_screen_render ren +set screenlet_listbox_syspk_array[2] = tbl.new_syspk +from ( +with syspk_tbl as ( +select distinct t.base_client_id, t.new_client_id, t.base_function_id, t.new_function_id, screenlet_listbox_syspk_array[1] base_syspk +from fw_core.fw_config_menu_screen_render a, fw_core.tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +union +select distinct t.base_client_id, t.new_client_id, t.base_function_id, t.new_function_id, screenlet_listbox_syspk_array[2] base_syspk +from fw_core.fw_config_menu_screen_render a, fw_core.tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +union +select distinct t.base_client_id, t.new_client_id, t.base_function_id, t.new_function_id, screenlet_listbox_syspk_array[3] base_syspk +from fw_core.fw_config_menu_screen_render a, fw_core.tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +union +select distinct t.base_client_id, t.new_client_id, t.base_function_id, t.new_function_id, screenlet_listbox_syspk_array[4] base_syspk +from fw_core.fw_config_menu_screen_render a, fw_core.tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +union +select distinct t.base_client_id, t.new_client_id, t.base_function_id, t.new_function_id, screenlet_listbox_syspk_array[5] base_syspk +from fw_core.fw_config_menu_screen_render a, fw_core.tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +) +select new_client_id, new_function_id, base_syspk, b.syspk new_syspk +from fw_core.fw_config_m_listbox a, fw_core.fw_config_m_listbox b, syspk_tbl +where a.listbox_dim_name = b.listbox_dim_name +and a.client_id = base_client_id and a.function_id = base_function_id +and b.client_id = new_client_id and b.function_id = new_function_id +and a.syspk = base_syspk and base_syspk is not null +) tbl +where ren.client_id = tbl.new_client_id and ren.function_id = tbl.new_function_id +and ren.screenlet_listbox_syspk_array[2] = tbl.base_syspk; + +--------------- + +update fw_core.fw_config_menu_screen_render ren +set screenlet_listbox_syspk_array[3] = tbl.new_syspk +from ( +with syspk_tbl as ( +select distinct t.base_client_id, t.new_client_id, t.base_function_id, t.new_function_id, screenlet_listbox_syspk_array[1] base_syspk +from fw_core.fw_config_menu_screen_render a, fw_core.tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +union +select distinct t.base_client_id, t.new_client_id, t.base_function_id, t.new_function_id, screenlet_listbox_syspk_array[2] base_syspk +from fw_core.fw_config_menu_screen_render a, fw_core.tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +union +select distinct t.base_client_id, t.new_client_id, t.base_function_id, t.new_function_id, screenlet_listbox_syspk_array[3] base_syspk +from fw_core.fw_config_menu_screen_render a, fw_core.tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +union +select distinct t.base_client_id, t.new_client_id, t.base_function_id, t.new_function_id, screenlet_listbox_syspk_array[4] base_syspk +from fw_core.fw_config_menu_screen_render a, fw_core.tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +union +select distinct t.base_client_id, t.new_client_id, t.base_function_id, t.new_function_id, screenlet_listbox_syspk_array[5] base_syspk +from fw_core.fw_config_menu_screen_render a, fw_core.tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +) +select new_client_id, new_function_id, base_syspk, b.syspk new_syspk +from fw_core.fw_config_m_listbox a, fw_core.fw_config_m_listbox b, syspk_tbl +where a.listbox_dim_name = b.listbox_dim_name +and a.client_id = base_client_id and a.function_id = base_function_id +and b.client_id = new_client_id and b.function_id = new_function_id +and a.syspk = base_syspk and base_syspk is not null +) tbl +where ren.client_id = tbl.new_client_id and ren.function_id = tbl.new_function_id +and ren.screenlet_listbox_syspk_array[3] = tbl.base_syspk; + +---------------------- + +update fw_core.fw_config_menu_screen_render ren +set screenlet_listbox_syspk_array[4] = tbl.new_syspk +from ( +with syspk_tbl as ( +select distinct t.base_client_id, t.new_client_id, t.base_function_id, t.new_function_id, screenlet_listbox_syspk_array[1] base_syspk +from fw_core.fw_config_menu_screen_render a, fw_core.tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +union +select distinct t.base_client_id, t.new_client_id, t.base_function_id, t.new_function_id, screenlet_listbox_syspk_array[2] base_syspk +from fw_core.fw_config_menu_screen_render a, fw_core.tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +union +select distinct t.base_client_id, t.new_client_id, t.base_function_id, t.new_function_id, screenlet_listbox_syspk_array[3] base_syspk +from fw_core.fw_config_menu_screen_render a, fw_core.tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +union +select distinct t.base_client_id, t.new_client_id, t.base_function_id, t.new_function_id, screenlet_listbox_syspk_array[4] base_syspk +from fw_core.fw_config_menu_screen_render a, fw_core.tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +union +select distinct t.base_client_id, t.new_client_id, t.base_function_id, t.new_function_id, screenlet_listbox_syspk_array[5] base_syspk +from fw_core.fw_config_menu_screen_render a, fw_core.tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +) +select new_client_id, new_function_id, base_syspk, b.syspk new_syspk +from fw_core.fw_config_m_listbox a, fw_core.fw_config_m_listbox b, syspk_tbl +where a.listbox_dim_name = b.listbox_dim_name +and a.client_id = base_client_id and a.function_id = base_function_id +and b.client_id = new_client_id and b.function_id = new_function_id +and a.syspk = base_syspk and base_syspk is not null +) tbl +where ren.client_id = tbl.new_client_id and ren.function_id = tbl.new_function_id +and ren.screenlet_listbox_syspk_array[4] = tbl.base_syspk; + +---------------------- + +update fw_core.fw_config_menu_screen_render ren +set screenlet_listbox_syspk_array[5] = tbl.new_syspk +from ( +with syspk_tbl as ( +select distinct t.base_client_id, t.new_client_id, t.base_function_id, t.new_function_id, screenlet_listbox_syspk_array[1] base_syspk +from fw_core.fw_config_menu_screen_render a, fw_core.tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +union +select distinct t.base_client_id, t.new_client_id, t.base_function_id, t.new_function_id, screenlet_listbox_syspk_array[2] base_syspk +from fw_core.fw_config_menu_screen_render a, fw_core.tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +union +select distinct t.base_client_id, t.new_client_id, t.base_function_id, t.new_function_id, screenlet_listbox_syspk_array[3] base_syspk +from fw_core.fw_config_menu_screen_render a, fw_core.tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +union +select distinct t.base_client_id, t.new_client_id, t.base_function_id, t.new_function_id, screenlet_listbox_syspk_array[4] base_syspk +from fw_core.fw_config_menu_screen_render a, fw_core.tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +union +select distinct t.base_client_id, t.new_client_id, t.base_function_id, t.new_function_id, screenlet_listbox_syspk_array[5] base_syspk +from fw_core.fw_config_menu_screen_render a, fw_core.tmp_config_new_client t +where a.client_id = t.base_client_id and a.function_id = t.base_function_id +) +select new_client_id, new_function_id, base_syspk, b.syspk new_syspk +from fw_core.fw_config_m_listbox a, fw_core.fw_config_m_listbox b, syspk_tbl +where a.listbox_dim_name = b.listbox_dim_name +and a.client_id = base_client_id and a.function_id = base_function_id +and b.client_id = new_client_id and b.function_id = new_function_id +and a.syspk = base_syspk and base_syspk is not null +) tbl +where ren.client_id = tbl.new_client_id and ren.function_id = tbl.new_function_id +and ren.screenlet_listbox_syspk_array[5] = tbl.base_syspk; + + diff --git a/retail_model/script/metric_query.sql b/retail_model/script/metric_query.sql new file mode 100644 index 0000000..6a2077b --- /dev/null +++ b/retail_model/script/metric_query.sql @@ -0,0 +1,85 @@ +------------------------------ CYCM_MTD----------------------------------------- + +select client_id, function_id, 'CYCM_MTD' metric_type, sum(m1208) total_sale, sum(m1209) total_cost, sum(m1203) total_quantity, d1l01_name +from retail_saas.fw_ods_daily +where client_id = 200 and function_id = 1 +and date_yyyy = date_part('year', '2019-12-31'::date) +and date_mm = date_part('month', '2019-12-31'::date) +and date_dd <= date_part('day', '2019-12-31'::date) +group by client_id, function_id, d1l01_name; + +------------------------------ CYPM_MTD----------------------------------------- + +select client_id, function_id, 'CYPM_MTD' metric_type, sum(m1208) total_sale, sum(m1209) total_cost, sum(m1203) total_quantity, d1l01_name +from retail_saas.fw_ods_daily +where client_id = 200 and function_id = 1 +and date_yyyy = date_part('year', '2019-11-30'::date) +and date_mm = date_part('month', '2019-11-30'::date) +and date_dd <= date_part('day', '2019-11-30'::date) +group by client_id, function_id, d1l01_name; + +-------------------- PYCM_MTD--------------------------------------------------- + +select client_id, function_id, 'PYCM_MTD' metric_type, sum(m1208) total_sale, sum(m1209) total_cost, sum(m1203) total_quantity, d1l01_name +from retail_saas.fw_ods_daily +where client_id = 200 and function_id = 1 +and date_yyyy = date_part('year', '2018-12-31'::date) +and date_mm = date_part('month', '2018-12-31'::date) +and date_dd <= date_part('day', '2018-12-31'::date) +group by client_id, function_id, d1l01_name; + +-------------------- PYPM_MTD--------------------------------------------------- + +select client_id, function_id, 'PYPM_MTD' metric_type, sum(m1208) total_sale, sum(m1209) total_cost, sum(m1203) total_quantity, d1l01_name +from retail_saas.fw_ods_daily +where client_id = 200 and function_id = 1 +and date_yyyy = date_part('year', '2018-11-30'::date) +and date_mm = date_part('month', '2018-11-30'::date) +and date_dd <= date_part('day', '2018-11-30'::date) +group by client_id, function_id, d1l01_name; + +-------------------- CY_YTD--------------------------------------------------- + +select client_id, function_id, 'CY_YTD' metric_type, sum(m1208) total_sale, sum(m1209) total_cost, sum(m1203) total_quantity, d1l01_name +from retail_saas.fw_ods_daily +where client_id = 200 and function_id = 1 +and date_yyyy = date_part('year', '2019-12-31'::date) +and date_field <= '2019-12-31' +group by client_id, function_id, d1l01_name; + +-------------------- PY_YTD--------------------------------------------------- +select client_id, function_id, 'PY_YTD' metric_type, sum(m1208) total_sale, sum(m1209) total_cost, sum(m1203) total_quantity, d1l01_name +from retail_saas.fw_ods_daily +where client_id = 200 and function_id = 1 +and date_yyyy = date_part('year', '2018-12-31'::date) +and date_field <= '2018-12-31' +group by client_id, function_id, d1l01_name; + +-------------------- CFY_YTD--------------------------------------------------- + +select client_id, function_id, 'CFY_YTD' metric_type, sum(m1208) total_sale, sum(m1209) total_cost, sum(m1203) total_quantity, d1l01_name +from retail_saas.fw_ods_daily +where client_id = 200 and function_id = 1 +and date_fy_yyyy = date_part('year', '2019-12-31'::date) +and date_field <= '2019-12-31' +group by client_id, function_id, d1l01_name; + +-------------------- PFY_YTD--------------------------------------------------- + +select client_id, function_id, 'PFY_YTD' metric_type, sum(m1208) total_sale, sum(m1209) total_cost, sum(m1203) total_quantity, d1l01_name +from retail_saas.fw_ods_daily +where client_id = 200 and function_id = 1 +and date_fy_yyyy = date_part('year', '2018-12-31'::date) +and date_field <= '2018-12-31' +group by client_id, function_id, d1l01_name; + +-------------------- YOY --------------------------------------------------- +/** excluded previous year current date **/ +/** included current year current date **/ + +select client_id, function_id, 'CFY_YTD' metric_type, sum(m1208) total_sale, sum(m1209) total_cost, sum(m1203) total_quantity, d1l01_name +from retail_saas.fw_ods_daily +where client_id = 200 and function_id = 1 +and date_field > '2018-12-31' +and date_field <= '2019-12-31' +group by client_id, function_id, d1l01_name; \ No newline at end of file