ervu-dashboard-etl/mappings/region/total_registered.child_minor(reg).hpl

1017 lines
32 KiB
Text
Raw Normal View History

2024-10-16 10:38:29 +03:00
<pipeline>
<info>
<name>total_registered.child_minor(reg)</name>
<name_sync_with_filename>Y</name_sync_with_filename>
<description/>
<extended_description/>
<pipeline_version/>
<pipeline_type>Normal</pipeline_type>
<pipeline_status>0</pipeline_status>
<directory>/</directory>
<parameters>
</parameters>
<capture_transform_performance>N</capture_transform_performance>
<transform_performance_capturing_delay>1000</transform_performance_capturing_delay>
<transform_performance_capturing_size_limit>100</transform_performance_capturing_size_limit>
<created_user>-</created_user>
<created_date>2024/08/02 11:56:22.507</created_date>
<modified_user>-</modified_user>
<modified_date>2024/08/02 11:56:22.507</modified_date>
<key_for_session_key>H4sIAAAAAAAAAAMAAAAAAAAAAAA=</key_for_session_key>
<is_key_private>N</is_key_private>
</info>
<notepads>
</notepads>
<order>
<hop>
<from>Get variables 4 2</from>
<to>Select values 4 2</to>
<enabled>Y</enabled>
</hop>
<hop>
<from>Table input (person_registry)регион/все</from>
<to>Get variables 4 2</to>
<enabled>Y</enabled>
</hop>
<hop>
<from>Select values 4 2</from>
<to>Insert / update (total_registered.child_minor)</to>
<enabled>Y</enabled>
</hop>
<hop>
<from>Get variables 4 2 2</from>
<to>Select values 4 2 2</to>
<enabled>Y</enabled>
</hop>
<hop>
<from>Select values 4 2 2</from>
<to>Insert / update (total_registered.child_minor) 2</to>
<enabled>Y</enabled>
</hop>
<hop>
<from>Get variables 4 2 2 2</from>
<to>Select values 4 2 2 2</to>
<enabled>Y</enabled>
</hop>
<hop>
<from>Select values 4 2 2 2</from>
<to>Insert / update (total_registered.child_minor) 2 2</to>
<enabled>Y</enabled>
</hop>
<hop>
<from>Table input (person_registry)РФ/мужчины</from>
<to>Get variables 4 2 2</to>
<enabled>Y</enabled>
</hop>
<hop>
<from>Table input (person_registry)РФ/женщины</from>
<to>Get variables 4 2 2 2</to>
<enabled>Y</enabled>
</hop>
</order>
<transform>
<name>Get variables 4 2</name>
<type>GetVariable</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<fields>
<field>
<name>VK_ARRAY</name>
<variable/>
<type>String</type>
<format/>
<currency/>
<decimal/>
<group/>
<length>-1</length>
<precision>-1</precision>
<trim_type>none</trim_type>
</field>
<field>
<name>REG_ID</name>
<variable/>
<type>String</type>
<format/>
<currency/>
<decimal/>
<group/>
<length>-1</length>
<precision>-1</precision>
<trim_type>none</trim_type>
</field>
</fields>
<attributes/>
<cluster_schema/>
<GUI>
<xloc>592</xloc>
<yloc>288</yloc>
<draw>Y</draw>
</GUI>
</transform>
<transform>
<name>Get variables 4 2 2</name>
<type>GetVariable</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<fields>
<field>
<name>VK_ARRAY</name>
<variable/>
<type>String</type>
<format/>
<currency/>
<decimal/>
<group/>
<length>-1</length>
<precision>-1</precision>
<trim_type>none</trim_type>
</field>
<field>
<name>REG_ID</name>
<variable/>
<type>String</type>
<format/>
<currency/>
<decimal/>
<group/>
<length>-1</length>
<precision>-1</precision>
<trim_type>none</trim_type>
</field>
</fields>
<attributes/>
<cluster_schema/>
<GUI>
<xloc>592</xloc>
<yloc>384</yloc>
<draw>Y</draw>
</GUI>
</transform>
<transform>
<name>Get variables 4 2 2 2</name>
<type>GetVariable</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<fields>
<field>
<name>VK_ARRAY</name>
<variable/>
<type>String</type>
<format/>
<currency/>
<decimal/>
<group/>
<length>-1</length>
<precision>-1</precision>
<trim_type>none</trim_type>
</field>
<field>
<name>REG_ID</name>
<variable/>
<type>String</type>
<format/>
<currency/>
<decimal/>
<group/>
<length>-1</length>
<precision>-1</precision>
<trim_type>none</trim_type>
</field>
</fields>
<attributes/>
<cluster_schema/>
<GUI>
<xloc>592</xloc>
<yloc>480</yloc>
<draw>Y</draw>
</GUI>
</transform>
<transform>
<name>Insert / update (total_registered.child_minor)</name>
<type>InsertUpdate</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<connection>ervu-dashboard</connection>
<commit>100</commit>
<update_bypassed>N</update_bypassed>
<lookup>
<schema>total_registered</schema>
<table>child_minor</table>
<key>
<name>REG_ID</name>
<field>recruitment_id</field>
<condition>=</condition>
<name2/>
</key>
<value>
<name>no_child</name>
<rename>no_children</rename>
<update>Y</update>
</value>
<value>
<name>"1_child"</name>
<rename>one_child</rename>
<update>Y</update>
</value>
<value>
<name>"2_child"</name>
<rename>two_children</rename>
<update>Y</update>
</value>
<value>
<name>"3_child"</name>
<rename>three_children</rename>
<update>Y</update>
</value>
<value>
<name>"4_more_child"</name>
<rename>four_or_more_children</rename>
<update>Y</update>
</value>
<value>
<name>"all_M_W"</name>
<rename>gender</rename>
<update>N</update>
</value>
<value>
<name>no_child_percent</name>
<rename>no_children_percent</rename>
<update>Y</update>
</value>
<value>
<name>"1_child_percent"</name>
<rename>one_child_percent</rename>
<update>Y</update>
</value>
<value>
<name>"2_child_percent"</name>
<rename>two_children_percent</rename>
<update>Y</update>
</value>
<value>
<name>"3_child_percent"</name>
<rename>three_children_percent</rename>
<update>Y</update>
</value>
<value>
<name>"4_more_child_percent"</name>
<rename>four_or_more_children_percent</rename>
<update>Y</update>
</value>
<value>
<name>recruitment_id</name>
<rename>recruitment_id</rename>
<update>N</update>
</value>
</lookup>
<attributes/>
<cluster_schema/>
<GUI>
<xloc>1040</xloc>
<yloc>288</yloc>
<draw>Y</draw>
</GUI>
</transform>
<transform>
<name>Insert / update (total_registered.child_minor) 2</name>
<type>InsertUpdate</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<connection>ervu-dashboard</connection>
<commit>100</commit>
<update_bypassed>N</update_bypassed>
<lookup>
<schema>total_registered</schema>
<table>child_minor</table>
<key>
<name>REG_ID</name>
<field>recruitment_id</field>
<condition>=</condition>
<name2/>
</key>
<value>
<name>no_child</name>
<rename>no_children</rename>
<update>Y</update>
</value>
<value>
<name>"1_child"</name>
<rename>one_child</rename>
<update>Y</update>
</value>
<value>
<name>"2_child"</name>
<rename>two_children</rename>
<update>Y</update>
</value>
<value>
<name>"3_child"</name>
<rename>three_children</rename>
<update>Y</update>
</value>
<value>
<name>"4_more_child"</name>
<rename>four_or_more_children</rename>
<update>Y</update>
</value>
<value>
<name>"all_M_W"</name>
<rename>gender</rename>
<update>N</update>
</value>
<value>
<name>no_child_percent</name>
<rename>no_children_percent</rename>
<update>Y</update>
</value>
<value>
<name>"1_child_percent"</name>
<rename>one_child_percent</rename>
<update>Y</update>
</value>
<value>
<name>"2_child_percent"</name>
<rename>two_children_percent</rename>
<update>Y</update>
</value>
<value>
<name>"3_child_percent"</name>
<rename>three_children_percent</rename>
<update>Y</update>
</value>
<value>
<name>"4_more_child_percent"</name>
<rename>four_or_more_children_percent</rename>
<update>Y</update>
</value>
<value>
<name>recruitment_id</name>
<rename>recruitment_id</rename>
<update>N</update>
</value>
</lookup>
<attributes/>
<cluster_schema/>
<GUI>
<xloc>1040</xloc>
<yloc>384</yloc>
<draw>Y</draw>
</GUI>
</transform>
<transform>
<name>Insert / update (total_registered.child_minor) 2 2</name>
<type>InsertUpdate</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<connection>ervu-dashboard</connection>
<commit>100</commit>
<update_bypassed>N</update_bypassed>
<lookup>
<schema>total_registered</schema>
<table>child_minor</table>
<key>
<name>REG_ID</name>
<field>recruitment_id</field>
<condition>=</condition>
<name2/>
</key>
<value>
<name>no_child</name>
<rename>no_children</rename>
<update>Y</update>
</value>
<value>
<name>"1_child"</name>
<rename>one_child</rename>
<update>Y</update>
</value>
<value>
<name>"2_child"</name>
<rename>two_children</rename>
<update>Y</update>
</value>
<value>
<name>"3_child"</name>
<rename>three_children</rename>
<update>Y</update>
</value>
<value>
<name>"4_more_child"</name>
<rename>four_or_more_children</rename>
<update>Y</update>
</value>
<value>
<name>"all_M_W"</name>
<rename>gender</rename>
<update>N</update>
</value>
<value>
<name>no_child_percent</name>
<rename>no_children_percent</rename>
<update>Y</update>
</value>
<value>
<name>"1_child_percent"</name>
<rename>one_child_percent</rename>
<update>Y</update>
</value>
<value>
<name>"2_child_percent"</name>
<rename>two_children_percent</rename>
<update>Y</update>
</value>
<value>
<name>"3_child_percent"</name>
<rename>three_children_percent</rename>
<update>Y</update>
</value>
<value>
<name>"4_more_child_percent"</name>
<rename>four_or_more_children_percent</rename>
<update>Y</update>
</value>
<value>
<name>recruitment_id</name>
<rename>recruitment_id</rename>
<update>N</update>
</value>
</lookup>
<attributes/>
<cluster_schema/>
<GUI>
<xloc>1040</xloc>
<yloc>480</yloc>
<draw>Y</draw>
</GUI>
</transform>
<transform>
<name>Select values 4 2</name>
<type>SelectValues</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<fields>
<select_unspecified>N</select_unspecified>
<meta>
<name>REG_ID</name>
<rename>REG_ID</rename>
<type>String</type>
<length>-2</length>
<precision>-2</precision>
<conversion_mask/>
<date_format_lenient>false</date_format_lenient>
<date_format_locale/>
<date_format_timezone/>
<lenient_string_to_number>false</lenient_string_to_number>
<encoding/>
<decimal_symbol/>
<grouping_symbol/>
<currency_symbol/>
<storage_type/>
</meta>
<meta>
<name>VK_ARRAY</name>
<rename>VK_ARRAY</rename>
<type>String</type>
<length>-2</length>
<precision>-2</precision>
<conversion_mask/>
<date_format_lenient>false</date_format_lenient>
<date_format_locale/>
<date_format_timezone/>
<lenient_string_to_number>false</lenient_string_to_number>
<encoding/>
<decimal_symbol/>
<grouping_symbol/>
<currency_symbol/>
<storage_type/>
</meta>
</fields>
<attributes/>
<cluster_schema/>
<GUI>
<xloc>784</xloc>
<yloc>288</yloc>
<draw>Y</draw>
</GUI>
</transform>
<transform>
<name>Select values 4 2 2</name>
<type>SelectValues</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<fields>
<select_unspecified>N</select_unspecified>
<meta>
<name>REG_ID</name>
<rename>REG_ID</rename>
<type>String</type>
<length>-2</length>
<precision>-2</precision>
<conversion_mask/>
<date_format_lenient>false</date_format_lenient>
<date_format_locale/>
<date_format_timezone/>
<lenient_string_to_number>false</lenient_string_to_number>
<encoding/>
<decimal_symbol/>
<grouping_symbol/>
<currency_symbol/>
<storage_type/>
</meta>
<meta>
<name>VK_ARRAY</name>
<rename>VK_ARRAY</rename>
<type>String</type>
<length>-2</length>
<precision>-2</precision>
<conversion_mask/>
<date_format_lenient>false</date_format_lenient>
<date_format_locale/>
<date_format_timezone/>
<lenient_string_to_number>false</lenient_string_to_number>
<encoding/>
<decimal_symbol/>
<grouping_symbol/>
<currency_symbol/>
<storage_type/>
</meta>
</fields>
<attributes/>
<cluster_schema/>
<GUI>
<xloc>784</xloc>
<yloc>384</yloc>
<draw>Y</draw>
</GUI>
</transform>
<transform>
<name>Select values 4 2 2 2</name>
<type>SelectValues</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<fields>
<select_unspecified>N</select_unspecified>
<meta>
<name>REG_ID</name>
<rename>REG_ID</rename>
<type>String</type>
<length>-2</length>
<precision>-2</precision>
<conversion_mask/>
<date_format_lenient>false</date_format_lenient>
<date_format_locale/>
<date_format_timezone/>
<lenient_string_to_number>false</lenient_string_to_number>
<encoding/>
<decimal_symbol/>
<grouping_symbol/>
<currency_symbol/>
<storage_type/>
</meta>
<meta>
<name>VK_ARRAY</name>
<rename>VK_ARRAY</rename>
<type>String</type>
<length>-2</length>
<precision>-2</precision>
<conversion_mask/>
<date_format_lenient>false</date_format_lenient>
<date_format_locale/>
<date_format_timezone/>
<lenient_string_to_number>false</lenient_string_to_number>
<encoding/>
<decimal_symbol/>
<grouping_symbol/>
<currency_symbol/>
<storage_type/>
</meta>
</fields>
<attributes/>
<cluster_schema/>
<GUI>
<xloc>784</xloc>
<yloc>480</yloc>
<draw>Y</draw>
</GUI>
</transform>
<transform>
<name>Table input (person_registry)РФ/женщины</name>
<type>TableInput</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<connection>ervu_person_registry</connection>
<sql>WITH extracted_children AS (
SELECT
ri.recruit_id,
jsonb_array_elements_text(ri.info->'svedDeti'->'rebenok') AS child
FROM
public.recruits_info ri
JOIN public.recruits r ON ri.recruit_id = r.id
WHERE
jsonb_typeof(ri.info->'svedDeti'->'rebenok') = 'array'
AND r.vu_current_info->>'isMilitaryRegistered' = 'true'
AND r.gender = 'FEMALE'
AND r.current_recruitment_id IS NOT NULL
AND (
'${VK_ARRAY}' IS NULL
OR '${VK_ARRAY}' = ''
OR r.target_recruitment_id = ANY (
string_to_array(
trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ','
)::uuid[]
)
)
),
children_birth_dates AS (
SELECT
recruit_id,
(child::jsonb->'svedFLBS'->'dataRozhdDok'->>'den')::int AS day,
(child::jsonb->'svedFLBS'->'dataRozhdDok'->>'mesyacz')::int AS month,
(child::jsonb->'svedFLBS'->'dataRozhdDok'->>'god')::int AS year
FROM
extracted_children
),
children_count AS (
SELECT
recruit_id,
COUNT(*) AS children_under_18
FROM
children_birth_dates
WHERE
make_date(year, month, day) > CURRENT_DATE - INTERVAL '18 years'
GROUP BY
recruit_id
),
final_counts AS (
SELECT
COALESCE(children_under_18, 0) AS children_count,
COUNT(*) AS num_people
FROM
public.recruits_info ri
LEFT JOIN
children_count cc ON ri.recruit_id = cc.recruit_id
JOIN public.recruits r ON ri.recruit_id = r.id
WHERE
r.vu_current_info->>'isMilitaryRegistered' = 'true'
AND r.gender = 'FEMALE'
AND r.current_recruitment_id IS NOT NULL
AND (
'${VK_ARRAY}' IS NULL
OR '${VK_ARRAY}' = ''
OR r.target_recruitment_id = ANY (
string_to_array(
trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ','
)::uuid[]
)
)
GROUP BY
COALESCE(children_under_18, 0)
),
total_women AS (
SELECT
COUNT(*) AS total_women_count
FROM
public.recruits_info ri
JOIN public.recruits r ON ri.recruit_id = r.id
WHERE
r.vu_current_info->>'isMilitaryRegistered' = 'true'
AND r.gender = 'FEMALE'
AND r.current_recruitment_id IS NOT NULL
AND (
'${VK_ARRAY}' IS NULL
OR '${VK_ARRAY}' = ''
OR r.target_recruitment_id = ANY (
string_to_array(
trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ','
)::uuid[]
)
)
)
SELECT
'W' AS gender,
'${REG_ID}' AS recruitment_id,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count = 0 THEN num_people ELSE 0 END), 0) END AS no_children,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count = 1 THEN num_people ELSE 0 END), 0) END AS one_child,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count = 2 THEN num_people ELSE 0 END), 0) END AS two_children,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count = 3 THEN num_people ELSE 0 END), 0) END AS three_children,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count >= 4 THEN num_people ELSE 0 END), 0) END AS four_or_more_children,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count = 0 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_women_count FROM total_women), 0), 2) END AS no_children_percent,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count = 1 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_women_count FROM total_women), 0), 2) END AS one_child_percent,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count = 2 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_women_count FROM total_women), 0), 2) END AS two_children_percent,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count = 3 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_women_count FROM total_women), 0), 2) END AS three_children_percent,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count >= 4 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_women_count FROM total_women), 0), 2) END AS four_or_more_children_percent
FROM
final_counts;</sql>
<limit>0</limit>
<lookup/>
<execute_each_row>N</execute_each_row>
<variables_active>Y</variables_active>
<lazy_conversion_active>N</lazy_conversion_active>
<attributes/>
<cluster_schema/>
<GUI>
<xloc>352</xloc>
<yloc>480</yloc>
<draw>Y</draw>
</GUI>
</transform>
<transform>
<name>Table input (person_registry)РФ/мужчины</name>
<type>TableInput</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<connection>ervu_person_registry</connection>
<sql>WITH extracted_children AS (
SELECT
ri.recruit_id,
jsonb_array_elements_text(ri.info->'svedDeti'->'rebenok') AS child
FROM
public.recruits_info ri
JOIN public.recruits r ON ri.recruit_id = r.id
WHERE
jsonb_typeof(ri.info->'svedDeti'->'rebenok') = 'array'
AND r.vu_current_info->>'isMilitaryRegistered' = 'true'
AND r.gender = 'MALE'
AND r.current_recruitment_id IS NOT NULL
AND (
'${VK_ARRAY}' IS NULL
OR '${VK_ARRAY}' = ''
OR r.target_recruitment_id = ANY (
string_to_array(
trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ','
)::uuid[]
)
)
),
children_birth_dates AS (
SELECT
recruit_id,
(child::jsonb->'svedFLBS'->'dataRozhdDok'->>'den')::int AS day,
(child::jsonb->'svedFLBS'->'dataRozhdDok'->>'mesyacz')::int AS month,
(child::jsonb->'svedFLBS'->'dataRozhdDok'->>'god')::int AS year
FROM
extracted_children
),
children_count AS (
SELECT
recruit_id,
COUNT(*) AS children_under_18
FROM
children_birth_dates
WHERE
make_date(year, month, day) > CURRENT_DATE - INTERVAL '18 years'
GROUP BY
recruit_id
),
final_counts AS (
SELECT
COALESCE(children_under_18, 0) AS children_count,
COUNT(*) AS num_people
FROM
public.recruits_info ri
LEFT JOIN
children_count cc ON ri.recruit_id = cc.recruit_id
JOIN public.recruits r ON ri.recruit_id = r.id
WHERE
r.vu_current_info->>'isMilitaryRegistered' = 'true'
AND r.gender = 'MALE'
AND r.current_recruitment_id IS NOT NULL
AND (
'${VK_ARRAY}' IS NULL
OR '${VK_ARRAY}' = ''
OR r.target_recruitment_id = ANY (
string_to_array(
trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ','
)::uuid[]
)
)
GROUP BY
COALESCE(children_under_18, 0)
),
total_men AS (
SELECT
COUNT(*) AS total_men_count
FROM
public.recruits_info ri
JOIN public.recruits r ON ri.recruit_id = r.id
WHERE
r.vu_current_info->>'isMilitaryRegistered' = 'true'
AND r.gender = 'MALE'
AND r.current_recruitment_id IS NOT NULL
AND (
'${VK_ARRAY}' IS NULL
OR '${VK_ARRAY}' = ''
OR r.target_recruitment_id = ANY (
string_to_array(
trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ','
)::uuid[]
)
)
)
SELECT
'M' AS gender,
'${REG_ID}' AS recruitment_id,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count = 0 THEN num_people ELSE 0 END), 0) END AS no_children,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count = 1 THEN num_people ELSE 0 END), 0) END AS one_child,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count = 2 THEN num_people ELSE 0 END), 0) END AS two_children,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count = 3 THEN num_people ELSE 0 END), 0) END AS three_children,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count >= 4 THEN num_people ELSE 0 END), 0) END AS four_or_more_children,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count = 0 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_men_count FROM total_men), 0), 2) END AS no_children_percent,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count = 1 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_men_count FROM total_men), 0), 2) END AS one_child_percent,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count = 2 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_men_count FROM total_men), 0), 2) END AS two_children_percent,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count = 3 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_men_count FROM total_men), 0), 2) END AS three_children_percent,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count >= 4 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_men_count FROM total_men), 0), 2) END AS four_or_more_children_percent
FROM
final_counts;</sql>
<limit>0</limit>
<lookup/>
<execute_each_row>N</execute_each_row>
<variables_active>Y</variables_active>
<lazy_conversion_active>N</lazy_conversion_active>
<attributes/>
<cluster_schema/>
<GUI>
<xloc>352</xloc>
<yloc>384</yloc>
<draw>Y</draw>
</GUI>
</transform>
<transform>
<name>Table input (person_registry)регион/все</name>
<type>TableInput</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<connection>ervu_person_registry</connection>
<sql>WITH extracted_children AS (
SELECT
ri.recruit_id,
jsonb_array_elements_text(ri.info->'svedDeti'->'rebenok') AS child
FROM
public.recruits_info ri
JOIN public.recruits r ON ri.recruit_id = r.id
WHERE
jsonb_typeof(ri.info->'svedDeti'->'rebenok') = 'array'
AND r.vu_current_info->>'isMilitaryRegistered' = 'true'
AND r.current_recruitment_id IS NOT NULL
AND (
'${VK_ARRAY}' IS NULL
OR '${VK_ARRAY}' = ''
OR r.target_recruitment_id = ANY (
string_to_array(
trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ','
)::uuid[]
)
)
),
children_birth_dates AS (
SELECT
recruit_id,
(child::jsonb->'svedFLBS'->'dataRozhdDok'->>'den')::int AS day,
(child::jsonb->'svedFLBS'->'dataRozhdDok'->>'mesyacz')::int AS month,
(child::jsonb->'svedFLBS'->'dataRozhdDok'->>'god')::int AS year
FROM
extracted_children
),
children_count AS (
SELECT
recruit_id,
COUNT(*) AS children_under_18
FROM
children_birth_dates
WHERE
AGE(make_date(year, month, day)) &lt; interval '18 years'
GROUP BY
recruit_id
),
final_counts AS (
SELECT
COALESCE(children_under_18, 0) AS children_count,
COUNT(*) AS num_people
FROM
public.recruits_info ri
LEFT JOIN
children_count cc ON ri.recruit_id = cc.recruit_id
JOIN public.recruits r ON ri.recruit_id = r.id
WHERE r.vu_current_info->>'isMilitaryRegistered' = 'true'
AND r.current_recruitment_id IS NOT NULL
AND (
'${VK_ARRAY}' IS NULL
OR '${VK_ARRAY}' = ''
OR r.target_recruitment_id = ANY (
string_to_array(
trim(both '{}' FROM replace('${VK_ARRAY}', ' ', '')), ','
)::uuid[]
)
)
GROUP BY
COALESCE(children_under_18, 0)
),
total_people AS (
SELECT SUM(num_people) AS total_count
FROM final_counts
)
SELECT
'ALL' AS gender,
'${REG_ID}' as recruitment_id,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count = 0 THEN num_people ELSE 0 END), 0) END AS no_children,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count = 1 THEN num_people ELSE 0 END), 0) END AS one_child,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count = 2 THEN num_people ELSE 0 END), 0) END AS two_children,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count = 3 THEN num_people ELSE 0 END), 0) END AS three_children,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE COALESCE(SUM(CASE WHEN children_count >= 4 THEN num_people ELSE 0 END), 0) END AS four_or_more_children,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count = 0 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_count FROM total_people), 0), 2) END AS no_children_percent,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count = 1 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_count FROM total_people), 0), 2) END AS one_child_percent,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count = 2 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_count FROM total_people), 0), 2) END AS two_children_percent,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count = 3 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_count FROM total_people), 0), 2) END AS three_children_percent,
CASE WHEN '${VK_ARRAY}' IS NULL OR '${VK_ARRAY}' = '' THEN 0 ELSE ROUND(COALESCE(SUM(CASE WHEN children_count >= 4 THEN num_people ELSE 0 END), 0) * 100.0 / NULLIF((SELECT total_count FROM total_people), 0), 2) END AS four_or_more_children_percent
FROM
final_counts;</sql>
<limit>0</limit>
<lookup/>
<execute_each_row>N</execute_each_row>
<variables_active>Y</variables_active>
<lazy_conversion_active>N</lazy_conversion_active>
<attributes/>
<cluster_schema/>
<GUI>
<xloc>352</xloc>
<yloc>288</yloc>
<draw>Y</draw>
</GUI>
</transform>
<transform_error_handling>
</transform_error_handling>
<attributes/>
</pipeline>