You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2020/12/02 09:43:51 UTC

[GitHub] [hbase] anoopsjohn commented on a change in pull request #2707: [HBASE-25328] Add builder method to create Tags.

anoopsjohn commented on a change in pull request #2707:
URL: https://github.com/apache/hbase/pull/2707#discussion_r534006501



##########
File path: hbase-common/src/main/java/org/apache/hadoop/hbase/RawCell.java
##########
@@ -64,4 +65,19 @@ public static void checkForTagsLength(int tagsLength) {
       throw new IllegalArgumentException("tagslength " + tagsLength + " > " + MAX_TAGS_LENGTH);
     }
   }
+
+  /**
+   * @return A new cell which is having the extra tags also added to it.
+   */
+  public static Cell createCell(Cell cell, List<Tag> tags) {
+    return PrivateCellUtil.createCell(cell, tags);
+  }
+
+  /**
+   * @param cell The Cell
+   * @return Tags in the given Cell as a List
+   */
+  public static List<Tag> getTags(Cell cell) {

Review comment:
       We already have Iterator<Tag> getTags() here right?  Thats good enough?

##########
File path: hbase-common/src/main/java/org/apache/hadoop/hbase/ByteBufferTag.java
##########
@@ -44,6 +44,21 @@ public ByteBufferTag(ByteBuffer buffer, int offset, int length) {
     this.type = ByteBufferUtils.toByte(buffer, offset + TAG_LENGTH_SIZE);
   }
 
+  /**
+   * This constructor <b>just contains the tag value</b> in ByteBuffer. In above constructor,
+   * tag length and tag type are also contained in the ByteBuffer.
+   * @param buffer input byte buffer
+   * @param type  type of the tag
+   * @param offset offset of the start of tag in byte buffer
+   * @param length length of the tag
+   */
+  public ByteBufferTag(ByteBuffer buffer, byte type, int offset, int length) {

Review comment:
       So here Tag value is in the BB at given offset -> length.
   Suggest rearrange the params order so that BB, offset and length are together.
   May be byte type, BB value, int offset, int length) will be better
   Also pls name BB param as value  than plain buffer.

##########
File path: hbase-common/src/main/java/org/apache/hadoop/hbase/TagBuilderFactory.java
##########
@@ -0,0 +1,105 @@
+/**
+ * Copyright The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase;
+
+import java.nio.ByteBuffer;
+import org.apache.yetus.audience.InterfaceAudience;
+
+/**
+ * Factory to create Tags.
+ */
+@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
+public final class TagBuilderFactory {
+
+  public static TagBuilder create(TagBuilderType type) {
+    switch (type) {
+      case ARRAY_BACKED:
+        return new ArrayTagBuilderImpl();
+      case BYTE_BUFFER_BACKED:
+        return new ByteBufferTagBuilderImpl();
+      default:
+        throw new UnsupportedOperationException("The type:" + type + " is unsupported");
+    }
+  }
+}
+
+/**
+ * Builder implementation to create {@link ArrayBackedTag}
+ */
+class ArrayTagBuilderImpl implements TagBuilder {
+  private byte[] tagBytes;
+  private byte tagType;
+
+  @Override
+  public TagBuilder setTagType(byte tagType) {
+    this.tagType = tagType;
+    return this;
+  }
+
+  @Override
+  public TagBuilder setTagValue(byte[] tagBytes) {
+    this.tagBytes = tagBytes;
+    return this;
+  }
+
+  @Override
+  public TagBuilder setTagByteBuffer(ByteBuffer byteBuffer) {

Review comment:
       ya this one I was expecting.
   What i suggest is lets have only one builder impl. It will never ask for any builder type.  It can accept both byte[] or BB.  Based on what was being latest set, create corresponding Tag impl Object

##########
File path: hbase-common/src/main/java/org/apache/hadoop/hbase/TagBuilder.java
##########
@@ -0,0 +1,59 @@
+/**
+ * Copyright The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase;
+
+import java.nio.ByteBuffer;
+import org.apache.yetus.audience.InterfaceAudience;
+
+/**
+ * Builder method to create {@link Tag}.
+ */
+@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
+public interface TagBuilder {
+  /**
+   * Set type of the tag.
+   * @param tagType type of the tag
+   * @return {@link TagBuilder}
+   */
+  TagBuilder setTagType(byte tagType);
+
+  /**
+   * For {@link ArrayBackedTag}, set the value of the tag.
+   * This method throws {@link UnsupportedOperationException}
+   * if the tag is backed by {@link ByteBuffer}
+   * @param tagBytes tag bytes.
+   * @return {@link TagBuilder}
+   */
+  TagBuilder setTagValue(byte[] tagBytes);

Review comment:
       When create a new Tag (Not reading HFile data and creating back Tag POJO), actually it does not matter much whether we pass value as byte[] or BB.  Infact as a user I would have created array backed value and so array backed tag only.
   We can give both options anyways in Builder. But we can have it as overloaded method? 
   setTagValue (or setValue is enough as we are anyways in tagBuilder)
   setTagValue(byte[])
   setTagValue(BB)
   In impl the latest set one will anyways be used.

##########
File path: hbase-common/src/main/java/org/apache/hadoop/hbase/TagBuilderFactory.java
##########
@@ -0,0 +1,105 @@
+/**
+ * Copyright The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase;
+
+import java.nio.ByteBuffer;
+import org.apache.yetus.audience.InterfaceAudience;
+
+/**
+ * Factory to create Tags.
+ */
+@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
+public final class TagBuilderFactory {
+
+  public static TagBuilder create(TagBuilderType type) {
+    switch (type) {

Review comment:
       I suggest we dont have to complicate this.
   TagBuilder can build ArrayBackedTag or BB backed tag based on whether value is byte[]/BB right? No need for the client code to explicitly tell what to be built. Or else I believe we will have validation like on ArrayBacked builder one should set only value in byte[]




----------------------------------------------------------------
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:
users@infra.apache.org