Vyshali,

Please also consider looking at your splitlines call. Splitlines is defined in 
python's script class, but not in Java. This is Jython, so IOUtils.toString 
returns a Java string, not a Python string, and that string splits in a 
different way.

Regards,

Andy
________________________________________
From: Andy Christianson <[email protected]>
Sent: Thursday, November 2, 2017 1:40 PM
To: [email protected]
Subject: Re: Issue with Executescript

Vyshali,

These types of issues can be difficult to diagnose in a running NiFi instance. 
Once your script reaches beyond a certain threshold, I recommend creating unit 
tests for your script and mocking the NiFi interfaces. MattyB's script tester 
[1] may help you with this task as well as general script testing.

My initial eyeball of your code tells me there's something up with your 
putattribute.

On a final note, if you're not familiar with Python, are there any other 
languages you are more familiar with? ExecuteScript allows you to use almost 
any language you could think of, so if you are more comfortable with another 
supported language, I recommend porting to that. Between using a language 
your'e more comfortable with, and using MattyB's script tester, I'm confident 
we should be able to resolve the issue.

Regards,

Andy

P.S. I would consider this more of a user question than a developer question, 
so next time please email [email protected] rather than the dev list.

[1]: 
http://funnifi.blogspot.com/2017/10/release-120-of-nifi-script-tester.html?m=1
________________________________________
From: Vyshali <[email protected]>
Sent: Thursday, November 2, 2017 1:31 PM
To: [email protected]
Subject: Issue with Executescript

Hi,

I'm using the executescript process to generate some fake data using "Faker"
package and replacing it in the original data.I have attached the script for
your reference.

import java.io
from org.apache.commons.io import IOUtils
from java.nio.charset import StandardCharsets
from org.apache.nifi.processor.io import StreamCallback
import unicodecsv as csv
from faker import Factory
from collections import defaultdict

class TransformCallback(StreamCallback):
    def _init_(self):
        pass

    def process(self,inputStream,outputStream):
        text = IOUtils.toString(inputStream,StandardCharsets.ISO_8859_1)
        faker  = Factory.create()            //generating fake data
        names  = defaultdict(faker.name)
        emails = defaultdict(faker.email)
        ssns = defaultdict(faker.ssn)
        phone_numbers = defaultdict(faker.phone_number)

        for row in text.splitlines():
            row["name"]  = names[row["name"]]     //Assigning the fake data
            row["email"] = emails[row["email"]]
            row["ssn"] = ssns[row["ssn"]]
            row["phone_number"] = phone_numbers[row["phone_number"]]
            flowFile = session.putAttribute(flowFile,"name",row["name"])

        outputStream.write(text.encode('UTF8'))


flowFile = session.get()
if flowFile != None:
    flowFile = session.write(flowFile,TransformCallback())
    session.transfer(flowFile, REL_SUCCESS)
    session.commit()

But I'm unable to execute it successfully.I'm getting the following error
"ProcessException:TypeError:None required"

I'm not much familiar to python.Please give me suggestions on how can I
solve this.Correct me in case my coding is also not appropriate.

Regards,
Vyshali




--
Sent from: http://apache-nifi-developer-list.39713.n7.nabble.com/





Reply via email to