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.

How can I insert a date in Cassandra from NiFi?

How can I insert a date in Cassandra from NiFi?

New Contributor

Hi,


I have a Cassandra table where one of its fields is "register_date", which is a date type field. I'm facing several problems to insert this date in Cassandra from NiFi. I'm using UpdateAttribute processor to generate the field, with this content:

${now():format("yyyyMMdd")}

When the flow file arrives to PutCassandraRecord processor I get the following error: "Expected 4 byte long for date".


What am I doing wrong? Thanks for your help :)

5 REPLIES 5

Re: How can I insert a date in Cassandra from NiFi?

You'll want to convert now() into a number for use by PutCassandraRecord, try ${now():toNumber()} instead.

Highlighted

Re: How can I insert a date in Cassandra from NiFi?

New Contributor

Hi @Matt Burgess. Thanks for your response, but it is still failing :(. My three blocks are: UpdateAttribute, to give to register_date the value you have indicate, AttributestoJSON and, at last, PutCassandraRecord.

Am I doing anything wrong?


Thanks for your attention.

Re: How can I insert a date in Cassandra from NiFi?

Once the value is in an attribute, it loses its type information as all attribute values are treated as strings. So when you use AttributesToJSON, you'll get a string value of the timestamp, not the long value.


Instead, try UpdateRecord, you can set/generate the field using a ReplacementValueStrategy of "Literal Value", where you can use NiFi Expression Language such as ${now():toNumber()}. Just make sure that the field is in the output schema as a long.

Re: How can I insert a date in Cassandra from NiFi?

New Contributor

Hi @Matt Burgess, I have deleted the "AttributeToJSON" processor I indicated you and now PutCassandraRecord processor doesn't return any error, so this problem has disappeared. Without it, anyway, and setting only this structure:

108159-1556127260627.png

In AttributesToJson I take the field register_date (which is null until that date), because this is the only field I want to put in the database. Then, with UpdateAttribute, I configure register_date as ${now():toNumber()} . At last, I use PutCassandraRecord. I'm obtaining in my database the following record: -294294420. What does this number mean? What if I want to obtain the date in a format of "yyyy-MM-dd", which is the format I was expecting to see?


However, I do not understand very well the solution you are proposing (English is not my first language so it will possibly has something to do with that). Which is the structure you are proposing me, and how could I configure the UpdateRecord Processor, to achieve the objective that I have proposed in the previous paragraph?


Many thanks for your help.


captura-de-pantalla-2019-04-24-a-las-193354.png1556127258391.png

Re: How can I insert a date in Cassandra from NiFi?

New Contributor

The error I'm obtaining now is "Expected 4 byte long for date (13)".

Don't have an account?
Coming from Hortonworks? Activate your account here