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


Reply via email to