Class TupleExprIRRenderer
java.lang.Object
org.eclipse.rdf4j.queryrender.sparql.TupleExprIRRenderer
TupleExprIRRenderer: user-facing façade to convert RDF4J algebra back into SPARQL text.
Conversion of TupleExpr into a textual IR and expression rendering is delegated to
TupleExprToIrConverter. This class orchestrates IR transforms and printing, and provides a small
configuration surface and convenience entrypoints.
- SELECT / ASK / DESCRIBE / CONSTRUCT forms
- BGPs, OPTIONALs, UNIONs, MINUS, GRAPH, SERVICE, VALUES
- Property paths, plus safe best-effort reassembly for simple cases
- Aggregates, GROUP BY, HAVING (with _anon_having_* substitution)
- Subselects in WHERE
- ORDER BY, LIMIT, OFFSET
- Prefix compaction and nice formatting
- Normalize the TupleExpr (peel Order/Slice/Distinct/etc., detect HAVING) into a lightweight
Normalizedcarrier. - Build a textual Intermediate Representation (IR) that mirrors SPARQL’s shape: a header (projection), a list-like
WHERE block (
IrBGP), and trailing modifiers. The IR tries to be a straightforward, low-logic mirror of the TupleExpr tree. - Run a small, ordered pipeline of IR transforms (
IrTransforms) that are deliberately side‑effect‑free and compositional. Each transform is narrowly scoped (e.g., property path fusions, negated property sets, collections) and uses simple heuristics like only fusing across parser‑generated bridge variables named with the_anon_path_prefix. - Print the transformed IR using a tiny printer interface (
) that centralizes indentation, IRI compaction, and child printing.
invalid reference
IrPrinter
- Do not rewrite a single inequality
?p != <iri>into?p NOT IN (<iri>). Only reconstruct NOT IN when multiple!=terms share the same variable. - Do not fuse
?s ?p ?o . FILTER (?p != <iri>)into a negated path?s !(<iri>) ?o. - Use
aforrdf:typeconsistently, incl. inside property lists.
_anon_path_*: anonymous intermediate variables introduced when parsing property paths. Transforms only compose chains across these bridge variables to avoid altering user bindings._anon_having_*: marks variables synthesized for HAVING extraction._anon_bnode_*: placeholder variables for [] that should render as an empty blank node.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic final classOptional dataset input for FROM/FROM NAMED lines. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionconvertIRIToString(IRI iri) Convert a Var to a compact IRI string when it is bound to a constant IRI; otherwise return null.Dump raw IR (JSON) for debugging/tests.dumpIRTransformed(TupleExpr tupleExpr) Dump transformed IR (JSON) for debugging/tests.Backward-compatible: render as SELECT query (no dataset).render(TupleExpr tupleExpr, TupleExprIRRenderer.DatasetView dataset) SELECT with dataset (FROM/FROM NAMED).render(IrSelect ir, TupleExprIRRenderer.DatasetView dataset, boolean subselect) Render a textual SELECT query from anIrSelectmodel.renderAsk(TupleExpr tupleExpr, TupleExprIRRenderer.DatasetView dataset) ASK query (top-level).voidreset()toIRSelect(TupleExpr tupleExpr) Build a best‑effort textual IR for a SELECT‑form query.toIRSelectRaw(TupleExpr tupleExpr) Build IR without applying IR transforms (raw).
-
Constructor Details
-
TupleExprIRRenderer
public TupleExprIRRenderer() -
TupleExprIRRenderer
-
-
Method Details
-
reset
public void reset() -
toIRSelect
Build a best‑effort textual IR for a SELECT‑form query. Steps:- Normalize the TupleExpr (gather LIMIT/OFFSET/ORDER, peel wrappers, detect HAVING candidates).
- Translate the remaining WHERE tree into an IR block (
IrBGP) with simple, explicit nodes (statement patterns, path triples, filters, graphs, unions, etc.). - Apply the ordered IR transform pipeline (
IrTransforms.transformUsingChildren(IrSelect, TupleExprIRRenderer)) to perform purely-textual best‑effort fusions (paths, NPS, collections, property lists) while preserving user variable bindings. - Populate IR header sections (projection, group by, having, order by) from normalized metadata.
-
toIRSelectRaw
-
dumpIRRaw
-
dumpIRTransformed
-
render
Render a textual SELECT query from anIrSelectmodel. -
render
-
render
SELECT with dataset (FROM/FROM NAMED). -
renderAsk
ASK query (top-level). -
convertValueToString
-
convertIRIToString
-
convertVarIriToString
-