Hi @hoangthaihuy, @dgosselin and I have been discussing your question. There is no pre-built solution, but there are a couple of possible approaches: writing a user-defined operator (UDO) or using the stream operator from https://github.com/Paradigm4/stream . I wouldn’t go with a user-defined function approach, because UDFs only get to see the scidb::Value objects they’re applied to during query execution, and wouldn’t be able to really alter or stop the flow of execution.
An advantage of going with your own UDO is that you could pass parameters to it that would set your algorithm’s threshold for declaring “good enough”, which might be useful.
UDOs also have access to the Query object and so can cancel the query—but if you cancel, you’ll have to make some kind of custom way of communicating the partial result. Just cancelling the query would not store any result array. But you need not cancel the query; an operator in the middle of a larger query could decide instead to simply stop providing chunks to its upstream operator. Something like
store(outer_query(your_udo(inner_query(...), threshold), outer_args), RESULT)
If you can watch the innery_query() results flying past and decide that they’ve met the threshold criteria, then you can cease providing chunks to the outer_query() and store() will store whatever you’ve got.
In the course of deciding whether the threshold is met or not, you might find the AggregateLibrary helpful. In addition to UDOs and UDFs, SciDB also allows user-defined aggregates (UDAs). See include/query/Aggregate.h in the source tree.
Regarding the stream operator from Github, the best introduction is this excellent blog post by @rares : https://rvernica.github.io/2017/10/streaming-machine-learning . I have not myself used the stream operator, but you should definitely check it out since debugging R or Python is much easier than debugging a C++ SciDB operator.
Without knowing more about your application I can’t really say much more, but I hope this gives you some good directions to investigate!