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.

ParameterDescription
dirthe directory holding the result set, as the caller lays it out
fileNamethe 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.

ParameterDescription
dirthe directory holding the result set
fileNamethe result set file
rowsone 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.

ParameterDescription
dirthe directory holding the result set
fileNamethe 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.

ParameterDescription
dirthe directory holding the result set
fileNamethe result set file
offsethow many rows to skip. 0 is the first row, not the header.
limithow 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.

ParameterDescription
dirthe directory holding the result set
fileNamethe result set file
patternthe substring to look for, matched against the whole row as written
limithow many matching rows to return at most
ignoreCasetrue 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.

ParameterDescription
dirthe directory holding the result set
fileNamethe result set file
fieldthe field to take, at the top level of each row
maxValuesstop 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.

ParameterDescription
dirthe directory holding the result set
fileNamethe result set file

delete(String dir, String fileName)

Returns: boolean

Deletes a result set file, if it exists.

ParameterDescription
dirthe directory holding the result set
fileNamethe result set file
To get full access to the Kademi Hub existing customers can login here, or new customers can register here.