Prepending collection keys to attribute names in metadata

You can use a graph to prepend collection keys to attribute names in the metadata.

To prepend collection keys to attribute names in a graph:

  1. Create a new graph.

    You can create the new graph anywhere in your Integrator ETL workspace, as you may want to re-use it. You do not have to create it in a specific project.

  2. On the Source tab of the graph, replace the <Global> with the following <Global> node code:
    <Global>
    <Metadata id="Metadata0" previewAttachmentCharset="ISO-8859-1">
    <Record fieldDelimiter="|" name="row" previewAttachmentCharset="ISO-8859-1" recordDelimiter="\n" type="delimited">
    <Field delimiter="\r" name="row" type="string"/>
    </Record>
    </Metadata>
    <Property fileURL="workspace.prm" id="GraphParameter0"/>
    <Note alignment="1" backgroundColorB="225" backgroundColorG="255" backgroundColorR="255" folded="false" height="177" id="Note0" textColorB="0" textColorG="0" textColorR="0" textFontSize="8" title="Description" titleColorB="0" titleColorG="0" titleColorR="0" titleFontSize="10" width="824" x="20" y="56">
    <attr name="text"><![CDATA[This graph reads metadata from a single external source.  It adds a prefix and rewrites the metadata to a new .fmt]]></attr>
    </Note>
    <Dictionary/>
    </Global>
    <Phase number="0">
    <Node enabled="enabled" fileURL="${META_DIR}/no_prefix.fmt" guiHeight="87" guiName="DATA_READER0" guiWidth="128" guiX="30" guiY="126" id="DATA_READER0" type="DATA_READER"/>
    <Node enabled="enabled" guiHeight="65" guiName="Filter Header" guiWidth="128" guiX="255" guiY="126" id="EXT_FILTER0" type="EXT_FILTER">
    <attr name="filterExpression"><![CDATA[$0.row ~= "<Field.*>"]]></attr>
    </Node>
    <Node enabled="enabled" guiHeight="65" guiName="Prefix" guiWidth="128" guiX="480" guiY="126" id="REFORMAT0" type="REFORMAT">
    <attr name="transform"><![CDATA[//#CTL2
     
    // Transforms input record into output record.
    function integer transform() {
        $out.0.row = replace($0.row,"name=\"","name=\"Vehicle_");
     
        return ALL;
    }
    ]]></attr>
    </Node>
    <Node enabled="enabled" fileURL="${META_DIR}/prefix_after.fmt" footer="&lt;/Record&gt;" guiHeight="87" guiName="Create Metadata" guiWidth="128" guiX="705" guiY="126" header="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;Record fieldDelimiter=&quot;|&quot; name=&quot;ProductCategory&quot; previewAttachmentCharset=&quot;ISO-8859-1&quot; recordDelimiter=&quot;\\r\\n&quot; type=&quot;delimited&quot;&gt;&#10;" id="STRUCTURE_WRITER0" mask="$row \n" type="STRUCTURE_WRITER"/>
    <Edge debugMode="true" fromNode="DATA_READER0:0" guiBendpoints="" guiRouter="Manhattan" id="Edge1" inPort="Port 0 (in)" metadata="Metadata0" outPort="Port 0 (output)" toNode="EXT_FILTER0:0"/>
    <Edge debugMode="true" fromNode="EXT_FILTER0:0" guiBendpoints="" guiRouter="Manhattan" id="Edge3" inPort="Port 0 (in)" metadata="Metadata0" outPort="Port 0 (accepted)" toNode="REFORMAT0:0"/>
    <Edge debugMode="true" fromNode="REFORMAT0:0" guiBendpoints="" guiRouter="Manhattan" id="Edge5" inPort="Port 0 (Body port)" metadata="Metadata0" outPort="Port 0 (out)" toNode="STRUCTURE_WRITER0:0"/>
    </Phase>
  3. Save the graph.
  4. Edit the Date Reader0 data reader component. In the File URL property, specify the path to the metadata file with the attribute names to which you want to prepend the collection key.
    If the metadata is in a different project that than the prepend graph, be sure you specify the fully-qualified path to the metadata file.
    Note: You may want to give this metadata file a name that indicates that the collection key is not prepended to the attribute names..
  5. Edit the Prefix Reformat component. In the Transform property, modify the following line:$out.0.row = replace($0.row,"name=\"","name=\"Vehicle_");. Replace Vehicle_ with the collection key of the collection in the graph for which you are creating the metadata.
    For example, if the collection key is "Insurance", the updated code would be $out.0.row = replace($0.row,"name=\"","name=\"Insurance_");
  6. Edit the Create Metadata structure writer component. In the File URL property, specify the path and name of the new metadata file you want to create.
    In the metadata is in a different project that the prepend graph, be sure you specify the fully-qualified path to the metadata file.
    Note: You may want to give this metadata file a name that indicates that the collection key has been prepended to the attribute names.
  7. Save your changes.
  8. Run the graph.

A new metadata is created with the name you specified. In the metadata, the collection key you specified is appended to the attribute names.

You can re-use this graph to create additional metadata. For each new metadata you want to create, repeat Steps 3 through 8.