You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@nifi.apache.org by Hong Li <ho...@centricconsulting.com> on 2016/03/22 00:54:06 UTC
Create row keys for HBase from Json messages
I'm a new user for Nifi, and just started my first Nifi project, where we
need to move Json messages into HBase. After I read the templates and user
guide, I see I still need help to learn how to concatenate the values
pulled out from the Json messages to form a unique row key for HBase tables.
Given the sample message below, I run into errors where I need to create
the unique keys for HBase by concatenating values pulled from the messages.
{
"effectiveTimestamp": "2015-12-03T23:17:29.874Z",
"event": {
"@class": "events.policy.PolicyCreated",
"id": "1e9b91398160471f8b6197ad974e2464",
"ipAddress": "10.8.30.145",
"policy": {
"additionalListedInsureds": [],
"address": {
"city": "Skokie",
"county": "Cook",
"id": "b863190a5bf846858eb372fb5f532fe7",
"latitude": 42.0101,
"longitude": -87.75354,
"state": "IL",
"street": "5014 Estes Ave",
"zip": "60077-3520"
},
"applicant": {
"age": 36,
"birthDate": "1979-01-12",
"clientId": "191",
"creditReport": {
"id": "ca5ec932d33d444b880c9a43a6eb7c50",
"reasons": [],
"referenceNumber": "15317191300474",
"status": "NoHit"
},
"firstName": "Kathy",
"gender": "Female",
"id": "1f4a3862fab54e058305e3c73cc13dd3",
"lastName": "Bockett",
"maritalStatus": "Single",
"middleName": "Sue",
"ssn": "*******"
},
"channelOfOrigin": "PublicWebsite",
... ...
For example, in processor EvaluateJsonPath, I could pull out individual
values as shown below:
$.effectiveTimestamp
$.event.id
$.event.applicant.id
However, when I tried to create the HBase row key there such as
${allAttributes($.event.id,
$event.applicant.id):join($.effectiveTimestamp:toDate('MMM
d HH:mm:ss'):toString()}_${uuid}
I could not make it work no matter how I modified or simplified the long
string. I must have misunderstood something here. I don't know if this
question has already been asked and answered.
Thank you for your help.
Hong
*Hong Li*
*Centric Consulting*
*In Balance*
(888) 781-7567 office
(614) 296-7644 mobile
www.centricconsulting.com | @Centric <https://twitter.com/centric>
Re: Create row keys for HBase from Json messages
Posted by Hong Li <ho...@centricconsulting.com>.
Hi Bryan,
Thank you very much for tips. I tested during the day. They are working
now.
Hong
*Hong Li*
*Centric Consulting*
*In Balance*
(888) 781-7567 office
(614) 296-7644 mobile
www.centricconsulting.com | @Centric <https://twitter.com/centric>
On Mon, Mar 21, 2016 at 8:33 PM, Bryan Bende <bb...@gmail.com> wrote:
> Hong,
>
> Glad to hear you are getting started with NiFi! What do your property
> names look like on EvaluatJsonPath?
>
> Typically if you wanted to extract the effective timestamp, event id, and
> applicant id from your example json, then you would add properties to
> EvaluateJsonPath like the following:
>
> effectiveTimestamp = $.effectiveTimestamp
> eventId = $.event.id
> eventApplicantId = $.event.applicant.id
>
> Then in PutHBaseJson if you want the Row Id to be the event id, followed
> by applicant id, followed by timestamp, you could do:
>
> ${eventId}_${eventApplicantId}_${effectiveTimestamp}
>
> The above expression with your sample JSON should give you:
>
> 1e9b91398160471f8b6197ad974e2464_1f4a3862fab54e058305e3c73cc13dd3_
> 2015-12-03T23:17:29.874Z
>
> Now if you wanted to timestamp to be the long representation instead of
> the date string, you could do:
>
> ${eventId}_${eventApplicantId}_${effectiveTimestamp:
> toDate("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"):toNumber()}
>
> Let us know if this helps.
>
> -Bryan
>
>
> On Mon, Mar 21, 2016 at 7:54 PM, Hong Li <ho...@centricconsulting.com>
> wrote:
>
>> I'm a new user for Nifi, and just started my first Nifi project, where we
>> need to move Json messages into HBase. After I read the templates and user
>> guide, I see I still need help to learn how to concatenate the values
>> pulled out from the Json messages to form a unique row key for HBase tables.
>>
>> Given the sample message below, I run into errors where I need to create
>> the unique keys for HBase by concatenating values pulled from the messages.
>>
>> {
>> "effectiveTimestamp": "2015-12-03T23:17:29.874Z",
>> "event": {
>> "@class": "events.policy.PolicyCreated",
>> "id": "1e9b91398160471f8b6197ad974e2464",
>> "ipAddress": "10.8.30.145",
>> "policy": {
>> "additionalListedInsureds": [],
>> "address": {
>> "city": "Skokie",
>> "county": "Cook",
>> "id": "b863190a5bf846858eb372fb5f532fe7",
>> "latitude": 42.0101,
>> "longitude": -87.75354,
>> "state": "IL",
>> "street": "5014 Estes Ave",
>> "zip": "60077-3520"
>> },
>> "applicant": {
>> "age": 36,
>> "birthDate": "1979-01-12",
>> "clientId": "191",
>> "creditReport": {
>> "id": "ca5ec932d33d444b880c9a43a6eb7c50",
>> "reasons": [],
>> "referenceNumber": "15317191300474",
>> "status": "NoHit"
>> },
>> "firstName": "Kathy",
>> "gender": "Female",
>> "id": "1f4a3862fab54e058305e3c73cc13dd3",
>> "lastName": "Bockett",
>> "maritalStatus": "Single",
>> "middleName": "Sue",
>> "ssn": "*******"
>> },
>> "channelOfOrigin": "PublicWebsite",
>> ... ...
>>
>> For example, in processor EvaluateJsonPath, I could pull out individual
>> values as shown below:
>>
>> $.effectiveTimestamp
>> $.event.id
>> $.event.applicant.id
>>
>>
>> However, when I tried to create the HBase row key there such as
>>
>> ${allAttributes($.event.id, $event.applicant.id):join($.effectiveTimestamp:toDate('MMM
>> d HH:mm:ss'):toString()}_${uuid}
>>
>>
>> I could not make it work no matter how I modified or simplified the long
>> string. I must have misunderstood something here. I don't know if this
>> question has already been asked and answered.
>>
>> Thank you for your help.
>> Hong
>>
>>
>> *Hong Li*
>>
>> *Centric Consulting*
>>
>> *In Balance*
>> (888) 781-7567 office
>> (614) 296-7644 mobile
>> www.centricconsulting.com | @Centric <https://twitter.com/centric>
>>
>
>
Re: Create row keys for HBase from Json messages
Posted by Bryan Bende <bb...@gmail.com>.
Hong,
Glad to hear you are getting started with NiFi! What do your property names
look like on EvaluatJsonPath?
Typically if you wanted to extract the effective timestamp, event id, and
applicant id from your example json, then you would add properties to
EvaluateJsonPath like the following:
effectiveTimestamp = $.effectiveTimestamp
eventId = $.event.id
eventApplicantId = $.event.applicant.id
Then in PutHBaseJson if you want the Row Id to be the event id, followed by
applicant id, followed by timestamp, you could do:
${eventId}_${eventApplicantId}_${effectiveTimestamp}
The above expression with your sample JSON should give you:
1e9b91398160471f8b6197ad974e2464_1f4a3862fab54e058305e3c73cc13dd3_
2015-12-03T23:17:29.874Z
Now if you wanted to timestamp to be the long representation instead of the
date string, you could do:
${eventId}_${eventApplicantId}_${effectiveTimestamp:
toDate("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"):toNumber()}
Let us know if this helps.
-Bryan
On Mon, Mar 21, 2016 at 7:54 PM, Hong Li <ho...@centricconsulting.com>
wrote:
> I'm a new user for Nifi, and just started my first Nifi project, where we
> need to move Json messages into HBase. After I read the templates and user
> guide, I see I still need help to learn how to concatenate the values
> pulled out from the Json messages to form a unique row key for HBase tables.
>
> Given the sample message below, I run into errors where I need to create
> the unique keys for HBase by concatenating values pulled from the messages.
>
> {
> "effectiveTimestamp": "2015-12-03T23:17:29.874Z",
> "event": {
> "@class": "events.policy.PolicyCreated",
> "id": "1e9b91398160471f8b6197ad974e2464",
> "ipAddress": "10.8.30.145",
> "policy": {
> "additionalListedInsureds": [],
> "address": {
> "city": "Skokie",
> "county": "Cook",
> "id": "b863190a5bf846858eb372fb5f532fe7",
> "latitude": 42.0101,
> "longitude": -87.75354,
> "state": "IL",
> "street": "5014 Estes Ave",
> "zip": "60077-3520"
> },
> "applicant": {
> "age": 36,
> "birthDate": "1979-01-12",
> "clientId": "191",
> "creditReport": {
> "id": "ca5ec932d33d444b880c9a43a6eb7c50",
> "reasons": [],
> "referenceNumber": "15317191300474",
> "status": "NoHit"
> },
> "firstName": "Kathy",
> "gender": "Female",
> "id": "1f4a3862fab54e058305e3c73cc13dd3",
> "lastName": "Bockett",
> "maritalStatus": "Single",
> "middleName": "Sue",
> "ssn": "*******"
> },
> "channelOfOrigin": "PublicWebsite",
> ... ...
>
> For example, in processor EvaluateJsonPath, I could pull out individual
> values as shown below:
>
> $.effectiveTimestamp
> $.event.id
> $.event.applicant.id
>
>
> However, when I tried to create the HBase row key there such as
>
> ${allAttributes($.event.id, $event.applicant.id):join($.effectiveTimestamp:toDate('MMM
> d HH:mm:ss'):toString()}_${uuid}
>
>
> I could not make it work no matter how I modified or simplified the long
> string. I must have misunderstood something here. I don't know if this
> question has already been asked and answered.
>
> Thank you for your help.
> Hong
>
>
> *Hong Li*
>
> *Centric Consulting*
>
> *In Balance*
> (888) 781-7567 office
> (614) 296-7644 mobile
> www.centricconsulting.com | @Centric <https://twitter.com/centric>
>