vanus-labs / vanus

Vanus is a Serverless, event streaming system with processing capabilities. It easily connects SaaS, Cloud Services, and Databases to help users build next-gen Event-driven Applications.

Home Page:https://vanus.ai

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Good First Issues]: implement function "extract_pattern" - 7 points

Michaelg22 opened this issue · comments

commented

Motivation

Vanus Functions are a series of pre-built functions worked within Vanus transformer. By choosing a function, users can specify the way that events will be changed.

It will be a good start if you decide to contribute to Vanus codes.

Details

The function is used to get value from the source JSON path, which matches the regular expression. Then assign the value to the target JSON path.

args

  • sourceJsonPath – The name of an existing path.
  • targetJsonPath – The name of the new path to be created.
  • pattern – A regular expression that indicates which character or characters to extract and create the new path from.

..

Description

Function name: extract_pattern

If the pattern is "a.*?c" the function will search for all elements that start with the letter 'a' and end with the letter 'c'.

Example

{
    "specversion" : "1.0",
    "type" : "com.example.someevent",
    "source" : "/mycontext",
    "subject": null,
    "id" : "C234-1234-1234",
    "time" : "2018-04-05T17:31:00Z",
    "comexampleextension1" : "value",
    "comexampleothervalue" : 5,
    "datacontenttype" : "application/json",
    "data" : {
        "appinfoA": "abcdadc",
        "appinfoB": "efgs",

    }
}

After the function "extract_pattern":

"pipeline":[
    {"command":["extract_pattern","$.data.appinfoA", "$.data.appinfoC", "a.*?c"]}
]

The transformed event should look like this:

{
    "specversion" : "1.0",
    "type" : "com.example.someevent",
    "source" : "/mycontext",
    "subject": null,
    "id" : "C234-1234-1234",
    "time" : "2018-04-05T17:31:00Z",
    "comexampleextension1" : "value",
    "comexampleothervalue" : 5,
    "datacontenttype" : "application/json",
    "data" : {
        "appinfoA": "abcdadc",
        "appinfoB": "efgs",
        "appinfoC": ["abc", "adc"],
    }
}

How to implement

  1. Fork the vanus repository.
  2. Create a branch function-extract_pattern
  3. Create extract_pattern.go under internal/primitive/transform/action/strings, and then implement the function.
  4. Create extract_pattern_test.go under internal/primitive/transform/action/strings for unit test.
  5. Register your function in internal/primitive/transform/runtime/init.go.
  6. Submit your PR

Contribution points

Each issue counts specific points based on its difficulty. Contributors earn the corresponding points if they solve that issue. Contribution points are used to describe the contributions contributors have made. They can also be used to get rewards when there are community events.

This issue counts 7 points.

How to claim to solve the issue

If you want to implement this function, please leave a comment in this issue like:

I'd like to implement this function, please assign this issue to me.

Vanus community will assign the issue to you on time.

Please, I'd love to work on this

Hey, Kindly assign this issue to me. This seems easily solvable.

commented

Hi @shashank-mishra14 We would love to have you contribute to this issue. Please also join our community on slack.