[
https://issues.apache.org/jira/browse/JENA-630?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13964036#comment-13964036
]
Andy Seaborne commented on JENA-630:
------------------------------------
I'm seeing something unexpected.
I added a print to ExprFunction2.copySubstitute
{noformat}
@Override
final public Expr copySubstitute(Binding binding, boolean foldConstants)
{
System.out.println("ExprFunction2: "+this) ;
{noformat}
and also in NodeValue and Exprvar then tested with
{noformat}
public static void main(String... argv) throws Exception {
Op op = SSE.parseOp("(filter (= ?x (+ ?y 3)) (table unit))") ;
op = Transformer.transform(new TransformCopy(), new
ExprTransformConstantFold(), op);
System.out.println("DONE") ;
}
{noformat}
I get:
{noformat}
ExprFunction2: ( 1 + 3 )
NodeValue: 1
NodeValue: 3
ExprFunction2: ( ?x = ( 1 + 3 ) )
ExprVar: ?x
ExprFunction2: ( 1 + 3 )
NodeValue: 1
NodeValue: 3
{noformat}
It's bottom up so if a ExprTransform does nothing, then the subtree does not
need copying. This is done in ExprTransformCopy.
ExprTransformConstantFold is applied bottom up on the expression tree so it
folds ?x and (+ 1 3).
Then the folder is applied on (= ?x (?y 3)) and ExprFunction2 calls
copySubstitute on the original arguments, not "4", so the deeper {{( 1 + 3 )}}
fold is lost, and copySubstitute on the arguments is called again.
Either the ExprTransformConstantFold should return the original if no change
happens, and not call copySubstitute down the tree because ExprTransformCopy
controls that.
Or if it's going to copy always, can't the constant folder just call the top of
the expression tree once and not bottom up?
> 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)