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; 022import org.apache.hadoop.conf.Configuration; 023import org.apache.hadoop.hbase.Cell; 024import org.apache.hadoop.hbase.KeyValue; 025import org.apache.hadoop.hbase.Tag; 026import org.apache.hadoop.util.ReflectionUtils; 027import org.apache.yetus.audience.InterfaceAudience; 028 029/** 030 * Facade to create Cells for HFileOutputFormat. The created Cells are of <code>Put</code> type. 031 */ 032@InterfaceAudience.Public 033public class CellCreator { 034 035 public static final String VISIBILITY_EXP_RESOLVER_CLASS = 036 "hbase.mapreduce.visibility.expression.resolver.class"; 037 038 private VisibilityExpressionResolver visExpResolver; 039 040 public CellCreator(Configuration conf) { 041 Class<? extends VisibilityExpressionResolver> clazz = 042 conf.getClass(VISIBILITY_EXP_RESOLVER_CLASS, DefaultVisibilityExpressionResolver.class, 043 VisibilityExpressionResolver.class); 044 this.visExpResolver = ReflectionUtils.newInstance(clazz, conf); 045 this.visExpResolver.init(); 046 } 047 048 /** 049 * @param row row key 050 * @param roffset row offset 051 * @param rlength row length 052 * @param family family name 053 * @param foffset family offset 054 * @param flength family length 055 * @param qualifier column qualifier 056 * @param qoffset qualifier offset 057 * @param qlength qualifier length 058 * @param timestamp version timestamp 059 * @param value column value 060 * @param voffset value offset 061 * @param vlength value length 062 * @return created Cell 063 */ 064 public Cell create(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, 065 byte[] qualifier, int qoffset, int qlength, long timestamp, byte[] value, int voffset, 066 int vlength) throws IOException { 067 return create(row, roffset, rlength, family, foffset, flength, qualifier, qoffset, qlength, 068 timestamp, value, voffset, vlength, (List<Tag>) null); 069 } 070 071 /** 072 * @param row row key 073 * @param roffset row offset 074 * @param rlength row length 075 * @param family family name 076 * @param foffset family offset 077 * @param flength family length 078 * @param qualifier column qualifier 079 * @param qoffset qualifier offset 080 * @param qlength qualifier length 081 * @param timestamp version timestamp 082 * @param value column value 083 * @param voffset value offset 084 * @param vlength value length 085 * @param visExpression visibility expression to be associated with cell 086 * @return created Cell 087 * @deprecated since 0.98.9 088 * @see <a href="https://issues.apache.org/jira/browse/HBASE-10560">HBASE-10560</a> 089 */ 090 @Deprecated 091 public Cell create(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, 092 byte[] qualifier, int qoffset, int qlength, long timestamp, byte[] value, int voffset, 093 int vlength, String visExpression) throws IOException { 094 List<Tag> visTags = null; 095 if (visExpression != null) { 096 visTags = this.visExpResolver.createVisibilityExpTags(visExpression); 097 } 098 return new KeyValue(row, roffset, rlength, family, foffset, flength, qualifier, qoffset, 099 qlength, timestamp, KeyValue.Type.Put, value, voffset, vlength, visTags); 100 } 101 102 /** 103 * @param row row key 104 * @param roffset row offset 105 * @param rlength row length 106 * @param family family name 107 * @param foffset family offset 108 * @param flength family length 109 * @param qualifier column qualifier 110 * @param qoffset qualifier offset 111 * @param qlength qualifier length 112 * @param timestamp version timestamp 113 * @param value column value 114 * @param voffset value offset 115 * @param vlength value length 116 * @return created Cell 117 */ 118 public Cell create(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, 119 byte[] qualifier, int qoffset, int qlength, long timestamp, byte[] value, int voffset, 120 int vlength, List<Tag> tags) throws IOException { 121 return new KeyValue(row, roffset, rlength, family, foffset, flength, qualifier, qoffset, 122 qlength, timestamp, KeyValue.Type.Put, value, voffset, vlength, tags); 123 } 124 125 /** Returns Visibility expression resolver */ 126 public VisibilityExpressionResolver getVisibilityExpressionResolver() { 127 return this.visExpResolver; 128 } 129}