-
Notifications
You must be signed in to change notification settings - Fork 258
Fix aggregate rows key error #8322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix aggregate rows key error #8322
Conversation
hail/python/hail/ir/ir.py
Outdated
| return AggArrayPerElement(_subst(ir.array, delete(agg_env, ir.element_name)), | ||
| ir.element_name, | ||
| ir.index_name, | ||
| ir.agg_ir, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, I think this is wrong. I think it should be:
return AggArrayPerElement(_subst(ir.array, env2=agg_env, agg_env2=None),
ir.element_name,
ir.index_name,
_subst(ir.agg_ir, env2=_subst(delete(env, ir.index_name), delete(agg_env, ir.element_name),
ir.is_scan)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain to me how env vs agg_env works? Like, why does ir.array's env2 become an agg_env?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have three variable scopes: eval, scan, and agg. Suppose we have a node like TableAggregate, that supports aggregation:
TableAggregate
table ir
ApplyBinaryPrimOp
+
Ref x
ApplyAggOp(Sum(), ... seqOpArgs = Seq( Ref y )In the above, the x variable is in the eval scope, and y is in the agg scope. When we're traversing nodes with data structures that track variables defined/referenced, agg nodes need to do extra work to move variables between scopes. ApplyAggOp takes the agg env coming into it, and uses that agg env as the evaluation env for its seqOp args.
AggArrayPerElement uses the agg environment for its array argument, and passes down both an eval and agg env to its agg_ir child.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this help?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'm following, though I don't know what the index_name is for in the code you wrote above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, in this line:
_subst(ir.agg_ir, env2=_subst(delete(env, ir.index_name), delete(agg_env, ir.element_name)
you're calling _subst on an env instead of an ir
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
index_name is a variable exposed in the evaluation scope of agg_ir (the array element index) that can be used in the aggregation result operation.
I think in the above, I added an extra _subst around the env which can be deleted
98860ab to
eb9bc03
Compare
hail/python/hail/ir/ir.py
Outdated
| subst_init_op_args, | ||
| subst_seq_op_args) | ||
| elif isinstance(ir, AggArrayPerElement): | ||
| return AggArrayPerElement(_subst(ir.array, delete(agg_env, ir.element_name)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this subst shouldn't delete anything, I think. The array uses the aggregation environment, but AggArrayPerElement only binds index_name in the body.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we use UIDs everywhere so it's kinda possible that this can never cause trigger an error, but should fix it
Fixes #8316
I honestly don't know really know how this env/agg_env stuff works, I just know that this makes the tests pass. It's possible that this is an improvement but not a fully correct substitution rule, would appreciate if you could check it / tell me how you figured out what it's supposed to be.