001/* 002 * Copyright (c) 2016-2017 Chris K Wensel <chris@wensel.net>. All Rights Reserved. 003 * Copyright (c) 2007-2017 Xplenty, Inc. All Rights Reserved. 004 * 005 * Project and contact information: http://www.cascading.org/ 006 * 007 * This file is part of the Cascading project. 008 * 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 */ 021 022package cascading.tap.partition; 023 024import java.io.Serializable; 025 026import cascading.tuple.Fields; 027import cascading.tuple.TupleEntry; 028 029/** 030 * The Partition interface allows for custom partitioning mechanisms to be created with the {@link BasePartitionTap} 031 * sub-classes. 032 * <p> 033 * A partition is a directory on a filesystem, where the directory contains data related to the files underneath 034 * the partition directory. 035 * <p> 036 * For example, a partition could be {@code "2012/09/01"}, which would contain log files for that day. 037 */ 038public interface Partition extends Serializable 039 { 040 /** 041 * Returns the directory search depth of the partition. 042 * <p> 043 * For example, a Partition implementation that returns values like {@code "2012/09/01"} would have a depth of 3. 044 * 045 * @return an int 046 */ 047 int getPathDepth(); 048 049 /** 050 * The {@link Fields} used to populate the partition. 051 * 052 * @return a Fields instance 053 */ 054 Fields getPartitionFields(); 055 056 /** 057 * Converts the given partition String to a {@link TupleEntry} using the given TupleEntry instance for re-use. 058 * 059 * @param partition a String 060 * @param tupleEntry a TupleEntry 061 */ 062 void toTuple( String partition, TupleEntry tupleEntry ); 063 064 /** 065 * Converts the given tupleEntry into a partition string. 066 * 067 * @param tupleEntry a TupleEntry 068 * @return a String 069 */ 070 String toPartition( TupleEntry tupleEntry ); 071 }