use of org.apache.jena.sdb.core.sqlexpr.SqlColumn in project jena by apache.
the class TransformSDB method transform.
// Now done in QueryCompilerMain at a later stage.
// @Override
// public Op transform(OpSlice opSlice, Op subOp)
// {
// if ( ! request.LimitOffsetTranslation )
// return super.transform(opSlice, subOp) ;
//
// // Not a slice of SQL
// if ( ! SDB_QC.isOpSQL(subOp) )
// return super.transform(opSlice, subOp) ;
//
// // Two cases are currently handled:
// // (slice (project (sql expression)))
// // (slice (sql expression))
//
// if ( isProject(opSlice.getSubOp()) )
// // This should not happen because the pre-transform done in QueryEngineMain
// // rewrites the case into the equivalent (project (slice ...))
// return transformSliceProject(opSlice, (OpSQL)subOp, ((OpSQL)subOp).getSqlNode()) ;
//
// // (slice (sql expression))
// return transformSlice(opSlice, ((OpSQL)subOp).getSqlNode()) ;
// }
//
// private Op transformSlice(OpSlice opSlice, SqlNode sqlSubOp)
// {
// SqlNode n = SqlSelectBlock.slice(request, sqlSubOp, opSlice.getStart(), opSlice.getLength()) ;
// OpSQL x = new OpSQL(n, opSlice, request) ;
// return x ;
// }
//
// private Op transformSliceProject(OpSlice opSlice, OpSQL subOp, SqlNode sqlOp)
// {
// // This put the LIMIT outside all the projects left joins, which is a bit of a pity.
// // Could improve by rewriting (slice (project...)) into (project (slice...)) in QueryCompilerMain
// OpSQL x = (OpSQL)transformSlice(opSlice, sqlOp) ;
// SQLBridge bridge = subOp.getBridge() ;
// return x ;
// }
// // ----
//
// private boolean translateConstraints = true ;
//
// private SDBConstraint transformFilter(OpFilter opFilter)
// {
// if ( ! translateConstraints )
// return null ;
//
// ExprList exprs = opFilter.getExprs() ;
// List<Expr> x = exprs.getList() ;
// for ( Expr expr : x )
// {
// ConditionCompiler cc = new RegexCompiler() ;
// SDBConstraint psc = cc.recognize(expr) ;
// if ( psc != null )
// return psc ;
// }
// return null ;
// }
//
// private Set<Var> getVarsInFilter(Expr expr)
// {
// Set<Var> vars = expr.getVarsMentioned() ;
// return vars ;
// }
@Override
public Op transform(OpDatasetNames opDatasetNames) {
if (false)
return super.transform(opDatasetNames);
// Basically, an implementation of "GRAPH ?g {}"
Node g = opDatasetNames.getGraphNode();
if (!Var.isVar(g))
throw new SDBInternalError("OpDatasetNames - not a variable: " + g);
Var v = Var.alloc(g);
// Inner SELECT SQL: (SELECT DISTINCT g FROM Quads)
TableDescQuads quads = request.getStore().getQuadTableDesc();
SqlTable sqlTableQ = new SqlTable(quads.getTableName());
sqlTableQ.setIdColumnForVar(v, new SqlColumn(sqlTableQ, quads.getGraphColName()));
SqlNode sqlNodeQ = SqlSelectBlock.distinct(request, sqlTableQ);
// Will have the value left join added later.
return new OpSQL(sqlNodeQ, opDatasetNames, request);
}
use of org.apache.jena.sdb.core.sqlexpr.SqlColumn 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.sdb.core.sqlexpr.SqlColumn 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.sdb.core.sqlexpr.SqlColumn 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.sdb.core.sqlexpr.SqlColumn in project jena by apache.
the class SqlProject method project.
/** make sure this node is a projection and add a column */
/*public*/
private static SqlNode project(SqlNode sqlNode, SqlColumn col, String colOutName) {
SqlColumn asCol = new SqlColumn(null, colOutName);
ColAlias colAlias = new ColAlias(col, asCol);
return SqlProject.project(sqlNode, colAlias);
}
Aggregations