UNPKG

@jahed/sparql-engine

Version:

SPARQL query engine for servers and web browsers.

40 lines 1.79 kB
// SPDX-License-Identifier: MIT import { termToString } from "rdf-string"; import { Pipeline } from "../../engine/pipeline/pipeline.js"; import HashJoinTable from "./hash-join-table.js"; /** * Utility function used to perform one half of a symmetric hash join * @param joinKey - SPARQL variable used as join attribute * @param source - Source of bindings (a {@link PipelineStage}) * @param innerTable - Hash table in which bindings are inserted * @param outerTable - Hash table in which bindings are probed * @return A {@link PipelineStage} that performs one half of a symmetric hash join */ function halfHashJoin(joinKey, source, innerTable, outerTable) { const engine = Pipeline.getInstance(); return engine.mergeMap(source, (bindings) => { if (!bindings.has(joinKey)) { return engine.empty(); } const key = termToString(bindings.get(joinKey)); // insert into inner table innerTable.put(key, bindings); // probe into outer table return engine.from(outerTable.join(key, bindings)); }); } /** * Perform a Symmetric Hash Join between two sources * @param joinKey - SPARQL variable used as join attribute * @param left - Left source (a {@link PipelineStage}) * @param right - Right source (a {@link PipelineStage}) * @return A {@link PipelineStage} that performs a symmetric hash join between the sources */ export default function symHashJoin(joinKey, left, right) { const leftTable = new HashJoinTable(); const rightTable = new HashJoinTable(); const leftOp = halfHashJoin(joinKey, left, leftTable, rightTable); const rightOp = halfHashJoin(joinKey, right, rightTable, leftTable); return Pipeline.getInstance().merge(leftOp, rightOp); } //# sourceMappingURL=shjoin.js.map