Line-oriented storage for large tool result sets, exposed to scripts as services.resultSetManager. A query that matches more rows than fit in a model's context writes them here and hands back a handle, a sample and the true total, instead of a silently truncated page, and later operations - reading a window, searching it, counting it, or pulling one field out of every row - then cost a single call rather than a re-run of the original query, acting on the set that was found rather than whatever the query matches when it is run again. The caller supplies the directory and file name, since where a result set belongs is a question for the caller, and what this class adds is streaming: the underlying storage API only reads a whole file at once, so every method here reads only as much of the file as it was asked for. Line zero of the file is a JSON header describing the set and every line after it is one row as JSON, which is what makes a windowed read or a search possible without parsing the whole file first. Values returned to the caller cross as JSON strings rather than as maps or lists, since Nashorn's handling of Java collections is a known source of quiet failures.
Group: Managers
Methods
newHandle() · exists(String dir, String fileName) · appendRows(String dir, String fileName, String rows) · readHeader(String dir, String fileName) · readRows(String dir, String fileName, Integer offset, Integer limit) · grep(String dir, String fileName, String pattern, Integer limit, Boolean ignoreCase) · pluck(String dir, String fileName, String field, Integer maxValues) · stats(String dir, String fileName) · delete(String dir, String fileName)
newHandle()
Returns: String
A fresh handle, unique enough to name a result set within a conversation.
exists(String dir, String fileName)
Returns: boolean
Checks whether a result set file already exists, without reading any of its content.
| Parameter | Description |
|---|---|
dir | the directory holding the result set, as the caller lays it out |
fileName | the result set file |
appendRows(String dir, String fileName, String rows)
Returns: int
Appends rows to a result set, creating it if this is the first call. Takes newline-separated text rather than a list, so nothing depends on how the script engine converts a JS array to a Java list. Blank lines are dropped, since a trailing newline is the normal shape of a batch and must not become an empty row.
| Parameter | Description |
|---|---|
dir | the directory holding the result set |
fileName | the result set file |
rows | one row per line. The first call is expected to write the header line. |
readHeader(String dir, String fileName)
Returns: String
The header line, as it was written.
| Parameter | Description |
|---|---|
dir | the directory holding the result set |
fileName | the result set file |
readRows(String dir, String fileName, Integer offset, Integer limit)
Returns: String
A window of rows, parsed so the caller gets objects rather than strings to parse a second time.
| Parameter | Description |
|---|---|
dir | the directory holding the result set |
fileName | the result set file |
offset | how many rows to skip. 0 is the first row, not the header. |
limit | how many rows to return at most |
grep(String dir, String fileName, String pattern, Integer limit, Boolean ignoreCase)
Returns: String
Rows containing a substring, with a true count of how many matched rather than only the ones returned. A plain substring rather than a regular expression: this runs against a caller-supplied pattern on every row of a large file, and a pathological expression there is a denial of service rather than a better search. Anything needing real matching should pull the field out with pluck and work on that.
| Parameter | Description |
|---|---|
dir | the directory holding the result set |
fileName | the result set file |
pattern | the substring to look for, matched against the whole row as written |
limit | how many matching rows to return at most |
ignoreCase | true to match without regard to case |
pluck(String dir, String fileName, String field, Integer maxValues)
Returns: String
One field's value from every row - the id list a write tool needs to act on exactly the set that was found. Rows missing the field, or holding null for it, are skipped rather than yielding a null entry, so the count reported is the number of usable values and not the number of rows looked at.
| Parameter | Description |
|---|---|
dir | the directory holding the result set |
fileName | the result set file |
field | the field to take, at the top level of each row |
maxValues | stop after this many. A caller that gets {@code truncated: true} has more than it asked for, and must not treat what it got as the whole set. |
stats(String dir, String fileName)
Returns: String
Row and byte counts for a result set, without returning any of the rows themselves.
| Parameter | Description |
|---|---|
dir | the directory holding the result set |
fileName | the result set file |
delete(String dir, String fileName)
Returns: boolean
Deletes a result set file, if it exists.
| Parameter | Description |
|---|---|
dir | the directory holding the result set |
fileName | the result set file |