how to rename attribute names through config file in rapidminer

sgnarkhede2016
sgnarkhede2016 New Altair Community Member
edited November 2024 in Community Q&A
Hello ,
I have two column in db "Name and Rename"
how can rename the Name after reading database I need to rename "Name" fields with "Rename" value present in db.

Any new attribute added in db it automatically rename values in future we have provided in db

e.g.
1) first time when create db/excel
Name       Rename
Sachin      Sachin N
Om            Om Rathi

2)After few days added new column in db/excel

Name       Rename
Sachin      Sachin N
Om            Om Rathi
Sager        Sagi

how to achieve this in rapidminer




Tagged:

Best Answer

  • YYH
    YYH
    Altair Employee
    edited March 2020 Answer ✓
    Hi @sgnarkhede2016,

    I believe there is a solution in database to dynamically call SQL procedure. e.g. https://stackoverflow.com/questions/47159800/sql-server-rename-column-within-stored-procedure-with-different-databases

    If you prefer a code-free solution, the attached process is built in RapidMiner with an iterative loop that scan your reference mapping table top-to-bottom and "Rename" is applied for each pair of old name & new name. The only maintenance you have to do is keeping the mapping dictionary table updated.

    <?xml version="1.0" encoding="UTF-8"?><process version="9.6.000">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="9.6.000" expanded="true" name="Process">
        <parameter key="logverbosity" value="init"/>
        <parameter key="random_seed" value="2001"/>
        <parameter key="send_mail" value="never"/>
        <parameter key="notification_email" value="yhuang@rapidminer.com"/>
        <parameter key="process_duration_for_mail" value="1"/>
        <parameter key="encoding" value="SYSTEM"/>
        <process expanded="true">
          <operator activated="true" class="utility:create_exampleset" compatibility="9.6.000" expanded="true" height="68" name="Create ExampleSet" width="90" x="246" y="289">
            <parameter key="generator_type" value="comma separated text"/>
            <parameter key="number_of_examples" value="100"/>
            <parameter key="use_stepsize" value="false"/>
            <list key="function_descriptions"/>
            <parameter key="add_id_attribute" value="false"/>
            <list key="numeric_series_configuration"/>
            <list key="date_series_configuration"/>
            <list key="date_series_configuration (interval)"/>
            <parameter key="date_format" value="yyyy-MM-dd HH:mm:ss"/>
            <parameter key="time_zone" value="SYSTEM"/>
            <parameter key="input_csv_text" value="Name,Rename&#10;Sachin,Sachin N&#10;Om,Om Rathi&#10;Sager,Sagi"/>
            <parameter key="column_separator" value=","/>
            <parameter key="parse_all_as_nominal" value="false"/>
            <parameter key="decimal_point_character" value="."/>
            <parameter key="trim_attribute_names" value="true"/>
            <description align="center" color="transparent" colored="false" width="126">mapping dictionary for renaming</description>
          </operator>
          <operator activated="true" class="extract_macro" compatibility="9.6.000" expanded="true" height="68" name="Extract Macro" width="90" x="380" y="289">
            <parameter key="macro" value="NN_RENAME"/>
            <parameter key="macro_type" value="number_of_examples"/>
            <parameter key="statistics" value="average"/>
            <parameter key="attribute_name" value=""/>
            <list key="additional_macros"/>
          </operator>
          <operator activated="true" breakpoints="after" class="utility:create_exampleset" compatibility="9.6.000" expanded="true" height="68" name="Create ExampleSet (2)" width="90" x="246" y="34">
            <parameter key="generator_type" value="comma separated text"/>
            <parameter key="number_of_examples" value="100"/>
            <parameter key="use_stepsize" value="false"/>
            <list key="function_descriptions"/>
            <parameter key="add_id_attribute" value="false"/>
            <list key="numeric_series_configuration"/>
            <list key="date_series_configuration"/>
            <list key="date_series_configuration (interval)"/>
            <parameter key="date_format" value="yyyy-MM-dd HH:mm:ss"/>
            <parameter key="time_zone" value="SYSTEM"/>
            <parameter key="input_csv_text" value="id,Sachin,Om,Sager&#10;1,2,3,4&#10;2,2,3,4&#10;3,2,3,4"/>
            <parameter key="column_separator" value=","/>
            <parameter key="parse_all_as_nominal" value="false"/>
            <parameter key="decimal_point_character" value="."/>
            <parameter key="trim_attribute_names" value="true"/>
            <description align="center" color="transparent" colored="false" width="126">any database table</description>
          </operator>
          <operator activated="true" class="set_role" compatibility="9.6.000" expanded="true" height="82" name="Set Role" width="90" x="380" y="34">
            <parameter key="attribute_name" value="id"/>
            <parameter key="target_role" value="id"/>
            <list key="set_additional_roles"/>
          </operator>
          <operator activated="true" class="concurrency:loop" compatibility="9.6.000" expanded="true" height="103" name="Loop" width="90" x="648" y="34">
            <parameter key="number_of_iterations" value="%{NN_RENAME}"/>
            <parameter key="iteration_macro" value="iteration"/>
            <parameter key="reuse_results" value="true"/>
            <parameter key="enable_parallel_execution" value="true"/>
            <process expanded="true">
              <operator activated="true" class="filter_example_range" compatibility="9.6.000" expanded="true" height="82" name="Filter Example Range" width="90" x="45" y="136">
                <parameter key="first_example" value="%{iteration}"/>
                <parameter key="last_example" value="%{iteration}"/>
                <parameter key="invert_filter" value="false"/>
              </operator>
              <operator activated="true" class="extract_macro" compatibility="9.6.000" expanded="true" height="68" name="Extract Macro (2)" width="90" x="179" y="136">
                <parameter key="macro" value="OLD_NAME"/>
                <parameter key="macro_type" value="data_value"/>
                <parameter key="statistics" value="average"/>
                <parameter key="attribute_name" value="Name"/>
                <parameter key="example_index" value="1"/>
                <list key="additional_macros">
                  <parameter key="NEW_NAME" value="Rename"/>
                </list>
              </operator>
              <operator activated="false" class="operator_toolbox:set_parameters_from_es" compatibility="2.3.000" expanded="true" height="82" name="Set Parameters from ExampleSet" width="90" x="313" y="340">
                <parameter key="operator_name_attribute" value="FUNCTION_NAME"/>
                <parameter key="parameter_name_attribute" value=""/>
                <parameter key="value_attribute" value=""/>
              </operator>
              <operator activated="true" class="rename" compatibility="9.6.000" expanded="true" height="82" name="Rename" width="90" x="380" y="34">
                <parameter key="old_name" value="%{OLD_NAME}"/>
                <parameter key="new_name" value="%{NEW_NAME}"/>
                <list key="rename_additional_attributes"/>
              </operator>
              <connect from_port="input 1" to_op="Rename" to_port="example set input"/>
              <connect from_port="input 2" to_op="Filter Example Range" to_port="example set input"/>
              <connect from_op="Filter Example Range" from_port="example set output" to_op="Extract Macro (2)" to_port="example set"/>
              <connect from_op="Filter Example Range" from_port="original" to_port="output 2"/>
              <connect from_op="Rename" from_port="example set output" to_port="output 1"/>
              <portSpacing port="source_input 1" spacing="0"/>
              <portSpacing port="source_input 2" spacing="0"/>
              <portSpacing port="source_input 3" spacing="0"/>
              <portSpacing port="sink_output 1" spacing="0"/>
              <portSpacing port="sink_output 2" spacing="0"/>
              <portSpacing port="sink_output 3" spacing="0"/>
            </process>
          </operator>
          <connect from_op="Create ExampleSet" from_port="output" to_op="Extract Macro" to_port="example set"/>
          <connect from_op="Extract Macro" from_port="example set" to_op="Loop" to_port="input 2"/>
          <connect from_op="Create ExampleSet (2)" from_port="output" to_op="Set Role" to_port="example set input"/>
          <connect from_op="Set Role" from_port="example set output" to_op="Loop" to_port="input 1"/>
          <connect from_op="Loop" from_port="output 1" to_port="result 1"/>
          <connect from_op="Loop" from_port="output 2" to_port="result 2"/>
          <portSpacing port="source_input 1" spacing="0"/>
          <portSpacing port="sink_result 1" spacing="0"/>
          <portSpacing port="sink_result 2" spacing="0"/>
          <portSpacing port="sink_result 3" spacing="0"/>
        </process>
      </operator>
    </process>
    



    HTH!

    Cheers,
    YY

Answers

  • YYH
    YYH
    Altair Employee
    edited March 2020 Answer ✓
    Hi @sgnarkhede2016,

    I believe there is a solution in database to dynamically call SQL procedure. e.g. https://stackoverflow.com/questions/47159800/sql-server-rename-column-within-stored-procedure-with-different-databases

    If you prefer a code-free solution, the attached process is built in RapidMiner with an iterative loop that scan your reference mapping table top-to-bottom and "Rename" is applied for each pair of old name & new name. The only maintenance you have to do is keeping the mapping dictionary table updated.

    <?xml version="1.0" encoding="UTF-8"?><process version="9.6.000">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="9.6.000" expanded="true" name="Process">
        <parameter key="logverbosity" value="init"/>
        <parameter key="random_seed" value="2001"/>
        <parameter key="send_mail" value="never"/>
        <parameter key="notification_email" value="yhuang@rapidminer.com"/>
        <parameter key="process_duration_for_mail" value="1"/>
        <parameter key="encoding" value="SYSTEM"/>
        <process expanded="true">
          <operator activated="true" class="utility:create_exampleset" compatibility="9.6.000" expanded="true" height="68" name="Create ExampleSet" width="90" x="246" y="289">
            <parameter key="generator_type" value="comma separated text"/>
            <parameter key="number_of_examples" value="100"/>
            <parameter key="use_stepsize" value="false"/>
            <list key="function_descriptions"/>
            <parameter key="add_id_attribute" value="false"/>
            <list key="numeric_series_configuration"/>
            <list key="date_series_configuration"/>
            <list key="date_series_configuration (interval)"/>
            <parameter key="date_format" value="yyyy-MM-dd HH:mm:ss"/>
            <parameter key="time_zone" value="SYSTEM"/>
            <parameter key="input_csv_text" value="Name,Rename&#10;Sachin,Sachin N&#10;Om,Om Rathi&#10;Sager,Sagi"/>
            <parameter key="column_separator" value=","/>
            <parameter key="parse_all_as_nominal" value="false"/>
            <parameter key="decimal_point_character" value="."/>
            <parameter key="trim_attribute_names" value="true"/>
            <description align="center" color="transparent" colored="false" width="126">mapping dictionary for renaming</description>
          </operator>
          <operator activated="true" class="extract_macro" compatibility="9.6.000" expanded="true" height="68" name="Extract Macro" width="90" x="380" y="289">
            <parameter key="macro" value="NN_RENAME"/>
            <parameter key="macro_type" value="number_of_examples"/>
            <parameter key="statistics" value="average"/>
            <parameter key="attribute_name" value=""/>
            <list key="additional_macros"/>
          </operator>
          <operator activated="true" breakpoints="after" class="utility:create_exampleset" compatibility="9.6.000" expanded="true" height="68" name="Create ExampleSet (2)" width="90" x="246" y="34">
            <parameter key="generator_type" value="comma separated text"/>
            <parameter key="number_of_examples" value="100"/>
            <parameter key="use_stepsize" value="false"/>
            <list key="function_descriptions"/>
            <parameter key="add_id_attribute" value="false"/>
            <list key="numeric_series_configuration"/>
            <list key="date_series_configuration"/>
            <list key="date_series_configuration (interval)"/>
            <parameter key="date_format" value="yyyy-MM-dd HH:mm:ss"/>
            <parameter key="time_zone" value="SYSTEM"/>
            <parameter key="input_csv_text" value="id,Sachin,Om,Sager&#10;1,2,3,4&#10;2,2,3,4&#10;3,2,3,4"/>
            <parameter key="column_separator" value=","/>
            <parameter key="parse_all_as_nominal" value="false"/>
            <parameter key="decimal_point_character" value="."/>
            <parameter key="trim_attribute_names" value="true"/>
            <description align="center" color="transparent" colored="false" width="126">any database table</description>
          </operator>
          <operator activated="true" class="set_role" compatibility="9.6.000" expanded="true" height="82" name="Set Role" width="90" x="380" y="34">
            <parameter key="attribute_name" value="id"/>
            <parameter key="target_role" value="id"/>
            <list key="set_additional_roles"/>
          </operator>
          <operator activated="true" class="concurrency:loop" compatibility="9.6.000" expanded="true" height="103" name="Loop" width="90" x="648" y="34">
            <parameter key="number_of_iterations" value="%{NN_RENAME}"/>
            <parameter key="iteration_macro" value="iteration"/>
            <parameter key="reuse_results" value="true"/>
            <parameter key="enable_parallel_execution" value="true"/>
            <process expanded="true">
              <operator activated="true" class="filter_example_range" compatibility="9.6.000" expanded="true" height="82" name="Filter Example Range" width="90" x="45" y="136">
                <parameter key="first_example" value="%{iteration}"/>
                <parameter key="last_example" value="%{iteration}"/>
                <parameter key="invert_filter" value="false"/>
              </operator>
              <operator activated="true" class="extract_macro" compatibility="9.6.000" expanded="true" height="68" name="Extract Macro (2)" width="90" x="179" y="136">
                <parameter key="macro" value="OLD_NAME"/>
                <parameter key="macro_type" value="data_value"/>
                <parameter key="statistics" value="average"/>
                <parameter key="attribute_name" value="Name"/>
                <parameter key="example_index" value="1"/>
                <list key="additional_macros">
                  <parameter key="NEW_NAME" value="Rename"/>
                </list>
              </operator>
              <operator activated="false" class="operator_toolbox:set_parameters_from_es" compatibility="2.3.000" expanded="true" height="82" name="Set Parameters from ExampleSet" width="90" x="313" y="340">
                <parameter key="operator_name_attribute" value="FUNCTION_NAME"/>
                <parameter key="parameter_name_attribute" value=""/>
                <parameter key="value_attribute" value=""/>
              </operator>
              <operator activated="true" class="rename" compatibility="9.6.000" expanded="true" height="82" name="Rename" width="90" x="380" y="34">
                <parameter key="old_name" value="%{OLD_NAME}"/>
                <parameter key="new_name" value="%{NEW_NAME}"/>
                <list key="rename_additional_attributes"/>
              </operator>
              <connect from_port="input 1" to_op="Rename" to_port="example set input"/>
              <connect from_port="input 2" to_op="Filter Example Range" to_port="example set input"/>
              <connect from_op="Filter Example Range" from_port="example set output" to_op="Extract Macro (2)" to_port="example set"/>
              <connect from_op="Filter Example Range" from_port="original" to_port="output 2"/>
              <connect from_op="Rename" from_port="example set output" to_port="output 1"/>
              <portSpacing port="source_input 1" spacing="0"/>
              <portSpacing port="source_input 2" spacing="0"/>
              <portSpacing port="source_input 3" spacing="0"/>
              <portSpacing port="sink_output 1" spacing="0"/>
              <portSpacing port="sink_output 2" spacing="0"/>
              <portSpacing port="sink_output 3" spacing="0"/>
            </process>
          </operator>
          <connect from_op="Create ExampleSet" from_port="output" to_op="Extract Macro" to_port="example set"/>
          <connect from_op="Extract Macro" from_port="example set" to_op="Loop" to_port="input 2"/>
          <connect from_op="Create ExampleSet (2)" from_port="output" to_op="Set Role" to_port="example set input"/>
          <connect from_op="Set Role" from_port="example set output" to_op="Loop" to_port="input 1"/>
          <connect from_op="Loop" from_port="output 1" to_port="result 1"/>
          <connect from_op="Loop" from_port="output 2" to_port="result 2"/>
          <portSpacing port="source_input 1" spacing="0"/>
          <portSpacing port="sink_result 1" spacing="0"/>
          <portSpacing port="sink_result 2" spacing="0"/>
          <portSpacing port="sink_result 3" spacing="0"/>
        </process>
      </operator>
    </process>
    



    HTH!

    Cheers,
    YY
  • sgnarkhede2016
    sgnarkhede2016 New Altair Community Member
    THANKS