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 */ 091 @Deprecated 092 public Cell create(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, 093 byte[] qualifier, int qoffset, int qlength, long timestamp, byte[] value, int voffset, 094 int vlength, String visExpression) throws IOException { 095 List<Tag> visTags = null; 096 if (visExpression != null) { 097 visTags = this.visExpResolver.createVisibilityExpTags(visExpression); 098 } 099 return new KeyValue(row, roffset, rlength, family, foffset, flength, qualifier, qoffset, 100 qlength, timestamp, KeyValue.Type.Put, value, voffset, vlength, visTags); 101 } 102 103 /** 104 * @param row row key 105 * @param roffset row offset 106 * @param rlength row length 107 * @param family family name 108 * @param foffset family offset 109 * @param flength family length 110 * @param qualifier column qualifier 111 * @param qoffset qualifier offset 112 * @param qlength qualifier length 113 * @param timestamp version timestamp 114 * @param value column value 115 * @param voffset value offset 116 * @param vlength value length 117 * @param tags 118 * @return created Cell 119 * @throws IOException 120 */ 121 public Cell create(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, 122 byte[] qualifier, int qoffset, int qlength, long timestamp, byte[] value, int voffset, 123 int vlength, List<Tag> tags) throws IOException { 124 return new KeyValue(row, roffset, rlength, family, foffset, flength, qualifier, qoffset, 125 qlength, timestamp, KeyValue.Type.Put, value, voffset, vlength, tags); 126 } 127 128 /** 129 * @return Visibility expression resolver 130 */ 131 public VisibilityExpressionResolver getVisibilityExpressionResolver() { 132 return this.visExpResolver; 133 } 134}