S
- - type of shape written as value.public class GridRecordWriter<S extends Shape> extends java.lang.Object implements ShapeRecordWriter<S>
RecordWriter
with specific keys and values, we do all
the implementation in this class and extend it with an implementation of
RecordWriter with specific key and value.
This class is not made abstract because it is still used outside of MapReduce
programs.GridRecordWriter
,
GridRecordWriter2
,
GridRecordWriter3
Modifier and Type | Field and Description |
---|---|
protected long |
blockSize
Block size for grid file written
|
protected CellInfo[] |
cells
The spatial boundaries for each cell
|
protected Rectangle[] |
cellsMbr
MBR of the records written so far to each cell
|
protected java.util.ArrayList<java.lang.Thread> |
closingThreads
A list of threads closing cells in background
|
static java.util.Set<java.lang.String> |
ExpandedIndexes
A list of indexes in which each partition has to be expanded to fully
contain all the records inside it
|
protected FileSystem |
fileSystem
File system for output path
|
protected Path[] |
intermediateCellPath
Paths of intermediate files
|
protected int[] |
intermediateCellRecordCount
Keeps the number of elements written to each cell so far.
|
protected int[] |
intermediateCellSize
Size in bytes of intermediate files written so far
|
protected java.io.OutputStream[] |
intermediateCellStreams
An output stream for each grid cell
|
protected JobConf |
jobConf
Job configuration if part of a MapReduce job
|
static Log |
LOG |
protected java.io.OutputStream |
masterFile
An output stream to the master file
|
protected static byte[] |
NEW_LINE
New line marker to separate records
|
protected Path |
outDir
Path of the output directory if not part of a MapReduce job
|
protected boolean |
pack
Pack MBR of each cell around its content after it's written to disk
|
static java.util.Set<java.lang.String> |
PackedIndexes
A list of indexes the can be optimized by packing each partition to remove
empty space
|
protected java.lang.String |
prefix
A unique prefix to all files written by this writer
|
static java.util.Set<java.lang.String> |
ReplicatedIndexes
Indexes where an object might be replicated to multiple partitions.
|
protected S |
stockObject
A stock object used for serialization/deserialization
|
protected Text |
text
Temporary text to serialize one object
|
Constructor and Description |
---|
GridRecordWriter(Path outDir,
JobConf job,
java.lang.String prefix,
CellInfo[] cells)
Creates a new GridRecordWriter that will write all data files to the
given directory
|
Modifier and Type | Method and Description |
---|---|
void |
close(Progressable progressable)
Close the whole writer.
|
protected void |
closeCell(int cellIndex)
Closes (or initiates a close command) for the cell with the given index.
|
protected void |
closeCellBackground(Path intermediateCellPath,
Path finalCellPath,
java.io.OutputStream intermediateCellStream,
java.io.OutputStream masterFile,
CellInfo cellMbr,
long recordCount,
long cellSize)
Close the given cell freeing all memory reserved by it.
|
protected java.io.OutputStream |
createFinalCellStream(Path cellFilePath)
Creates an output stream that will be used to write the final cell file
|
protected Path |
flushAllEntries(Path intermediateCellPath,
java.io.OutputStream intermediateCellStream,
Path finalCellPath)
Flushes all shapes that were written to one cell to the final file.
|
protected Path |
getFilePath(java.lang.String filename)
Returns a path to a file with the given name in the output directory
of the record writer.
|
protected Path |
getFinalCellPath(int cellIndex)
Returns path to a file in which the final cell will be written.
|
protected java.io.OutputStream |
getIntermediateCellStream(int cellIndex)
Returns an output stream in which records are written as they come before
they are finally flushed to the cell file.
|
protected Path |
getMasterFilePath() |
void |
setStockObject(S stockObject)
Sets a stock object used to serialize/deserialize objects when written to
disk.
|
void |
write(NullWritable dummy,
S shape)
Writes the given shape to the file to all cells it overlaps with
|
protected void |
writeInternal(int cellIndex,
S shape)
Write the given shape to the cellIndex indicated.
|
public static final Log LOG
protected CellInfo[] cells
protected Path[] intermediateCellPath
protected java.io.OutputStream[] intermediateCellStreams
protected Rectangle[] cellsMbr
protected JobConf jobConf
protected Path outDir
protected final FileSystem fileSystem
protected Text text
protected long blockSize
protected S extends Shape stockObject
protected java.io.OutputStream masterFile
protected java.util.ArrayList<java.lang.Thread> closingThreads
protected int[] intermediateCellRecordCount
protected int[] intermediateCellSize
protected static byte[] NEW_LINE
protected java.lang.String prefix
protected boolean pack
public static final java.util.Set<java.lang.String> PackedIndexes
public static final java.util.Set<java.lang.String> ReplicatedIndexes
public static final java.util.Set<java.lang.String> ExpandedIndexes
public GridRecordWriter(Path outDir, JobConf job, java.lang.String prefix, CellInfo[] cells) throws java.io.IOException
outDir
- - The directory in which all files will be storedjob
- - The MapReduce job associated with this outputprefix
- - A unique prefix to be associated with files of this writercells
- - Cells to partition the filepack
- - After writing each cell, pack its MBR around contentsjava.io.IOException
protected Path getMasterFilePath() throws java.io.IOException
java.io.IOException
protected Path getFilePath(java.lang.String filename) throws java.io.IOException
filename
- java.io.IOException
public void setStockObject(S stockObject)
ShapeRecordWriter
setStockObject
in interface ShapeRecordWriter<S extends Shape>
public void write(NullWritable dummy, S shape) throws java.io.IOException
ShapeRecordWriter
write
in interface ShapeRecordWriter<S extends Shape>
java.io.IOException
protected void writeInternal(int cellIndex, S shape) throws java.io.IOException
cellIndex
- shape
- java.io.IOException
protected java.io.OutputStream getIntermediateCellStream(int cellIndex) throws java.io.IOException
cellIndex
- java.io.IOException
protected java.io.OutputStream createFinalCellStream(Path cellFilePath) throws java.io.IOException
cellFilePath
- java.io.IOException
protected void closeCell(int cellIndex) throws java.io.IOException
cellIndex
- java.io.IOException
protected void closeCellBackground(Path intermediateCellPath, Path finalCellPath, java.io.OutputStream intermediateCellStream, java.io.OutputStream masterFile, CellInfo cellMbr, long recordCount, long cellSize) throws java.io.IOException
cellInfo
- java.io.IOException
protected Path flushAllEntries(Path intermediateCellPath, java.io.OutputStream intermediateCellStream, Path finalCellPath) throws java.io.IOException
cellIndex
- java.io.IOException
public void close(Progressable progressable) throws java.io.IOException
close
in interface ShapeRecordWriter<S extends Shape>
java.io.IOException
protected Path getFinalCellPath(int cellIndex) throws java.io.IOException
column
- row
- java.io.IOException