Skip to content
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

Merged

Conversation

johnc1231
Copy link
Contributor

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.

return AggArrayPerElement(_subst(ir.array, delete(agg_env, ir.element_name)),
ir.element_name,
ir.index_name,
ir.agg_ir,
Copy link
Contributor

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)

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this help?

Copy link
Contributor Author

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.

Copy link
Contributor Author

@johnc1231 johnc1231 Mar 26, 2020

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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

@@ -2494,6 +2494,12 @@ def delete(env, name):
return ApplyAggOp(ir.agg_op,
subst_init_op_args,
subst_seq_op_args)
elif isinstance(ir, AggArrayPerElement):
return AggArrayPerElement(_subst(ir.array, delete(agg_env, ir.element_name)),
Copy link
Contributor

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.

Copy link
Contributor

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

@danking danking merged commit bd7a720 into hail-is:master Apr 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Key Error va in aggregate_rows
4 participants