use of org.eclipse.rdf4j.query.algebra.TupleExpr in project rdf4j by eclipse.
the class QueryModelBuilder method visit.
@Override
public Object visit(ASTPathExprUnion node, Object data) throws VisitorException {
Iterator<ASTPathExpr> args = node.getPathExprList().iterator();
// Create new sub-graph pattern for optional path expressions
TupleExpr unionExpr = parseGraphPattern(args.next()).buildTupleExpr();
while (args.hasNext()) {
TupleExpr argExpr = parseGraphPattern(args.next()).buildTupleExpr();
unionExpr = new Union(unionExpr, argExpr);
}
graphPattern.addRequiredTE(unionExpr);
return null;
}
use of org.eclipse.rdf4j.query.algebra.TupleExpr in project rdf4j by eclipse.
the class TupleExprBuilder method visit.
@Override
public Group visit(ASTGroupClause node, Object data) throws VisitorException {
TupleExpr tupleExpr = (TupleExpr) data;
Group g = new Group(tupleExpr);
int childCount = node.jjtGetNumChildren();
List<String> groupBindingNames = new ArrayList<String>();
for (int i = 0; i < childCount; i++) {
String name = (String) node.jjtGetChild(i).jjtAccept(this, g);
groupBindingNames.add(name);
}
g.setGroupBindingNames(groupBindingNames);
return g;
}
use of org.eclipse.rdf4j.query.algebra.TupleExpr in project rdf4j by eclipse.
the class TupleExprBuilder method visit.
@Override
public TupleExpr visit(ASTDescribeQuery node, Object data) throws VisitorException {
TupleExpr tupleExpr = null;
if (node.getWhereClause() != null) {
// Start with building the graph pattern
graphPattern = new GraphPattern();
node.getWhereClause().jjtAccept(this, null);
tupleExpr = graphPattern.buildTupleExpr();
// Apply grouping
Group group = null;
ASTGroupClause groupNode = node.getGroupClause();
if (groupNode != null) {
tupleExpr = (TupleExpr) groupNode.jjtAccept(this, tupleExpr);
group = (Group) tupleExpr;
}
if (node.getHavingClause() != null) {
if (group == null) {
// create implicit group
group = new Group(tupleExpr);
}
// Apply HAVING group filter condition
tupleExpr = processHavingClause(node.getHavingClause(), tupleExpr, group);
}
if (node.getOrderClause() != null) {
if (group == null) {
// create implicit group
group = new Group(tupleExpr);
}
// Apply result ordering
tupleExpr = processOrderClause(node.getOrderClause(), tupleExpr, group);
}
// Process limit and offset clauses
ASTLimit limitNode = node.getLimit();
long limit = -1;
if (limitNode != null) {
limit = (Long) limitNode.jjtAccept(this, null);
}
ASTOffset offsetNode = node.getOffset();
long offset = -1;
if (offsetNode != null) {
offset = (Long) offsetNode.jjtAccept(this, null);
}
if (offset >= 1 || limit >= 0) {
tupleExpr = new Slice(tupleExpr, offset, limit);
}
}
// Process describe clause last
return (TupleExpr) node.getDescribe().jjtAccept(this, tupleExpr);
}
use of org.eclipse.rdf4j.query.algebra.TupleExpr in project rdf4j by eclipse.
the class TupleExprBuilder method visit.
@Override
public String visit(ASTGroupCondition node, Object data) throws VisitorException {
Group group = (Group) data;
TupleExpr arg = group.getArg();
Extension extension = null;
if (arg instanceof Extension) {
extension = (Extension) arg;
} else {
extension = new Extension();
}
String name = null;
ValueExpr ve = (ValueExpr) node.jjtGetChild(0).jjtAccept(this, data);
boolean aliased = false;
if (node.jjtGetNumChildren() > 1) {
aliased = true;
Var v = (Var) node.jjtGetChild(1).jjtAccept(this, data);
name = v.getName();
} else {
if (ve instanceof Var) {
name = ((Var) ve).getName();
} else {
aliased = true;
Var v = createAnonVar();
name = v.getName();
}
}
if (aliased) {
ExtensionElem elem = new ExtensionElem(ve, name);
extension.addElement(elem);
}
if (extension.getElements().size() > 0 && !(arg instanceof Extension)) {
extension.setArg(arg);
group.setArg(extension);
}
return name;
}
use of org.eclipse.rdf4j.query.algebra.TupleExpr in project rdf4j by eclipse.
the class TupleExprBuilder method visit.
@Override
public TupleExpr visit(ASTSelectQuery node, Object data) throws VisitorException {
GraphPattern parentGP = graphPattern;
// Start with building the graph pattern
graphPattern = new GraphPattern(parentGP);
node.getWhereClause().jjtAccept(this, null);
TupleExpr tupleExpr = graphPattern.buildTupleExpr();
// Apply grouping
Group group = null;
ASTGroupClause groupNode = node.getGroupClause();
if (groupNode != null) {
tupleExpr = (TupleExpr) groupNode.jjtAccept(this, tupleExpr);
group = (Group) tupleExpr;
}
final ASTHavingClause havingClause = node.getHavingClause();
if (havingClause != null) {
if (group == null) {
// create implicit group
group = new Group(tupleExpr);
}
// Apply HAVING group filter condition
tupleExpr = processHavingClause(havingClause, tupleExpr, group);
}
// process bindings clause
final ASTBindingsClause bindingsClause = node.getBindingsClause();
if (bindingsClause != null) {
tupleExpr = new Join((BindingSetAssignment) bindingsClause.jjtAccept(this, null), tupleExpr);
}
final ASTOrderClause orderClause = node.getOrderClause();
if (orderClause != null) {
if (group == null) {
// create implicit group
group = new Group(tupleExpr);
}
// Apply result ordering
tupleExpr = processOrderClause(node.getOrderClause(), tupleExpr, group);
}
// Apply projection
tupleExpr = (TupleExpr) node.getSelect().jjtAccept(this, tupleExpr);
// Process limit and offset clauses
ASTLimit limitNode = node.getLimit();
long limit = -1L;
if (limitNode != null) {
limit = (Long) limitNode.jjtAccept(this, null);
}
ASTOffset offsetNode = node.getOffset();
long offset = -1L;
if (offsetNode != null) {
offset = (Long) offsetNode.jjtAccept(this, null);
}
if (offset >= 1L || limit >= 0L) {
tupleExpr = new Slice(tupleExpr, offset, limit);
}
if (parentGP != null) {
parentGP.addRequiredTE(tupleExpr);
graphPattern = parentGP;
}
return tupleExpr;
}
Aggregations