Class ydn.db.Solver
An Algorithm class represents an iterative solver by guiding cursor increment for each scanning iteration.
ydn.db.algo.AbstractSolver(solver, initializer,
finalizer)
Create an algorithm giving functions.
Solver function is an optimizer receiving input argument, input
,
of some function to optimized and its function output value, output
.
Solver return an array giving advance to make for next iteration step.
At the same time solver must meet given constrain condition. A solver
function decide a result and push to output streamers.
Adapter function format result from scanning iteration to solver function.
- Parameters:
- {!function(input: !Array, output: !Array, constrain: !Array): Array} solver
- The solver function to guide next cursor iteration.
- {function(iterator_keys: !Array, iterator_values: !Array, streamer_keys: !Array, streamer_values: !Array): {'input': !Array, 'output': !Array, 'constrain': !Array} adapter
- Optional. The adapter function format streaming values from the scanner for advancer function.
- {function(iterators: !Array, streamers: !Array, on_complete: Function): boolean} initializer
- Optional. The initializer
function is invoked before beginning of scanning iteration.
Return
true
to wait foron_complete
callback. - {function(on_complete: Function): boolean} finalizer
- Optional. The finalizer
function is invoked at the end of scanning iteration. Return
true
to wait foron_complete
callback.
ydn.db.algo.NestedLoop(out, limit) version
4
Create an nested loop join algorithm.
The following example illustrate friendship graph query. friendship
object store has only one listed indexed field friend_list
.
It uses people object store key as out-of-line key. people
object store has many attributes, among them is location
field. The query is to find list of friends who know me
and other_guy
and located in 'Singapore'.
var q1 = ydn.db.Cursor.where('friendship', 'friend_list', '=', me); var q2 = ydn.db.Cursor.where('friendship', 'friend_list', '=', other_guy); var q3 = ydn.db.Cursor.where('people', 'location', '=', Singapore); var out = new ydn.db.Streamer(db, 'people'); var join_algo = new ydn.db.algo.NestedJoin(out); var result = db.scan([q3, q1, q2], join_algo); result.done(function() { out.collect(function(friends) { console.log(friends); // should get desire list of friends } });
- Parameters:
- {(!Array|!{push: Function}|!ydn.db.Streamer)=} out
- The output streamers.
- {number=} limit
- Limit number of results.
ydn.db.algo.SortedMerge(out, limit)
Create an sorted merge join algorithm.
Sorted merge join given input iterators by their reference value. Generally input iterators are index key cursor iterator and hence their reference values are primary keys.
- Parameters:
- {(!Array|!{push: Function}|!ydn.db.Streamer)=} out
- The output streamers.
- {number=} limit
- Limit number of results.
ydn.db.algo.Zigzag(out, limit)
Create an zigzag merge join algorithm.
Sorted merge join given input iterators by their effective key, which compose a constant prefix and sorted post-fix. Generally input iterators are composite index key cursor iterator of filtered prefix index and sorted postfix index.
- Parameters:
- {(!Array|!{push: Function}|!ydn.db.Streamer)=} out
- The output streamers.
- {number=} limit
- Limit number of results.