maoling commented on a change in pull request #1121: HBASE-20623: [WIP]Introduce the helper method "getCellBuilder()" to Mutation URL: https://github.com/apache/hbase/pull/1121#discussion_r375085410
########## File path: src/main/asciidoc/_chapters/datamodel.adoc ########## @@ -471,6 +471,26 @@ Caution: the version timestamp is used internally by HBase for things like time- It's usually best to avoid setting this timestamp yourself. Prefer using a separate timestamp attribute of the row, or have the timestamp as a part of the row key, or both. +===== Cell Version Example + +The following Put uses a method getCellBuilder() to get a CellBuilder instance +that already has relevant Type and Row set. + +[source,java] +---- + +public static final byte[] CF = "cf".getBytes(); +public static final byte[] ATTR = "attr".getBytes(); +... + +Put put = new Put(Bytes.toBytes(row)); +put.add(put.getCellBuilder().setQualifier(ATTR) + .setFamily(CF) + .setValue(Bytes.toBytes(data)) + .build()); Review comment: @saintstack Thanks for your review. - Yes, `put.addColumn()` can have the same effect. - this design was discussed in this [email thread](https://lists.apache.org/thread.html/d05bfaa0134502a47f6e1aca56cb0b096d4dd32ddefbbdf28db4952a@%3Cdev.hbase.apache.org%3E) which had a user case provided by Sean Busbey. AFAIU, it wants to simplify the `put.add(cell)` api, because sometimes when users use this cell api: ``` CellBuilder cb = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY); cb.setRow(Bytes.toBytes("row3")); cb.setFamily(Bytes.toBytes("cf")); cb.setQualifier("qualifier1".getBytes()); cb.setValue(Bytes.toBytes("mjj2")); cb.setType(Type.Put); Cell cell = cb.build(); Put p = new Put(Bytes.toBytes("row3")); p.add(cell); ``` `cb.setType(Type.Put)` is a little redundant and `getCellBuilder()` can help users to reuse the row, even Family and Qualifier they set last time to make the code short and clean. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services