nifi-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prabhu Mahendran <>
Subject How to update line with modified data in Jython?
Date Mon, 19 Jun 2017 12:31:45 GMT
I'm having one csv which contains lakhs of rows and below is sample lines..,

1,Ni,23,28-02-2015 12:22:33.2212-02
2,Fi,21,29-02-2015 12:22:34.3212-02
3,Us,33,30-03-2015 12:23:35-01
4,Uk,34,31-03-2015 12:24:36.332211-02
I need to get the last column of csv data which is in wrong datetime
format. So I need to get default datetimeformat("YYYY-MM-DD
hh:mm:ss[.nnn]") from last column of the data.

I have tried the following script to get lines from it and write into flow

import json
from import IOUtils
from java.nio.charset import StandardCharsets
from import StreamCallback

class PyStreamCallback(StreamCallback):
  def __init__(self):
  def process(self, inputStream, outputStream):
    text = IOUtils.readLines(inputStream, StandardCharsets.UTF_8)
    for line in text[1:]:
        outputStream.write(line + "\n")

flowFile = session.get()
if (flowFile != None):
  flowFile = session.write(flowFile,PyStreamCallback())
  flowFile = session.putAttribute(flowFile, "filename",
  session.transfer(flowFile, REL_SUCCESS)
but I am not able to find a way to convert it like below output.

1,Ni,23,28-02-2015 12:22:33.221
2,Fi,21,29-02-2015 12:22:34.321
3,Us,33,30-03-2015 12:23:35
4,Uk,34,31-03-2015 12:24:36.332
I have checked those requirement with my friend(google) and still not able
to find solution.

Can anyone guide me to convert those input data into my required output?

View raw message