Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

PutCassandraRecord failed to convert into a Record object with the given schema

Highlighted

PutCassandraRecord failed to convert into a Record object with the given schema

New Contributor

I have an incoming JSON flowfile going towards an ExecuteScript processor that looks like

{
"fields": { "app_name": "MICROSOFT PHOTOS", "_time": "2019-02-02T08:00:35.473" } 
} 

My ExecuteScript looks like:

text = IOUtils.toString(inputStream, StandardCharsets.UTF_8)
obj = json.loads(text)
fields = obj['fields']
simpleTime = fields['_time']
del fields['_time']
strippedTime = simpleTime.replace('T', " ")
ts = datetime.strptime(strippedTime, '%Y-%m-%d %H:%M:%S.%f')
fields['ts'] = ts
out = json.dumps(fields, indent = 4, sort_keys = True, default = str)
outputStream.write(out)

The ExecuteScript then flows to a PutCassandraRecord with an Avro schema like:

{ "name": "app.records", "type": "record", "fields":[ {"name": "ts", "type": {"type": "long", "logicalType": "timestamp-millies"}}, {"name": "app_name", "type": "string"}

I am getting an error:

Unable to write the records into Cassandra table due to org.apache.nifi.serialization.MalformedRecordException: Successfully parsed a Json object from input but failed to convert into a Record object with the given schema:
...
Caused by: java.lang.NumberFormatException: For input string: "2019-02-02 08:00:35.473"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:589)
at java.lang.Long.parseLong(Long.java:631)
at org.apache.nifi.serialization.record.util.DataTypeUtils.toTimestamp(DataTypeUtils.java:1057)

Any help would be appreciated.