use of org.apache.jena.sparql.core.Var in project jena by apache.
the class ScopeBase method toString.
@Override
public String toString() {
String str = "";
String sep = "";
for (Var v : frame.keySet()) {
SqlColumn c = frame.get(v);
str = str + sep + v + ":" + c;
sep = " ";
}
if (parent != null)
str = str + "=>" + parent.toString();
return str;
}
use of org.apache.jena.sparql.core.Var in project jena by apache.
the class ScopeRename method findScopes.
@Override
public Set<ScopeEntry> findScopes() {
Set<ScopeEntry> x = new HashSet<ScopeEntry>();
for (Var v : frame.keySet()) {
ScopeEntry e = findScopeForVar(v);
x.add(e);
}
return x;
// Set<ScopeEntry> x = scope.findScopes() ;
// x = toSet(map(x, converter)) ;
// return x ;
}
use of org.apache.jena.sparql.core.Var in project jena by apache.
the class SlotCompiler method processSlot.
public final void processSlot(SDBRequest request, SqlTable table, SqlExprList conditions, Node node, String colName) {
SqlColumn thisCol = new SqlColumn(table, colName);
if (!node.isVariable()) {
constantSlot(request, node, thisCol, conditions);
return;
}
Var var = Var.alloc(node);
if (table.getIdScope().hasColumnForVar(var)) {
ScopeEntry e = table.getIdScope().findScopeForVar(var);
SqlColumn otherCol = e.getColumn();
SqlExpr c = new S_Equal(otherCol, thisCol);
conditions.add(c);
c.addNote("processVar: " + node);
return;
}
table.setIdColumnForVar(var, thisCol);
}
use of org.apache.jena.sparql.core.Var in project jena by apache.
the class GenerateSQLVisitor method visit.
@Override
public void visit(SqlCoalesce sqlNode) {
out.print("SELECT ");
boolean first = true;
SqlJoin join = sqlNode.getJoinNode();
// Rough draft code.
for (Var v : sqlNode.getCoalesceVars()) {
if (!first)
out.print(", ");
SqlColumn col = sqlNode.getIdScope().findScopeForVar(v).getColumn();
SqlColumn leftCol = join.getLeft().getIdScope().findScopeForVar(v).getColumn();
SqlColumn rightCol = join.getRight().getIdScope().findScopeForVar(v).getColumn();
out.print("COALESCE(");
out.print(leftCol.getFullColumnName());
out.print(", ");
out.print(rightCol.getFullColumnName());
out.print(")");
out.print(aliasToken());
out.print(col.getColumnName());
first = false;
}
for (Var v : sqlNode.getNonCoalesceVars()) {
if (!first)
out.print(", ");
first = false;
// Need generated names.
SqlColumn colSub = join.getIdScope().findScopeForVar(v).getColumn();
SqlColumn col = sqlNode.getIdScope().findScopeForVar(v).getColumn();
out.print(colSub.getFullColumnName());
out.print(aliasToken());
out.print(col.getColumnName());
}
out.ensureStartOfLine();
// INC
out.incIndent();
out.println("FROM");
join.visit(this);
out.ensureStartOfLine();
// Alias and annotations handled by outputNode
}
use of org.apache.jena.sparql.core.Var in project jena by apache.
the class SqlRename method merge.
// Map all vars in the scope to names in the rename.
private void merge(Scope scope, ScopeBase newScope, Generator gen) {
String x = "";
String sep = "";
for (ScopeEntry e : scope.findScopes()) {
SqlColumn oldCol = e.getColumn();
Var v = e.getVar();
String colName = gen.next();
SqlColumn newCol = new SqlColumn(vTable, colName);
columns.add(new ColAlias(oldCol, newCol));
newScope.setColumnForVar(v, newCol);
// Annotations
x = String.format("%s%s%s:(%s=>%s)", x, sep, v, oldCol, newCol);
sep = " ";
}
if (x.length() > 0)
addNote(x);
}
Aggregations