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 n 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 n * @deprecated since 0.98.9 087 * @see <a href="https://issues.apache.org/jira/browse/HBASE-10560">HBASE-10560</a> 088 */ 089 @Deprecated 090 public Cell create(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, 091 byte[] qualifier, int qoffset, int qlength, long timestamp, byte[] value, int voffset, 092 int vlength, String visExpression) throws IOException { 093 List<Tag> visTags = null; 094 if (visExpression != null) { 095 visTags = this.visExpResolver.createVisibilityExpTags(visExpression); 096 } 097 return new KeyValue(row, roffset, rlength, family, foffset, flength, qualifier, qoffset, 098 qlength, timestamp, KeyValue.Type.Put, value, voffset, vlength, visTags); 099 } 100 101 /** 102 * @param row row key 103 * @param roffset row offset 104 * @param rlength row length 105 * @param family family name 106 * @param foffset family offset 107 * @param flength family length 108 * @param qualifier column qualifier 109 * @param qoffset qualifier offset 110 * @param qlength qualifier length 111 * @param timestamp version timestamp 112 * @param value column value 113 * @param voffset value offset 114 * @param vlength value length n * @return created Cell n 115 */ 116 public Cell create(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, 117 byte[] qualifier, int qoffset, int qlength, long timestamp, byte[] value, int voffset, 118 int vlength, List<Tag> tags) throws IOException { 119 return new KeyValue(row, roffset, rlength, family, foffset, flength, qualifier, qoffset, 120 qlength, timestamp, KeyValue.Type.Put, value, voffset, vlength, tags); 121 } 122 123 /** Returns Visibility expression resolver */ 124 public VisibilityExpressionResolver getVisibilityExpressionResolver() { 125 return this.visExpResolver; 126 } 127}