[
https://issues.apache.org/jira/browse/JENA-630?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13964410#comment-13964410
]
Andy Seaborne commented on JENA-630:
------------------------------------
It looks better when folding occurs.
I then tried a non-folding expression:
{noformat}
Expr expr = SSE.parseExpr("(* ?y (+ (* ?x 4) (* ?z 6 )))") ;
Expr expr2 = ExprTransformer.transform(new ExprTransformConstantFold(),
expr) ;
System.out.println("==> "+expr2) ;
System.out.println("DONE") ;
{noformat}
and got:
{noformat}
ExprFunction2: ( ?x * 4 )
ExprVar: ?x
NodeValue: 4
ExprFunction2: ( ?z * 6 )
ExprVar: ?z
NodeValue: 6
ExprFunction2: ( ( ?x * 4 ) + ( ?z * 6 ) )
ExprFunction2: ( ?x * 4 )
ExprVar: ?x
NodeValue: 4
ExprFunction2: ( ?z * 6 )
ExprVar: ?z
NodeValue: 6
ExprFunction2: ( ?y * ( ( ?x * 4 ) + ( ?z * 6 ) ) )
ExprVar: ?y
ExprFunction2: ( ( ?x * 4 ) + ( ?z * 6 ) )
ExprFunction2: ( ?x * 4 )
ExprVar: ?x
NodeValue: 4
ExprFunction2: ( ?z * 6 )
ExprVar: ?z
NodeValue: 6
==> ( ?y * ( ( ?x * 4 ) + ( ?z * 6 ) ) )
DONE
{noformat}
{{copySubstitute}} on the top node gets called and it recursively calls
copySubstitute on subnodes. But these have been processed.
It's the call to {{copySubstitute}} in
{{ExprTransformConstantFold.transform(ExprFunction2 func, Expr expr1, Expr
expr2)}} - the process does not need to copy at this point.
I've attached a possible {{ExprTransformConstantFold}} and a test programme --
a couple of things need cleaning up for a real version
({{ExprFunctionN.eval(List<NodeValue>}} needs to be public but that has knock
on changes which are not issues for this discussion; I hit the
ARQInternalErrorException from TestUSerFuntionsInSparql but looks like a
separate matter).
This does not make this issue "major" -- the optimization is almost certainly
beneficial.
> Do constant folding as part of query optimisation
> -------------------------------------------------
>
> Key: JENA-630
> URL: https://issues.apache.org/jira/browse/JENA-630
> Project: Apache Jena
> Issue Type: Improvement
> Components: ARQ
> Affects Versions: Jena 2.11.1
> Reporter: Rob Vesse
> Assignee: Rob Vesse
> Fix For: Jena 2.11.2
>
>
> Currently Jena does not automatically simplify expressions by constant
> folding even though the function API actually has support for this already
> baked into it.
> This issue will track work to integrate a transform for this into the
> standard optimiser.
--
This message was sent by Atlassian JIRA
(v6.2#6252)