Class StreamingDataset
- All Implemented Interfaces:
Dataset,StreamingDatasetWriter,Serializable
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.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classstatic classstatic class -
Constructor Summary
ConstructorsConstructorDescriptionStreamingDataset(long waitTimeout, boolean transientDataMode) Constructs the dataset with the given timeout and mode. -
Method Summary
Modifier and TypeMethodDescriptionintbinarySearch(int column, Object key) Performs a binary search on the specified column, looking for the specified key.protected voidvoidfinish()Notifies the writer to close- all data has been written.voidFinishes the stream while indicating an error occurred.intReturns the number of columns.intgetColumnIndex(String name) Returns the index of the given column, case-insensitivegetColumnName(int col) Returns the name of the given column.Returns an unmodifiable list of this dataset's column names, in order.Class<?>getColumnType(int col) Returns the type of the given column.Returns an unmodifiable list of this dataset's column types, in order.intMostly for unit testingdoublegetPrimitiveValueAt(int row, int col) If the given column is a numeric type or a Date, then the value will be returned as a double.getQualityAt(int row, int col) Returns the quality of the value at the given location.getRow(int row) intReturn the number of rows in this datasetgetValueAt(int row, int col) Returns the value in the dataset at the given location.getValueAt(int row, String colName) Returns the value at the given row and at a column named colName.booleanhasRow(int row) This is somewhat similar to isClosed, but will potentially wait for more data to come in, or for the dataset to close.voidinitialize(String[] columnNames, Class<?>[] columnTypes, boolean supportsQuality, int expectedRows) Initializes the streaming dataset with important information, primarily the column names and types.booleanisClosed()Returns whether this dataset has been closed to further writing.static StreamingDatasetReturns a new streaming dataset that is only intended to write, and not read.voidBlocks until all of the data has been read.voidsetBlockingWrites(boolean value) If true, the dataset will block on writes until the previously written row is read (standard producer/consumer).voidsetTransientMode(boolean transientMode) protected StreamingDataset.RowwaitFor(int row) protected voidvoidvoidwrite(Object[] data, QualityCode[] quality) Writes a row with the given data.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.inductiveautomation.ignition.common.Dataset
getColumnAsList, hasQualityData
-
Constructor Details
-
StreamingDataset
public StreamingDataset() -
StreamingDataset
public StreamingDataset(long waitTimeout, boolean transientDataMode) Constructs the dataset with the given timeout and mode. "Transient Data Mode" means that data will be discarded after it is read, so all requests to getData() should only move forward in row index. This is useful for minimizing memory usage with very large datasets when this object is only being used for data processing.
-
-
Method Details
-
setTransientMode
public void setTransientMode(boolean transientMode) -
newWriter
Returns a new streaming dataset that is only intended to write, and not read. Essentially is a plain streaming dataset, with blocking writes enabled. -
setBlockingWrites
public void setBlockingWrites(boolean value) If true, the dataset will block on writes until the previously written row is read (standard producer/consumer). This prevents a build up in memory of unread rows. -
readFully
public void readFully()Blocks until all of the data has been read. Will throw a StreamingException if the overall timeout is exceeded. -
isClosed
public boolean isClosed()Returns whether this dataset has been closed to further writing. -
hasRow
public 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. Will return immediately if we know there is a row greater than the requested row available. In general, this function should be called to wait for new data before each call to getValueAt. -
checkError
protected void checkError() -
waitForColumns
protected void waitForColumns() -
getColumnNames
Description copied from interface:DatasetReturns an unmodifiable list of this dataset's column names, in order.- Specified by:
getColumnNamesin interfaceDataset
-
getColumnTypes
Description copied from interface:DatasetReturns an unmodifiable list of this dataset's column types, in order.- Specified by:
getColumnTypesin interfaceDataset
-
getColumnCount
public int getColumnCount()Description copied from interface:DatasetReturns the number of columns.- Specified by:
getColumnCountin interfaceDataset
-
getRowCount
public int getRowCount()Description copied from interface:DatasetReturn the number of rows in this dataset- Specified by:
getRowCountin interfaceDataset
-
getColumnIndex
Description copied from interface:DatasetReturns the index of the given column, case-insensitive- Specified by:
getColumnIndexin interfaceDataset- Parameters:
name- the name of the column to look up- Returns:
- the index of the column
-
getColumnName
Description copied from interface:DatasetReturns the name of the given column.- Specified by:
getColumnNamein interfaceDataset
-
getColumnType
Description copied from interface:DatasetReturns the type of the given column.- Specified by:
getColumnTypein interfaceDataset
-
waitFor
-
getValueAt
Description copied from interface:DatasetReturns the value in the dataset at the given location.- Specified by:
getValueAtin interfaceDataset
-
getQualityAt
Description copied from interface:DatasetReturns the quality of the value at the given location.- Specified by:
getQualityAtin interfaceDataset
-
getValueAt
Description copied from interface:DatasetReturns the value at the given row and at a column named colName. Column name matching is case insensitive.- Specified by:
getValueAtin interfaceDataset
-
getPrimitiveValueAt
public double getPrimitiveValueAt(int row, int col) Description copied from interface:DatasetIf the given column is a numeric type or a Date, then the value will be returned as a double. (Charts uses this functionality to provide a seamless interface with certain optimized dataset implementations.- Specified by:
getPrimitiveValueAtin interfaceDataset
-
getRow
-
binarySearch
Description copied from interface:DatasetPerforms a binary search on the specified column, looking for the specified key. Column MUST be sorted in ascending order. Dataset provides an inefficient default implementation of binary search that allocates a new array list for the entire column.- Specified by:
binarySearchin interfaceDataset- Returns:
- index of the search key, if it is contained in the list; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the list: the index of the first element greater than the key, or list.size(), if all elements in the list are less than the specified key. Note that this guarantees the return value will be greater than or equal to 0, but only if the key is found.
-
initialize
public void initialize(String[] columnNames, Class<?>[] columnTypes, boolean supportsQuality, int expectedRows) Description copied from interface:StreamingDatasetWriterInitializes the streaming dataset with important information, primarily the column names and types. If supportsQuality is true, it is expected that every value added has an associated quality. expectedRows gives an idea as to how many rows will be returned- useful for progress indication. Should be -1 if the number cannot be known in advance.- Specified by:
initializein interfaceStreamingDatasetWriterexpectedRows- -1 if not known, otherwise the number of rows that will be in the dataset.
-
write
Description copied from interface:StreamingDatasetWriterWrites a row with the given data. Bounds and order of arrays must match that used to call initialize. quality may be null if dataset does not support quality.- Specified by:
writein interfaceStreamingDatasetWriter- Throws:
IOException
-
write
-
finish
public void finish()Description copied from interface:StreamingDatasetWriterNotifies the writer to close- all data has been written. Should be called from a finally block.- Specified by:
finishin interfaceStreamingDatasetWriter
-
finishWithError
Description copied from interface:StreamingDatasetWriterFinishes the stream while indicating an error occurred. Either this, or the successful finish(), must be called.- Specified by:
finishWithErrorin interfaceStreamingDatasetWriter
-
getInternalRowCount
public int getInternalRowCount()Mostly for unit testing
-