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    public static final String VISIBILITY_EXP_RESOLVER_CLASS =
39        "hbase.mapreduce.visibility.expression.resolver.class";
40  
41    private VisibilityExpressionResolver visExpResolver;
42  
43    public CellCreator(Configuration conf) {
44      Class<? extends VisibilityExpressionResolver> clazz = conf.getClass(
45          VISIBILITY_EXP_RESOLVER_CLASS, DefaultVisibilityExpressionResolver.class,
46          VisibilityExpressionResolver.class);
47      this.visExpResolver = ReflectionUtils.newInstance(clazz, conf);
48      this.visExpResolver.init();
49    }
50  
51    /**
52     * @param row row key
53     * @param roffset row offset
54     * @param rlength row length
55     * @param family family name
56     * @param foffset family offset
57     * @param flength family length
58     * @param qualifier column qualifier
59     * @param qoffset qualifier offset
60     * @param qlength qualifier length
61     * @param timestamp version timestamp
62     * @param value column value
63     * @param voffset value offset
64     * @param vlength value length
65     * @return created Cell
66     * @throws IOException
67     */
68    public Cell create(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength,
69        byte[] qualifier, int qoffset, int qlength, long timestamp, byte[] value, int voffset,
70        int vlength) throws IOException {
71      return create(row, roffset, rlength, family, foffset, flength, qualifier, qoffset, qlength,
72          timestamp, value, voffset, vlength, (List<Tag>)null);
73    }
74  
75    /**
76     * @param row row key
77     * @param roffset row offset
78     * @param rlength row length
79     * @param family family name
80     * @param foffset family offset
81     * @param flength family length
82     * @param qualifier column qualifier
83     * @param qoffset qualifier offset
84     * @param qlength qualifier length
85     * @param timestamp version timestamp
86     * @param value column value
87     * @param voffset value offset
88     * @param vlength value length
89     * @param visExpression visibility expression to be associated with cell
90     * @return created Cell
91     * @throws IOException
92     */
93    @Deprecated
94    public Cell create(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength,
95        byte[] qualifier, int qoffset, int qlength, long timestamp, byte[] value, int voffset,
96        int vlength, String visExpression) throws IOException {
97      List<Tag> visTags = null;
98      if (visExpression != null) {
99        visTags = this.visExpResolver.createVisibilityExpTags(visExpression);
100     }
101     return new KeyValue(row, roffset, rlength, family, foffset, flength, qualifier, qoffset,
102         qlength, timestamp, KeyValue.Type.Put, value, voffset, vlength, visTags);
103   }
104 
105   /**
106    * @param row row key
107    * @param roffset row offset
108    * @param rlength row length
109    * @param family family name
110    * @param foffset family offset
111    * @param flength family length
112    * @param qualifier column qualifier
113    * @param qoffset qualifier offset
114    * @param qlength qualifier length
115    * @param timestamp version timestamp
116    * @param value column value
117    * @param voffset value offset
118    * @param vlength value length
119    * @param tags
120    * @return created Cell
121    * @throws IOException
122    */
123   public Cell create(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength,
124       byte[] qualifier, int qoffset, int qlength, long timestamp, byte[] value, int voffset,
125       int vlength, List<Tag> tags) throws IOException {
126     return new KeyValue(row, roffset, rlength, family, foffset, flength, qualifier, qoffset,
127         qlength, timestamp, KeyValue.Type.Put, value, voffset, vlength, tags);
128   }
129 
130   /**
131    * @return Visibility expression resolver
132    */
133   public VisibilityExpressionResolver getVisibilityExpressionResolver() {
134     return this.visExpResolver;
135   }
136 }