<?xml version="1.0" encoding="UTF-8"?>
<pipeline>
  <info>
    <name>citizen_sports_categories</name>
    <name_sync_with_filename>Y</name_sync_with_filename>
    <description/>
    <extended_description/>
    <pipeline_version/>
    <pipeline_type>Normal</pipeline_type>
    <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>2025/02/14 13:05:06.026</created_date>
    <modified_user>-</modified_user>
    <modified_date>2025/02/14 13:05:06.026</modified_date>
  </info>
  <notepads>
  </notepads>
  <order>
    <hop>
      <from>Table input</from>
      <to>Insert / update</to>
      <enabled>Y</enabled>
    </hop>
  </order>
  <transform>
    <name>Insert / update</name>
    <type>InsertUpdate</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <commit>10000</commit>
    <connection>ervu-dashboard</connection>
    <lookup>
      <key>
        <condition>=</condition>
        <field>recruit_id</field>
        <name>recruit_id</name>
        <name2/>
      </key>
      <schema>ervu-dashboard</schema>
      <table>citizen_sports_categories</table>
      <value>
        <name>recruit_id</name>
        <rename>recruit_id</rename>
        <update>N</update>
      </value>
      <value>
        <name>start_date_category</name>
        <rename>start_date_category</rename>
        <update>Y</update>
      </value>
      <value>
        <name>end_date_category</name>
        <rename>end_date_category</rename>
        <update>Y</update>
      </value>
      <value>
        <name>sports_category_name</name>
        <rename>sports_category_name</rename>
        <update>Y</update>
      </value>
      <value>
        <name>type_sport</name>
        <rename>type_sport</rename>
        <update>Y</update>
      </value>
      <value>
        <name>sport_title</name>
        <rename>sport_title</rename>
        <update>Y</update>
      </value>
      <value>
        <name>having_sport_category</name>
        <rename>having_sport_category</rename>
        <update>Y</update>
      </value>
      <value>
        <name>having_sport_title</name>
        <rename>having_sport_title</rename>
        <update>Y</update>
      </value>
    </lookup>
    <update_bypassed>N</update_bypassed>
    <attributes/>
    <GUI>
      <xloc>672</xloc>
      <yloc>256</yloc>
    </GUI>
  </transform>
  <transform>
    <name>Table input</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>
    <execute_each_row>N</execute_each_row>
    <sql>SELECT recruit_id,
       (sport_info->'sportRazr'->>'dataPrisv')::date start_date_category,
       (sport_info->'sportRazr'->>'dataDeistv')::date as end_date_category,
       sport_info->'sportRazr'->>'razryadNaim' as sports_category_name,
       sport_info->'sportRazr'->>'sportNaim' as type_sport,
       sport_info->>'sportZvan' as sport_title,
       case when sport_info->>'sportRazr' != 'null'
        then true else false end as having_sport_category,
       (case when sport_info->>'sportZvan' != 'null'
       then true else false end) as having_sport_title
FROM public.recruits_info ri
join public.recruits r ON r.id = ri.recruit_id AND r.system_update_date >= '${UP_D}',
     jsonb_array_elements(ri.info->'svedFL'->'svedSport'->'sport') AS sport_info
WHERE info->'svedFL'->'svedSport'->>'sport' != 'null'
  and info->'svedFL'->'svedSport'->>'sport' != '[]';</sql>
    <variables_active>Y</variables_active>
    <attributes/>
    <GUI>
      <xloc>384</xloc>
      <yloc>256</yloc>
    </GUI>
  </transform>
  <transform_error_handling>
  </transform_error_handling>
  <attributes/>
</pipeline>
