Skip to content

Commit

Permalink
apacheGH-1615: LATERAL for jena-querybuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
afs committed Nov 19, 2022
1 parent d633fdb commit c0509b1
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,7 @@
import java.util.List;

import org.apache.jena.arq.querybuilder.handlers.WhereHandler;
import org.apache.jena.sparql.syntax.Element;
import org.apache.jena.sparql.syntax.ElementAssign;
import org.apache.jena.sparql.syntax.ElementBind;
import org.apache.jena.sparql.syntax.ElementData;
import org.apache.jena.sparql.syntax.ElementDataset;
import org.apache.jena.sparql.syntax.ElementExists;
import org.apache.jena.sparql.syntax.ElementFilter;
import org.apache.jena.sparql.syntax.ElementGroup;
import org.apache.jena.sparql.syntax.ElementMinus;
import org.apache.jena.sparql.syntax.ElementNamedGraph;
import org.apache.jena.sparql.syntax.ElementNotExists;
import org.apache.jena.sparql.syntax.ElementOptional;
import org.apache.jena.sparql.syntax.ElementPathBlock;
import org.apache.jena.sparql.syntax.ElementService;
import org.apache.jena.sparql.syntax.ElementSubQuery;
import org.apache.jena.sparql.syntax.ElementTriplesBlock;
import org.apache.jena.sparql.syntax.ElementUnion;
import org.apache.jena.sparql.syntax.ElementVisitor;
import org.apache.jena.sparql.syntax.*;

/**
* An element visitor that does an in-place modification of the elements to fix
Expand Down Expand Up @@ -114,6 +97,17 @@ public void visit(ElementUnion el) {
}
}

@Override
public void visit(ElementLateral el) {
el.getLateralElement().visit(this);
if (result == el.getLateralElement()) {
result = el;
} else {
result = new ElementOptional(result);
}
}


@Override
public void visit(ElementOptional el) {
el.getOptionalElement().visit(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,7 @@
import org.apache.jena.sparql.core.TriplePath;
import org.apache.jena.sparql.core.Var;
import org.apache.jena.sparql.engine.binding.Binding;
import org.apache.jena.sparql.syntax.Element;
import org.apache.jena.sparql.syntax.ElementAssign;
import org.apache.jena.sparql.syntax.ElementBind;
import org.apache.jena.sparql.syntax.ElementData;
import org.apache.jena.sparql.syntax.ElementDataset;
import org.apache.jena.sparql.syntax.ElementExists;
import org.apache.jena.sparql.syntax.ElementFilter;
import org.apache.jena.sparql.syntax.ElementGroup;
import org.apache.jena.sparql.syntax.ElementMinus;
import org.apache.jena.sparql.syntax.ElementNamedGraph;
import org.apache.jena.sparql.syntax.ElementNotExists;
import org.apache.jena.sparql.syntax.ElementOptional;
import org.apache.jena.sparql.syntax.ElementPathBlock;
import org.apache.jena.sparql.syntax.ElementService;
import org.apache.jena.sparql.syntax.ElementSubQuery;
import org.apache.jena.sparql.syntax.ElementTriplesBlock;
import org.apache.jena.sparql.syntax.ElementUnion;
import org.apache.jena.sparql.syntax.ElementVisitor;
import org.apache.jena.sparql.syntax.*;

/**
* A rewriter that implements an ElementVisitor
Expand All @@ -54,7 +37,7 @@ public class ElementRewriter extends AbstractRewriter<Element> implements Elemen

/**
* Constructor
*
*
* @param values The values to rewrite with.
*/
public ElementRewriter(Map<Var, Node> values) {
Expand Down Expand Up @@ -140,6 +123,12 @@ public void visit(ElementUnion el) {
push(retval);
}

@Override
public void visit(ElementLateral el) {
el.getLateralElement().visit(this);
push(new ElementLateral(getResult()));
}

@Override
public void visit(ElementOptional el) {
el.getOptionalElement().visit(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,46 +27,9 @@
import org.apache.jena.sparql.algebra.Op;
import org.apache.jena.sparql.algebra.OpVisitor;
import org.apache.jena.sparql.algebra.Table;
import org.apache.jena.sparql.algebra.op.OpAssign;
import org.apache.jena.sparql.algebra.op.OpBGP;
import org.apache.jena.sparql.algebra.op.OpConditional;
import org.apache.jena.sparql.algebra.op.OpDatasetNames;
import org.apache.jena.sparql.algebra.op.OpDiff;
import org.apache.jena.sparql.algebra.op.OpDisjunction;
import org.apache.jena.sparql.algebra.op.OpDistinct;
import org.apache.jena.sparql.algebra.op.OpExt;
import org.apache.jena.sparql.algebra.op.OpExtend;
import org.apache.jena.sparql.algebra.op.OpFilter;
import org.apache.jena.sparql.algebra.op.OpGraph;
import org.apache.jena.sparql.algebra.op.OpGroup;
import org.apache.jena.sparql.algebra.op.OpJoin;
import org.apache.jena.sparql.algebra.op.OpLabel;
import org.apache.jena.sparql.algebra.op.OpLeftJoin;
import org.apache.jena.sparql.algebra.op.OpList;
import org.apache.jena.sparql.algebra.op.OpMinus;
import org.apache.jena.sparql.algebra.op.OpNull;
import org.apache.jena.sparql.algebra.op.OpOrder;
import org.apache.jena.sparql.algebra.op.OpPath;
import org.apache.jena.sparql.algebra.op.OpProcedure;
import org.apache.jena.sparql.algebra.op.OpProject;
import org.apache.jena.sparql.algebra.op.OpPropFunc;
import org.apache.jena.sparql.algebra.op.OpQuad;
import org.apache.jena.sparql.algebra.op.OpQuadBlock;
import org.apache.jena.sparql.algebra.op.OpQuadPattern;
import org.apache.jena.sparql.algebra.op.OpReduced;
import org.apache.jena.sparql.algebra.op.OpSequence;
import org.apache.jena.sparql.algebra.op.OpService;
import org.apache.jena.sparql.algebra.op.OpSlice;
import org.apache.jena.sparql.algebra.op.OpTable;
import org.apache.jena.sparql.algebra.op.OpTopN;
import org.apache.jena.sparql.algebra.op.OpTriple;
import org.apache.jena.sparql.algebra.op.OpUnion;
import org.apache.jena.sparql.algebra.op.*;
import org.apache.jena.sparql.algebra.table.TableN;
import org.apache.jena.sparql.core.BasicPattern;
import org.apache.jena.sparql.core.Quad;
import org.apache.jena.sparql.core.QuadPattern;
import org.apache.jena.sparql.core.Var;
import org.apache.jena.sparql.core.VarExprList;
import org.apache.jena.sparql.core.*;
import org.apache.jena.sparql.engine.binding.Binding;
import org.apache.jena.sparql.expr.ExprAggregator;
import org.apache.jena.sparql.expr.ExprList;
Expand All @@ -80,7 +43,7 @@ class OpRewriter extends AbstractRewriter<Op> implements OpVisitor {

/**
* Constructor.
*
*
* @param values The values to replace.
*/
OpRewriter(Map<Var, Node> values) {
Expand Down Expand Up @@ -275,6 +238,13 @@ public void visit(OpMinus opMinus) {
push(OpMinus.create(pop(), pop()));
}

@Override
public void visit(OpLateral opLateral) {
opLateral.getRight().visit(this);
opLateral.getLeft().visit(this);
push(OpLateral.create(pop(), pop()));
}

@Override
public void visit(OpConditional opCondition) {
opCondition.getRight().visit(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,7 @@
import org.apache.jena.query.QueryParseException;
import org.apache.jena.sparql.core.Quad;
import org.apache.jena.sparql.core.TriplePath;
import org.apache.jena.sparql.syntax.Element;
import org.apache.jena.sparql.syntax.ElementAssign;
import org.apache.jena.sparql.syntax.ElementBind;
import org.apache.jena.sparql.syntax.ElementData;
import org.apache.jena.sparql.syntax.ElementDataset;
import org.apache.jena.sparql.syntax.ElementExists;
import org.apache.jena.sparql.syntax.ElementFilter;
import org.apache.jena.sparql.syntax.ElementGroup;
import org.apache.jena.sparql.syntax.ElementMinus;
import org.apache.jena.sparql.syntax.ElementNamedGraph;
import org.apache.jena.sparql.syntax.ElementNotExists;
import org.apache.jena.sparql.syntax.ElementOptional;
import org.apache.jena.sparql.syntax.ElementPathBlock;
import org.apache.jena.sparql.syntax.ElementService;
import org.apache.jena.sparql.syntax.ElementSubQuery;
import org.apache.jena.sparql.syntax.ElementTriplesBlock;
import org.apache.jena.sparql.syntax.ElementUnion;
import org.apache.jena.sparql.syntax.ElementVisitor;
import org.apache.jena.sparql.syntax.*;
import org.apache.jena.util.iterator.ExtendedIterator;
import org.apache.jena.util.iterator.WrappedIterator;

Expand All @@ -69,7 +52,7 @@ public Quad apply(Triple triple) {

/**
* Constructor.
*
*
* @param defaultGraph the default graph name.
*/
QuadIteratorBuilder(Node defaultGraph) {
Expand Down Expand Up @@ -120,6 +103,11 @@ public void visit(ElementUnion el) {
}
}

@Override
public void visit(ElementLateral el) {
throw new QueryParseException("lateral not permitted in data quad", -1, -1);
}

@Override
public void visit(ElementOptional el) {
throw new QueryParseException("optional not permitted in data quad", -1, -1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,7 @@

import java.util.List;

import org.apache.jena.sparql.syntax.Element;
import org.apache.jena.sparql.syntax.ElementAssign;
import org.apache.jena.sparql.syntax.ElementBind;
import org.apache.jena.sparql.syntax.ElementData;
import org.apache.jena.sparql.syntax.ElementDataset;
import org.apache.jena.sparql.syntax.ElementExists;
import org.apache.jena.sparql.syntax.ElementFilter;
import org.apache.jena.sparql.syntax.ElementGroup;
import org.apache.jena.sparql.syntax.ElementMinus;
import org.apache.jena.sparql.syntax.ElementNamedGraph;
import org.apache.jena.sparql.syntax.ElementNotExists;
import org.apache.jena.sparql.syntax.ElementOptional;
import org.apache.jena.sparql.syntax.ElementPathBlock;
import org.apache.jena.sparql.syntax.ElementService;
import org.apache.jena.sparql.syntax.ElementSubQuery;
import org.apache.jena.sparql.syntax.ElementTriplesBlock;
import org.apache.jena.sparql.syntax.ElementUnion;
import org.apache.jena.sparql.syntax.ElementVisitor;
import org.apache.jena.sparql.syntax.*;
import org.apache.jena.sparql.util.NodeIsomorphismMap;

/**
Expand Down Expand Up @@ -131,6 +114,14 @@ public void visit(ElementUnion el) {
return;
}

@Override
public void visit(ElementLateral el) {
checkMatching(el);
if (!matching) {
el.getLateralElement().visit(this);
}
}

@Override
public void visit(ElementOptional el) {
checkMatching(el);
Expand Down

0 comments on commit c0509b1

Please sign in to comment.