public interface ByteSink
ByteSinks
objects
represent entities existing outside of a logical graph,
such as files and sockets, which can be written to as a
stream of bytes. These can then be used in conjunction with
DataFormat
objects to consume records flowing
through a dataflow graph, the most common reason being
to persist the data to disk.
Generally, it is not necessarily to implement or even
directly use ByteSink
objects. Most write operators
provide a more convenient interface which obscures
the object; see AbstractWriter
as an example.
By default, sinks use OS-level authorization inherited from the execution environment, but can be configured to use use more complex authentication mechanisms to provide an authorization context.
Modifier and Type | Method and Description |
---|---|
boolean |
appendsExisting(WriteMode mode)
Indicates whether a write in the given mode
represents an append to an existing sink.
|
ByteSink |
authorize(FileClient client)
Creates a new sink with the same properties, but using the
specified authorization.
|
void |
cleanForOverwrite(int partitionCount)
Erases contents of the sink which do not correspond to
expected partition fragments.
|
ByteSink |
fragmentForPartition(int partitionId)
Creates a new subordinate sink.
|
boolean |
isFragmentable()
Indicates whether the sink can be broken into
subordinate sinks for parallel writes.
|
OutputStream |
open(WriteMode mode)
Opens the sink for writing in the specified mode.
|
FileChannel |
openChannel()
Opens the sink for random access.
|
InputStream |
openForRead()
Opens the sink for reading.
|
boolean |
supportsRandomAccess()
Indicates whether the sink supports random access.
|
void |
validate(WriteMode mode,
boolean forFragments)
Performs validation of the sink configuration.
|
ByteSink authorize(FileClient client)
If a sink is supposed to be used with a specific authorization context, this method should be called to produce a new sink to use.
client
- the authorization context to use for accessOutputStream open(WriteMode mode) throws IOException
mode
- indicates how to handle an existing sourceIOException
- if an I/O error occurs opening the sinkInputStream openForRead() throws IOException
appendsExisting(WriteMode)
.IOException
- if an I/O error occurs opening the sinkboolean supportsRandomAccess()
true
if the sink supports random access,
false
otherwise.openChannel()
FileChannel openChannel() throws IOException
supportsRandomAccess()
first.IOException
- if an I/O error occurs opening the sinkboolean isFragmentable()
Typically, this is only true if the sink represents a path in some hierarchical store, such as a file system.
true
if the sink can be
"fragmented", false
otherwise.fragmentForPartition(int)
ByteSink fragmentForPartition(int partitionId)
Fragments are used for parallel writes; each logical partition is written to a separate fragment created from the provided source.
partitionId
- a partition identifiervoid cleanForOverwrite(int partitionCount) throws IOException
This method will be called by one of the nodes during a parallel write in overwrite mode to ensure only the data from the current write is present on completion of the write.
partitionCount
- the number of partitions expectedIOException
- if an error occurs while attempting
to delete extraneous files from the target locationboolean appendsExisting(WriteMode mode)
This is used to determine whether file metadata needs to be written or updated. It is not always the case that this can be determined solely from the mode. For instance, an append to a non-existent file needs metadata to be written, but an append to an existing file may need to update metadata. Another example is console output, which should always write metadata, even though the sink always exists.
mode
- the intended write modetrue
if the write represents
the creation of a new dataset, false
otherwise.void validate(WriteMode mode, boolean forFragments) throws IOException
The caller should indicate how the write will be performed so that appropriate checks can be performed. For instance, if no overwriting is allowed, the target is checked to see if it already exists.
mode
- the intended write modeforFragments
- indicates whether the sink will
be fragmented for the writeIOException
- if an I/O error occurs while
validating the sourceCopyright © 2024 Actian Corporation. All rights reserved.