@Override public boolean equals(Object other) { if (other instanceof ProjectionElem) { ProjectionElem o = (ProjectionElem)other; return sourceName.equals(o.getSourceName()) && targetName.equals(o.getTargetName()); } return false; }
private boolean addBindingNames(StringBuilder builder, boolean alreadyMapping, Map<String, String> bindings, ProjectionElemList list, String name) { boolean mapping = alreadyMapping; if (variables.containsKey(name)) { String var = variables.get(name); builder.append(" ?").append(var); bindings.put(name, var); list.addElement(new ProjectionElem(var, name)); if (!name.equals(var)) { mapping = true; } } return mapping; }
@Override public void meet(ProjectionElem projElem) throws RuntimeException { if (projElem.getSourceName().equals(oldName)) { projElem.setSourceName(newName); } } }
public ProjectionElem(String sourceName, String targetName) { setSourceName(sourceName); setTargetName(targetName); }
.getProjectionElemList().getElements(); final boolean isConstruct = projections.size() >= 3 && "subject".equals(projections.get(0).getTargetName()) && "predicate".equals(projections.get(1).getTargetName()) && "object".equals(projections.get(2).getTargetName()) && (projections.size() == 3 || projections.size() == 4 && "context".equals(projections.get(3).getTargetName())); if (isConstruct && !forceSelect) { form = Form.CONSTRUCT; form = form == null ? Form.SELECT : form; for (final ProjectionElem projection : projections) { final String variable = projection.getTargetName(); ExtensionElem extension = extensions.get(variable); if (extension == null && projection.getSourceName() != null) { extension = extensions.get(projection.getSourceName()); final ProjectionElem newProjection = new ProjectionElem(); newProjection.setTargetName(variable); newProjection.setSourceExpression(extension); newProjection.setSourceName(extension == null || !(extension.getExpr() instanceof Var) ? projection .getSourceName() : ((Var) extension.getExpr()).getName()); select.add(newProjection); for (final String variableName : group.getGroupBindingNames()) { final ExtensionElem extension = extensions.get(variableName); final ProjectionElem projection = new ProjectionElem(); projection.setTargetName(variableName);
ProjectionElem elem = new ProjectionElem(sourceName, targetName); projElemList.addElement(elem); elem.setAggregateOperatorInExpression(true); for (AggregateOperator operator : collector.getOperators()) { elem.setSourceExpression(extElem); ProjectionElem elem = new ProjectionElem(projVar.getName()); projElemList.addElement(elem); ExtensionElem extElem = new ExtensionElem(projVar, projVar.getName()); extension.addElement(extElem); elem.setSourceExpression(extElem); if (!elem.hasAggregateOperatorInExpression()) { Set<String> groupNames = group.getBindingNames(); ExtensionElem extElem = elem.getSourceExpression(); if (extElem != null) { ValueExpr expr = extElem.getExpr(); if (!groupNames.contains(elem.getTargetName())) { throw new VisitorException("variable '" + elem.getTargetName() + "' in projection not present in GROUP BY."); else if (!groupNames.contains(elem.getSourceName())) { throw new VisitorException("variable '" + elem.getSourceName() + "' in projection not present in GROUP BY.");
private static VariableOrder getConstructGraphVarOrder(final List<ProjectionElemList> projections) { final Set<String> varOrders = new HashSet<>(); for(final ProjectionElemList elems: projections) { for(final ProjectionElem elem: elems.getElements()) { final String name = elem.getSourceName(); if(!name.startsWith("-const-") && !name.startsWith("-anon-")) { varOrders.add(name); } } } return new VariableOrder(varOrders); }
@Override public void meet(final ProjectionElem n) { final String source = n.getSourceName(); final String target = n.getTargetName(); final ValueExpr expr = n.getSourceExpression() == null ? null : n .getSourceExpression().getExpr(); if (target.startsWith("-")) { if (expr != null) { emit("(").emit(expr).emit(" AS ?").emit(sanitize(target)).emit(")"); } } else if (expr != null) { emit("(").emit(expr).emit(" AS ?").emit(target).emit(")"); } else if (!equalOrNull(source, target)) { emit("(?").emit(source).emit(" AS ?").emit(target).emit(")"); } else { emit("?").emit(target); } }
@Override public void meet(ProjectionElemList node) { List<ProjectionElem> proj = node.getElements(); for (ProjectionElem s : proj) { if (varChanges.containsKey(s.getSourceName())) { String name = s.getSourceName(); s.setSourceName(varChanges.get(name)); s.setTargetName(varChanges.get(name)); } } }
@Override public void meet(final GroupElem n) { final ProjectionElem e = new ProjectionElem(); e.setTargetName(n.getName()); e.setSourceName(n.getName()); e.setSourceExpression(new ExtensionElem(n.getOperator(), n.getName())); meet(e); }
emit("DESCRIBE"); for (final ProjectionElem p : query.select) { final ExtensionElem e = p.getSourceExpression(); emit(" ").emit( e != null && e.getExpr() instanceof ValueConstant ? e.getExpr() : p); newline().emit("GROUP BY"); for (final ProjectionElem n : query.groupBy) { emit(" ?").emit(n.getTargetName());
public Set<String> getTargetNames() { Set<String> targetNames = new LinkedHashSet<String>(elements.size()); for (ProjectionElem pe : elements) { targetNames.add(pe.getTargetName()); } return targetNames; }
ProjectionElem projElem = new ProjectionElem(varName, projName); projElem.setSourceExpression(new ExtensionElem(valueExpr, varName)); if (!aggregates.isEmpty()) { projElem.setAggregateOperatorInExpression(true); if (group == null) { group = new Group();
private Var createVar(String varName) { if (projElems != null) { ProjectionElem projElem = projElems.get(varName); if (projElem != null) { ExtensionElem extElem = projElem.getSourceExpression(); if (extElem != null && extElem.getExpr() instanceof Var) { projElem.setSourceExpression(null); } } } return new Var(varName); } }
private void addSourceExpressions(UnaryTupleOperator op, Collection<ProjectionElem> elems) { Extension ext = null; for (ProjectionElem projElem : elems) { ExtensionElem extElem = projElem.getSourceExpression(); if (extElem != null) { if (ext == null) { ext = new Extension(op.getArg()); op.setArg(ext); } ext.addElement(extElem); } } }
.getProjectionElemList().getElements(); final boolean isConstruct = projections.size() >= 3 && "subject".equals(projections.get(0).getTargetName()) && "predicate".equals(projections.get(1).getTargetName()) && "object".equals(projections.get(2).getTargetName()) && (projections.size() == 3 || projections.size() == 4 && "context".equals(projections.get(3).getTargetName())); if (isConstruct && !forceSelect) { form = Form.CONSTRUCT; form = form == null ? Form.SELECT : form; for (final ProjectionElem projection : projections) { final String variable = projection.getTargetName(); ExtensionElem extension = extensions.get(variable); if (extension == null && projection.getSourceName() != null) { extension = extensions.get(projection.getSourceName()); final ProjectionElem newProjection = new ProjectionElem(); newProjection.setTargetName(variable); newProjection.setSourceExpression(extension); newProjection.setSourceName(extension == null || !(extension.getExpr() instanceof Var) ? projection .getSourceName() : ((Var) extension.getExpr()).getName()); select.add(newProjection); for (final String variableName : group.getGroupBindingNames()) { final ExtensionElem extension = extensions.get(variableName); final ProjectionElem projection = new ProjectionElem(); projection.setTargetName(variableName);
private Set<String> getProjectedVariables(TupleExpr expr) { if(expr instanceof Projection) { Projection projection = (Projection)expr; Set<String> projectedVars = new HashSet<>(); for (ProjectionElem elem : projection.getProjectionElemList().getElements()) { projectedVars.add(elem.getSourceName()); } return projectedVars; } else { return Collections.EMPTY_SET; } } }
@Override public void meet(final ProjectionElem n) { final String source = n.getSourceName(); final String target = n.getTargetName(); final ValueExpr expr = n.getSourceExpression() == null ? null : n .getSourceExpression().getExpr(); if (target.startsWith("-")) { if (expr != null) { emit("(").emit(expr).emit(" AS ?").emit(sanitize(target)).emit(")"); } } else if (expr != null) { emit("(").emit(expr).emit(" AS ?").emit(target).emit(")"); } else if (!equalOrNull(source, target)) { emit("(?").emit(source).emit(" AS ?").emit(target).emit(")"); } else { emit("?").emit(target); } }
@Override public void meet(final GroupElem n) { final ProjectionElem e = new ProjectionElem(); e.setTargetName(n.getName()); e.setSourceName(n.getName()); e.setSourceExpression(new ExtensionElem(n.getOperator(), n.getName())); meet(e); }
emit("DESCRIBE"); for (final ProjectionElem p : query.select) { final ExtensionElem e = p.getSourceExpression(); emit(" ").emit( e != null && e.getExpr() instanceof ValueConstant ? e.getExpr() : p); newline().emit("GROUP BY"); for (final ProjectionElem n : query.groupBy) { emit(" ?").emit(n.getTargetName());