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 * @return created Cell 086 */ 087 public Cell create(byte[] row, int roffset, int rlength, byte[] family, int foffset, int flength, 088 byte[] qualifier, int qoffset, int qlength, long timestamp, byte[] value, int voffset, 089 int vlength, List<Tag> tags) throws IOException { 090 return new KeyValue(row, roffset, rlength, family, foffset, flength, qualifier, qoffset, 091 qlength, timestamp, KeyValue.Type.Put, value, voffset, vlength, tags); 092 } 093 094 /** Returns Visibility expression resolver */ 095 public VisibilityExpressionResolver getVisibilityExpressionResolver() { 096 return this.visExpResolver; 097 } 098}