gchq / stroom

Stroom is a highly scalable data storage, processing and analysis platform.
https://gchq.github.io/stroom-docs/
Apache License 2.0
424 stars 58 forks source link

Snippets for Parser #4108

Closed stroomdev10 closed 4 months ago

stroomdev10 commented 4 months ago

I'd like the dataSplitter elements to be available as snippets

maybe we could also have a basic CSV and multiline parser as a template

at055612 commented 4 months ago
exports.snippets = [

    {
        "tabTrigger": "csv",
        "name": "CSV Splitter",
        "content": `
<?xml version="1.0" encoding="UTF-8"?>
<dataSplitter
    xmlns="data-splitter:3"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="data-splitter:3 file://data-splitter-v3.0.xsd"
    version="3.0">
  <!-- Match each line using a new line character as the delimiter -->
  <split delimiter="\\n">
    <!-- Take the matched line (using group 1 ignores the delimiters, 
    without this each match would include the new line character) -->
    <group value="\\$1">
    <!-- Match each value separated by a comma as the delimiter -->
    <split delimiter=",">
      <!-- Output the value from group 1 (as above using group 1
        ignores the delimiters, without this each value would include
      the comma) -->
      <data value="\\$1"/>
      \${0}
    </split>
    </group>
  </split>
</dataSplitter>
`.trim()
    },

    {
        "tabTrigger": "csvh",
        "name": "CSV Splitter with heading",
        "content": `
<?xml version="1.0" encoding="UTF-8"?>
<dataSplitter
    xmlns="data-splitter:3"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="data-splitter:3 file://data-splitter-v3.0.xsd"
    version="3.0">

  <!-- Match heading line (note that maxMatch="1" means that only the
  first line will be matched by this splitter) -->
  <split delimiter="\\n" maxMatch="1">

    <!-- Store each heading in a named list -->
    <group>
      <split delimiter="\,">
        <var id="heading" />
      </split>
    </group>
  </split>

  <!-- Match each record -->
  <split delimiter="\\n">

    <!-- Take the matched line -->
    <group value="\\$1">

      <!-- Split the line up -->
      <split delimiter=",">

        <!-- Output the stored heading for each iteration and the value
        from group 1 -->
        <data name="\\$heading\\$1" value="\\$1" />
      </split>
    </group>
  </split>
</dataSplitter>
`.trim()
    },

    {
        "tabTrigger": "datasplit",
        "name": "Data Splitter Template",
        "content": `
<?xml version="1.0" encoding="UTF-8"?>
<dataSplitter
    xmlns="data-splitter:3"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="data-splitter:3 file://data-splitter-v3.0.xsd"
    version="3.0">
    \${0}
</dataSplitter>
`.trim()
    },      

    {
        "tabTrigger": "data",
        "name": "DS3 data element with name attribute",
        "content": `
<data name="\$1" value="\$2"/>
`.trim()
    }, 

    {
        "tabTrigger": "datavalue",
        "name": "DS3 aata element without name attribute",
        "content": `
<data value="\$1"/>
`.trim()
    },

    {
        "tabTrigger": "var",
        "name": "DS3 var element",
        "content": `
<var id="\$1"/>
`.trim()
    },

    {
        "tabTrigger": "split",
        "name": "DS3 split element",
        "content": `
<split delimiter="\${1:\\n}">
    <group value="$1">
        \${2}
   </group>
</split>
`.trim()
    },

    {
        "tabTrigger": "group",
        "name": "DS3 group element",
        "content": `
<group value="$1">
    \${0}
 </group>
`.trim()
    },

    {
        "tabTrigger": "all",
        "name": "DS3 all element",
        "content": `
<all>
    \${0}
 </all>
`.trim()
    },

];
at055612 commented 4 months ago

fixed in > 7.3-beta.8