use of org.apache.jena.sdb.core.sqlexpr.SqlColumn 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);
}
use of org.apache.jena.sdb.core.sqlexpr.SqlColumn in project jena by apache.
the class SqlSelectBlock method merge.
// Calculate renames
// 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);
this.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);
}
use of org.apache.jena.sdb.core.sqlexpr.SqlColumn in project jena by apache.
the class SQLBridge2 method insertValueGetter.
private SqlNode insertValueGetter(SDBRequest request, SqlNode sqlNode, Var var) {
ScopeEntry e1 = sqlNode.getIdScope().findScopeForVar(var);
if (e1 == null) {
// Debug.
Scope scope = sqlNode.getIdScope();
// Variable not actually in results.
return sqlNode;
}
// Already in scope (from a condition)?
ScopeEntry e2 = sqlNode.getNodeScope().findScopeForVar(var);
if (e2 != null)
// Already there
return sqlNode;
SqlColumn c1 = e1.getColumn();
// Not in scope -- add a table to get it
TableDescNodes nodeTableDesc = request.getStore().getNodeTableDesc();
String tableAlias = request.genId(NodeBase);
SqlTable nTable = new SqlTable(tableAlias, nodeTableDesc.getTableName());
String nodeKeyColName = nodeTableDesc.getNodeRefColName();
SqlColumn c2 = new SqlColumn(nTable, nodeKeyColName);
nTable.setValueColumnForVar(var, c2);
// Condition for value: triple table column = node table id/hash
nTable.addNote("Var: " + var);
SqlExpr cond = new S_Equal(c1, c2);
SqlNode n = SqlBuilder.leftJoin(request, sqlNode, nTable, cond);
return n;
}
use of org.apache.jena.sdb.core.sqlexpr.SqlColumn in project jena by apache.
the class SqlSelectBlock method _add.
private void _add(ColAlias c) {
SqlColumn col = c.getColumn();
SqlColumn aliasCol = c.getAlias();
c.check(getAliasName());
//
// if ( aliasCol.getTable() != null && aliasCol.getTable().getAliasName().equals(getAliasName()) )
// throw new SDBInternalError("Attempt to project to a column with different alias: "+col+" -> "+aliasCol) ;
cols.add(c);
}
use of org.apache.jena.sdb.core.sqlexpr.SqlColumn in project jena by apache.
the class GenerateSQLVisitor method rewrite.
public SqlJoinInner rewrite(SqlJoinInner join) {
if (!join.getRight().isInnerJoin())
return join;
// if ( join(A, join(B, C)) ) rewrite as join(join(A,B),C)
// this then is written without brackets (and so scope changing)
// TODO abstract as organiseJoin(List<join elements>)
// and remember to do top down to find maximal join trees
SqlJoinInner right = join.getRight().asInnerJoin();
String alias1 = join.getAliasName();
String alias2 = right.getAliasName();
SqlNode sn_a = join.getLeft();
SqlNode sn_b = right.getLeft();
SqlNode sn_c = right.getRight();
SqlExprList conditions = new SqlExprList(join.getConditions());
conditions.addAll(right.getConditions());
Set<SqlTable> tables_ab = sn_a.tablesInvolved();
tables_ab.addAll(sn_b.tablesInvolved());
// Goes to new join(A,B)
SqlExprList newCond_ab = new SqlExprList();
// Goes to new join(,C)
SqlExprList newCond_c = new SqlExprList();
// Place conditions
for (SqlExpr e : conditions) {
Set<SqlColumn> cols = e.getColumnsNeeded();
// columns to tables.
Set<SqlTable> tables = tables(cols);
// Are the tables contained in tables_ab?
tables.removeAll(tables_ab);
if (tables.size() == 0)
newCond_ab.add(e);
else
newCond_c.add(e);
}
if (newCond_ab.size() + newCond_c.size() != conditions.size())
log.error(String.format("Conditions mismatch: (%d,%d,%d)", newCond_ab.size(), newCond_c.size(), conditions.size()));
SqlJoinInner join2 = new SqlJoinInner(sn_a, sn_b);
join2.addConditions(newCond_ab);
join2 = new SqlJoinInner(join2, sn_c);
join2.addConditions(newCond_c);
return join2;
}
Aggregations