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 to add a new attribute to a Column in HBase Table with jason data?

Highlighted

How to add a new attribute to a Column in HBase Table with jason data?

Expert Contributor

I have a HBase table that has data in Json format. I have a peculiar requirement where I need to add a new attribute to the existing one. Here is a column that I have queried from the HBase table

COLUMN                               CELL
 c:601                               timestamp=1, value={"value": "000000005295", "id": 601, "name": "ID", "type": "ATOMIC", "hash": "4
                                     998c929c977272828456cd83aa0fc19635e674a61a67c96e6ccd226d3296db7", "attrs": {"timestamp": "2016-11-30T0919
                                     27Z", "code": "805", "uuid": "c6d82240-87fd-469a-86a7-e8b1e5d1da4b", "source": "online", "appV
                                     ersion": "1.14.40.7", "cutoff": "1", "exportedAt": "20161020T144804Z"}, "globalAttrs": {"source": "online
                                     ", "timestamp": 1480497567000, "exportedAt": 1476974884000, "countryCode": 805, "appVersion": "1.14.4
                                     0.7", "uuid": "c6d82240-87fd-469a-86a7-e8b1e5d1da4b", "index": null, "itemId": null, "publish": true}}

For each column we have attributes denoted as attrs. Currently there are seven attributes and I want to add a new attribute called delete with value as yes.

After altering the column it should like the below one.

COLUMN                               CELL
 c:601                               timestamp=1, value={"value": "000000005295", "id": 601, "name": "ID", "type": "ATOMIC", "hash": "4
                                     998c929c977272828456cd83aa0fc19635e674a61a67c96e6ccd226d3296db7", "attrs": {"timestamp": "2016-11-30T0919
                                     27Z", "code": "805", "uuid": "c6d82240-87fd-469a-86a7-e8b1e5d1da4b", "source": "online", "appV
                                     ersion": "1.14.40.7", "cutoff": "1", "exportedAt": "20161020T144804Z", "delete" : "yes"}, "globalAttrs": {"source": "online
                                     ", "timestamp": 1480497567000, "exportedAt": 1476974884000, "countryCode": 805, "appVersion": "1.14.4  0.7", "uuid": "c6d82240-87fd-469a-86a7-e8b1e5d1da4b", "index": null, "itemId": null, "publish": true}}
2 REPLIES 2

Re: How to add a new attribute to a Column in HBase Table with jason data?

New Contributor

I think you should write a client that rewrites the json objects with the new attribute added. There is no JSON support in hbase see: https://community.hortonworks.com/questions/37655/json-support-to-hbase.html.

Re: How to add a new attribute to a Column in HBase Table with jason data?

Just to expand a little: you need to read the value, modify the JSON client side, and submit a new Put to the same coordinates (rowKey, colfam, colqual). That is by far the easiest way.

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