View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.mapreduce;
19  
20  import java.io.IOException;
21  import java.util.List;
22  
23  import org.apache.hadoop.hbase.classification.InterfaceAudience;
24  import org.apache.hadoop.hbase.classification.InterfaceStability;
25  import org.apache.hadoop.conf.Configuration;
26  import org.apache.hadoop.hbase.Cell;
27  import org.apache.hadoop.hbase.KeyValue;
28  import org.apache.hadoop.hbase.Tag;
29  import org.apache.hadoop.util.ReflectionUtils;
30  
31  /**
32   * Facade to create Cells for HFileOutputFormat. The created Cells are of <code>Put</code> type.
33   */
34  @InterfaceAudience.Public
35  @InterfaceStability.Evolving
36  public class CellCreator {
37  
38    @InterfaceStability.Unstable
39    public static final String VISIBILITY_EXP_RESOLVER_CLASS =
40        "hbase.mapreduce.visibility.expression.resolver.class";
41  
42    private VisibilityExpressionResolver visExpResolver;
43  
44    public CellCreator(Configuration conf) {
45      Class<? extends VisibilityExpressionResolver> clazz = conf.getClass(
46          VISIBILITY_EXP_RESOLVER_CLASS, DefaultVisibilityExpressionResolver.class,
47          VisibilityExpressionResolver.class);
48      this.visExpResolver = ReflectionUtils.newInstance(clazz, conf);
49      this.visExpResolver.init();
50    }
51  
52    /**
53     * @param row row key
54     * @param roffset row offset
55     * @param rlength row length
56     * @param family family name
57     * @param foffset family offset
58     * @param flength family length
59     * @param qualifier column qualifier
60     * @param qoffset qualifier offset
61     * @param qlength qualifier length
62     * @param timestamp version timestamp
63     * @param value column value
64     * @param voffset value offset
65     * @param vlength value length
66     * @return created Cell
67     * @throws IOException
68     */
69    public Cell create(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength,
70        byte[] qualifier, int qoffset, int qlength, long timestamp, byte[] value, int voffset,
71        int vlength) throws IOException {
72      return create(row, roffset, rlength, family, foffset, flength, qualifier, qoffset, qlength,
73          timestamp, value, voffset, vlength, (List<Tag>)null);
74    }
75  
76    /**
77     * @param row row key
78     * @param roffset row offset
79     * @param rlength row length
80     * @param family family name
81     * @param foffset family offset
82     * @param flength family length
83     * @param qualifier column qualifier
84     * @param qoffset qualifier offset
85     * @param qlength qualifier length
86     * @param timestamp version timestamp
87     * @param value column value
88     * @param voffset value offset
89     * @param vlength value length
90     * @param visExpression visibility expression to be associated with cell
91     * @return created Cell
92     * @throws IOException
93     */
94    @Deprecated
95    public Cell create(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength,
96        byte[] qualifier, int qoffset, int qlength, long timestamp, byte[] value, int voffset,
97        int vlength, String visExpression) throws IOException {
98      List<Tag> visTags = null;
99      if (visExpression != null) {
100       visTags = this.visExpResolver.createVisibilityExpTags(visExpression);
101     }
102     return new KeyValue(row, roffset, rlength, family, foffset, flength, qualifier, qoffset,
103         qlength, timestamp, KeyValue.Type.Put, value, voffset, vlength, visTags);
104   }
105 
106   /**
107    * @param row row key
108    * @param roffset row offset
109    * @param rlength row length
110    * @param family family name
111    * @param foffset family offset
112    * @param flength family length
113    * @param qualifier column qualifier
114    * @param qoffset qualifier offset
115    * @param qlength qualifier length
116    * @param timestamp version timestamp
117    * @param value column value
118    * @param voffset value offset
119    * @param vlength value length
120    * @param tags
121    * @return created Cell
122    * @throws IOException
123    */
124   public Cell create(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength,
125       byte[] qualifier, int qoffset, int qlength, long timestamp, byte[] value, int voffset,
126       int vlength, List<Tag> tags) throws IOException {
127     return new KeyValue(row, roffset, rlength, family, foffset, flength, qualifier, qoffset,
128         qlength, timestamp, KeyValue.Type.Put, value, voffset, vlength, tags);
129   }
130 
131   /**
132    * @return Visibility expression resolver
133    */
134   @InterfaceStability.Unstable
135   public VisibilityExpressionResolver getVisibilityExpressionResolver() {
136     return this.visExpResolver;
137   }
138 }