Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Update all the aggregators with the input binding
const group = this.groups.get(groupHash);
for (const i in this.pattern.aggregates) {
const aggregate = this.pattern.aggregates[i];
// If distinct, check first wether we have inserted these values already
if (aggregate.distinct) {
const hash = this.hashBindings(bindings);
if (this.distinctHashes!.get(groupHash).has(hash)) {
continue;
} else {
this.distinctHashes!.get(groupHash).add(hash);
}
}
const variable = termToString(aggregate.variable);
group.aggregators[variable].put(bindings);
}
}
}
aggBindings[variable] = value;
}
}
// Merge grouping bindings and aggregator bindings
return groupBindings.merge(aggBindings);
});
// Case: No Input
// Some aggregators still define an output on the empty input
// Result is a single Bindings
if (rows.length === 0) {
const single: { [key: string]: Term } = {};
for (const i in this.pattern.aggregates) {
const aggregate = this.pattern.aggregates[i];
const key = termToString(aggregate.variable);
const value = AggregateEvaluator.emptyValue(aggregate);
if (value !== undefined) {
single[key] = value;
}
}
rows = [Bindings(single)];
}
return rows;
}
public async runOperation(pattern: Algebra.Extend, context: ActionContext)
: Promise {
const { expression, input, variable } = pattern;
const output: IActorQueryOperationOutputBindings = ActorQueryOperation.getSafeBindings(
await this.mediatorQueryOperation.mediate({ operation: input, context }));
const extendKey = termToString(variable);
const config = { ...ActorQueryOperation.getExpressionContext(context) };
const evaluator = new AsyncEvaluator(expression, config);
// Transform the stream by extending each Bindings with the expression result
const transform = async (bindings: Bindings, next: any) => {
try {
const result = await evaluator.evaluate(bindings);
// Extend operation is undefined when the key already exists
// We just override it here.
const extended = bindings.set(extendKey, result);
bindingsStream._push(extended);
} catch (err) {
if (isExpressionError(err)) {
// Errors silently don't actually extend according to the spec
bindingsStream._push(bindings);
// But let's warn anyway
constructor(ostrichDocument: any, versionContext: VersionContext,
subject?: RDF.Term, predicate?: RDF.Term, object?: RDF.Term, options?: any) {
super(options || { autoStart: false });
this.ostrichDocument = ostrichDocument;
this.versionContext = versionContext;
this.subject = RdfString.termToString(subject);
this.predicate = RdfString.termToString(predicate);
this.object = RdfString.termToString(object);
this.position = options && options.offset || 0;
this.on('newListener', (eventName) => {
if (eventName === 'totalItems') {
setImmediate(() => this._fillBuffer());
}
});
}
(acc: {[key: string]: string}, term: RDF.Term, key: QuadTermName) => {
if (ActorQueryOperationQuadpattern.isTermVariable(term)) {
acc[key] = termToString(term);
}
return acc;
}, {});
const quadBindingsReducer = (acc: {[key: string]: RDF.Term}, term: RDF.Term, key: QuadTermName) => {
constructor(hdtDocument: any, subject?: RDF.Term, predicate?: RDF.Term, object?: RDF.Term, options?: any) {
super(options || { autoStart: false });
this.hdtDocument = hdtDocument;
this.subject = RdfString.termToString(subject);
this.predicate = RdfString.termToString(predicate);
this.object = RdfString.termToString(object);
this.position = options && options.offset || 0;
this.on('newListener', (eventName) => {
if (eventName === 'totalItems') {
setImmediate(() => this._fillBuffer());
}
});
}
constructor(ostrichDocument: any, versionContext: VersionContext,
subject?: RDF.Term, predicate?: RDF.Term, object?: RDF.Term, options?: any) {
super(options || { autoStart: false });
this.ostrichDocument = ostrichDocument;
this.versionContext = versionContext;
this.subject = RdfString.termToString(subject);
this.predicate = RdfString.termToString(predicate);
this.object = RdfString.termToString(object);
this.position = options && options.offset || 0;
this.on('newListener', (eventName) => {
if (eventName === 'totalItems') {
setImmediate(() => this._fillBuffer());
}
});
}
return new Promise((resolve, reject) => {
const s = RdfString.termToString(subject);
const p = RdfString.termToString(predicate);
const o = RdfString.termToString(object);
const done = (error: Error, totalItems: number) => {
if (error) {
reject(error);
}
resolve(totalItems);
};
if (this.versionContext.type === 'version-materialization') {
this.ostrichDocument.countTriplesVersionMaterialized(s, p, o, this.versionContext.version, done);
} else if (this.versionContext.type === 'delta-materialization') {
this.ostrichDocument.countTriplesDeltaMaterialized(s, p, o,
this.versionContext.versionEnd, this.versionContext.versionStart, done);
} else {
this.ostrichDocument.countTriplesVersion(s, p, o, done);
}
});
.concat(aggregates.map((agg) => termToString(agg.variable)));
private substituteSingle(term: RDF.Term, bindings: Bindings): RDF.Term {
if (term.termType === 'Variable') {
return bindings.get(termToString(term), term);
}
return term;
}
}