public class StreamingDataset extends java.lang.Object implements Dataset, StreamingDatasetWriter
The dataset can operate as a normal dataset, or if "transientDataMode" is true, will discard data after it is read, freeing up memory when using a large dataset for data processing purposes.
Since the streaming dataset won't normally know how many rows to expect (unless it was told the number in the initialize), the interaction with it is a little different than normal. Instead of calling getRowCount(), which will return -1 if the number of rows isn't known, it's better to call hasRow(x) (with x being the next row you hope to get) until it returns False.
If you need to treat this dataset as a normal dataset, you can call readFully() to block and retrieve all data. After that, it will behave like a normal dataset, with getRowCount() returning the correct value.
| Modifier and Type | Class and Description |
|---|---|
protected static class |
StreamingDataset.Column |
static class |
StreamingDataset.Row |
static class |
StreamingDataset.StreamingException |
| Constructor and Description |
|---|
StreamingDataset() |
StreamingDataset(long waitTimeout,
boolean transientDataMode)
Constructs the dataset with the given timeout and mode.
|
| Modifier and Type | Method and Description |
|---|---|
int |
binarySearch(int column,
java.lang.Object key)
Performs a binary search on the specified column, looking for the specified key.
|
protected void |
checkError() |
void |
finish()
Notifies the writer to close- all data has been written.
|
void |
finishWithError(java.lang.Exception e)
Finishes the stream while indicating an error occurred.
|
int |
getColumnCount()
Returns the number of columns.
|
int |
getColumnIndex(java.lang.String name)
Returns the index of the given column, case insensitive
|
java.lang.String |
getColumnName(int col)
Returns the name of the given column.
|
java.util.List<java.lang.String> |
getColumnNames()
Returns an unmodifiable list of this dataset's column names, in order.
|
java.lang.Class<?> |
getColumnType(int col)
Returns the type of the given column.
|
java.util.List<java.lang.Class<?>> |
getColumnTypes()
Returns an unmodifiable list of this dataset's column types, in order.
|
int |
getInternalRowCount()
Mostly for unit testing
|
double |
getPrimitiveValueAt(int row,
int col)
If the given column is a numeric type or a Date, then the value will be returned as a double.
|
QualityCode |
getQualityAt(int row,
int col)
Returns the quality of the value at the given location.
|
StreamingDataset.Row |
getRow(int row) |
int |
getRowCount()
Return the number of rows in this dataset
|
java.lang.Object |
getValueAt(int row,
int col)
Returns the value in the dataset at the given location.
|
java.lang.Object |
getValueAt(int row,
java.lang.String colName)
Returns the value at the given row and at a column named colName.
|
boolean |
hasRow(int row)
This is somewhat similar to isClosed, but will potentially wait for more data to come in, or for the dataset to
close.
|
void |
initialize(java.lang.String[] columnNames,
java.lang.Class<?>[] columnTypes,
boolean supportsQuality,
int expectedRows)
Initializes the streaming dataset with important information, primarily the column names and types.
|
boolean |
isClosed()
Returns whether this dataset has been closed to further writing.
|
static StreamingDataset |
newWriter()
Returns a new streaming dataset that is only intended to write, and not read.
|
void |
readFully()
Blocks until all of the data has been read.
|
void |
setBlockingWrites(boolean value)
If true, the dataset will block on writes until the previously written row is read (standard producer/consumer).
|
void |
setTransientMode(boolean transientMode) |
protected StreamingDataset.Row |
waitFor(int row) |
protected void |
waitForColumns() |
void |
write(java.lang.Object[] data,
QualityCode[] quality)
Writes a row with the given data.
|
void |
write(StreamingDataset.Row row) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetColumnAsListpublic StreamingDataset()
public StreamingDataset(long waitTimeout,
boolean transientDataMode)
public void setTransientMode(boolean transientMode)
public static StreamingDataset newWriter()
public void setBlockingWrites(boolean value)
public void readFully()
public boolean isClosed()
public boolean hasRow(int row)
protected void checkError()
protected void waitForColumns()
public java.util.List<java.lang.String> getColumnNames()
DatasetgetColumnNames in interface Datasetpublic java.util.List<java.lang.Class<?>> getColumnTypes()
DatasetgetColumnTypes in interface Datasetpublic int getColumnCount()
DatasetgetColumnCount in interface Datasetpublic int getRowCount()
DatasetgetRowCount in interface Datasetpublic int getColumnIndex(java.lang.String name)
DatasetgetColumnIndex in interface Datasetname - the name of the column to look upwpublic java.lang.String getColumnName(int col)
DatasetgetColumnName in interface Datasetpublic java.lang.Class<?> getColumnType(int col)
DatasetgetColumnType in interface Datasetprotected StreamingDataset.Row waitFor(int row)
public java.lang.Object getValueAt(int row,
int col)
DatasetgetValueAt in interface Datasetpublic QualityCode getQualityAt(int row, int col)
DatasetgetQualityAt in interface Datasetpublic java.lang.Object getValueAt(int row,
java.lang.String colName)
DatasetgetValueAt in interface Datasetpublic double getPrimitiveValueAt(int row,
int col)
DatasetgetPrimitiveValueAt in interface Datasetpublic StreamingDataset.Row getRow(int row)
public int binarySearch(int column,
java.lang.Object key)
DatasetbinarySearch in interface Datasetpublic void initialize(java.lang.String[] columnNames,
java.lang.Class<?>[] columnTypes,
boolean supportsQuality,
int expectedRows)
StreamingDatasetWriterinitialize in interface StreamingDatasetWriterexpectedRows - -1 if not known, otherwise the number of rows that will be in the dataset.public void write(java.lang.Object[] data,
QualityCode[] quality)
throws java.io.IOException
StreamingDatasetWriterwrite in interface StreamingDatasetWriterjava.io.IOExceptionpublic void write(StreamingDataset.Row row)
public void finish()
StreamingDatasetWriterfinish in interface StreamingDatasetWriterpublic void finishWithError(java.lang.Exception e)
StreamingDatasetWriterfinishWithError in interface StreamingDatasetWriterpublic int getInternalRowCount()