2

I have a file which i get using the GetFile Processor.

The flowfile generated from this has an attribute (filename).

I want to split this "filename" attribute with value "ABC_gh_1245_ty.csv" by "_" into multiple attributes

ATTR1 = "ABC"
ATTR2 = "gh"
ATTR3 = "1245"
ATTR4 = "ty.csv"

I presume that there are no processors available for this functionality in nifi 1.7.1

I googled and found this custom processor: https://github.com/guvencenanguvenal/nifi-splitcreateattribute

It still doesnt work. It errors out with 'Attribuite dont found'

2 Answers 2

4

To solve this, you can leverage ExecuteScript or ExecuteGroovyScript processor. The following scrip would do the job just fine. It is written in Groovy though.

flowFile = session.get()

if (!flowFile)
    return

filename = flowFile.getAttribute('filename')
splits = filename.split('_')
attrsMap = [:]

splits.eachWithIndex {
    split, index -> attrsMap.put("ATTR" + index, split)
}

attrsMap.each{ k, v -> println "${k}:${v}" }
flowFile = session.putAllAttributes(flowFile, attrsMap)
session.transfer(flowFile, REL_SUCCESS)

Screenshots

enter image description here

enter image description here

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

The below processor works perfectly fine...

https://github.com/guvencenanguvenal/nifi-splitcreateattribute

Below is the config needed:

Split Attributes Name: ATTR1, ATTR2, ATTR3, ATTR4 Attribute Name Which Split: filename\ Split Separator (Regex): _

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.