|
28 | 28 |
|
29 | 29 | import org.apache.jena.atlas.iterator.Iter ;
|
30 | 30 | import org.apache.jena.graph.Node ;
|
| 31 | +import org.apache.jena.query.SortCondition; |
31 | 32 | import org.apache.jena.sdb.core.AliasesSql ;
|
32 | 33 | import org.apache.jena.sdb.core.SDBRequest ;
|
33 | 34 | import org.apache.jena.sdb.core.ScopeEntry ;
|
|
43 | 44 | import org.apache.jena.sparql.algebra.TransformCopy ;
|
44 | 45 | import org.apache.jena.sparql.algebra.op.* ;
|
45 | 46 | import org.apache.jena.sparql.core.Var ;
|
| 47 | +import org.apache.jena.sparql.expr.ExprAggregator; |
| 48 | +import org.apache.jena.sparql.expr.ExprVar; |
46 | 49 | import org.slf4j.Logger ;
|
47 | 50 | import org.slf4j.LoggerFactory ;
|
48 | 51 |
|
@@ -190,24 +193,56 @@ public Op transform(OpDistinct opDistinct, Op subOp)
|
190 | 193 |
|
191 | 194 | @Override
|
192 | 195 | public Op transform(OpProject opProject, Op subOp)
|
193 |
| - { |
| 196 | + { |
| 197 | + // If the an OpOrder has been pushed onto an SQL Op |
| 198 | + if (opProject.getSubOp() instanceof OpOrder && SDB_QC.isOpSQL(subOp) ) { |
| 199 | + // Just return an update Project, without a bridge |
| 200 | + return opProject.copy(subOp); |
| 201 | + } |
| 202 | + |
194 | 203 | //request.getStore().getSQLBridgeFactory().create(request, null, null)
|
195 | 204 | if ( ! SDB_QC.isOpSQL(subOp) )
|
196 | 205 | return super.transform(opProject, subOp) ;
|
197 |
| - |
| 206 | + |
198 | 207 | // Need to not do bridge elsewhere.
|
199 |
| - List<Var> vars = opProject.getVars() ; |
200 |
| - return doBridge(request, (OpSQL)subOp, vars, opProject) ; |
| 208 | + List<Var> vars = opProject.getVars(); |
| 209 | + return doBridge(request, (OpSQL) subOp, vars, opProject); |
201 | 210 | }
|
202 |
| - |
| 211 | + |
| 212 | + @Override |
| 213 | + public Op transform(OpOrder opOrder, Op subOp) { |
| 214 | + if (request.OrderTranslation) { |
| 215 | + // If this Order has an OpSQL child |
| 216 | + if (SDB_QC.isOpSQL(subOp)) { |
| 217 | + // Check that all of the SortConditions are simple variable expressions |
| 218 | + boolean orderInSQL = true; |
| 219 | + for (SortCondition sc : opOrder.getConditions()) { |
| 220 | + if (!(sc.getExpression() instanceof ExprVar)) { |
| 221 | + orderInSQL = false; |
| 222 | + } |
| 223 | + } |
| 224 | + |
| 225 | + // Simple sorts, so copy them on to the OpSQL and drop the OpOrder |
| 226 | + // (Ordering is then applied in the database, not in memory |
| 227 | + if (orderInSQL) { |
| 228 | + OpSQL opSQL = (OpSQL) subOp; |
| 229 | + opSQL.setSortConditions(opOrder.getConditions()); |
| 230 | + return opSQL; |
| 231 | + } |
| 232 | + } |
| 233 | + } |
| 234 | + |
| 235 | + return super.transform(opOrder, subOp); |
| 236 | + } |
| 237 | + |
203 | 238 | @Override
|
204 | 239 | public Op transform(OpService opService, Op subOp)
|
205 | 240 | {
|
206 | 241 | // Do not walk in any further.
|
207 | 242 | // See ARQ Optimize class for a better way to do this.
|
208 | 243 | return opService ;
|
209 | 244 | }
|
210 |
| - |
| 245 | + |
211 | 246 | // See QueryCompilerMain.SqlNodesFinisher.visit(OpExt op)
|
212 | 247 | // Be careful about being done twice.
|
213 | 248 | // XXX SHARE CODE!
|
|
0 commit comments