001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.mapreduce; 019 020import java.io.IOException; 021import java.util.List; 022 023import org.apache.yetus.audience.InterfaceAudience; 024import org.apache.hadoop.conf.Configuration; 025import org.apache.hadoop.hbase.Cell; 026import org.apache.hadoop.hbase.KeyValue; 027import org.apache.hadoop.hbase.Tag; 028import org.apache.hadoop.util.ReflectionUtils; 029 030/** 031 * Facade to create Cells for HFileOutputFormat. The created Cells are of <code>Put</code> type. 032 */ 033@InterfaceAudience.Public 034public class CellCreator { 035 036 public static final String VISIBILITY_EXP_RESOLVER_CLASS = 037 "hbase.mapreduce.visibility.expression.resolver.class"; 038 039 private VisibilityExpressionResolver visExpResolver; 040 041 public CellCreator(Configuration conf) { 042 Class<? extends VisibilityExpressionResolver> clazz = conf.getClass( 043 VISIBILITY_EXP_RESOLVER_CLASS, DefaultVisibilityExpressionResolver.class, 044 VisibilityExpressionResolver.class); 045 this.visExpResolver = ReflectionUtils.newInstance(clazz, conf); 046 this.visExpResolver.init(); 047 } 048 049 /** 050 * @param row row key 051 * @param roffset row offset 052 * @param rlength row length 053 * @param family family name 054 * @param foffset family offset 055 * @param flength family length 056 * @param qualifier column qualifier 057 * @param qoffset qualifier offset 058 * @param qlength qualifier length 059 * @param timestamp version timestamp 060 * @param value column value 061 * @param voffset value offset 062 * @param vlength value length 063 * @return created Cell 064 * @throws IOException 065 */ 066 public Cell create(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, 067 byte[] qualifier, int qoffset, int qlength, long timestamp, byte[] value, int voffset, 068 int vlength) throws IOException { 069 return create(row, roffset, rlength, family, foffset, flength, qualifier, qoffset, qlength, 070 timestamp, value, voffset, vlength, (List<Tag>)null); 071 } 072 073 /** 074 * @param row row key 075 * @param roffset row offset 076 * @param rlength row length 077 * @param family family name 078 * @param foffset family offset 079 * @param flength family length 080 * @param qualifier column qualifier 081 * @param qoffset qualifier offset 082 * @param qlength qualifier length 083 * @param timestamp version timestamp 084 * @param value column value 085 * @param voffset value offset 086 * @param vlength value length 087 * @param visExpression visibility expression to be associated with cell 088 * @return created Cell 089 * @throws IOException 090 * @deprecated since 0.98.9 091 * @see <a href="https://issues.apache.org/jira/browse/HBASE-10560">HBASE-10560</a> 092 */ 093 @Deprecated 094 public Cell create(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, 095 byte[] qualifier, int qoffset, int qlength, long timestamp, byte[] value, int voffset, 096 int vlength, String visExpression) throws IOException { 097 List<Tag> visTags = null; 098 if (visExpression != null) { 099 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}