UNPKG

@jahed/sparql-engine

Version:

SPARQL query engine for servers and web browsers.

17 lines 688 B
// SPDX-License-Identifier: MIT import { cloneDeep, partition } from "lodash-es"; import PlanVisitor from "../plan-visitor.js"; /** * Implements the UNION Merge rule: all SPARQL UNION clauses in the same group pattern * should be merged as one single UNION clause. */ export default class UnionMerge extends PlanVisitor { visitUnion(node) { const newNode = cloneDeep(node); const parts = partition(newNode.patterns, (group) => group.type === "union"); const singleUnion = parts[0].reduce((acc, c) => acc.concat(c.patterns), []); newNode.patterns = parts[1].concat(singleUnion); return newNode; } } //# sourceMappingURL=union-merge.js.map