Skip to content

Conversation

@tmager
Copy link
Contributor

@tmager tmager commented Feb 8, 2026

Introduces a new KeySet.union operation which combines two KeySets with matching schemas into a single KeySet containing all keys contained in either KeySet.

For the purposes of op-tree rewriting, this operation is relatively opaque; most other operations can't be pulled through it safely, so the only way unions are rewritten is to reorder operands and restructure nested unions. In principle filters and subtraction could be pushed down through it, but it seems unlikely to me that anyone will care if we can detect that ks1.union(ks2).filter(cond) is equivalent to ks1.filter(cond).union(ks2.filter(cond)).

tmlt.analytics.keyset._keyset was also rewritten to use the pipe syntax for unions instead of typing.Union, as the name conflict was confusing.

#122

Introduces a new `KeySet.union` operation which combines two KeySets with the
same schema into a single KeySet containing all keys contained in either
KeySet.

For the purposes of op-tree rewriting, this operation is relatively opaque; most
other operations can't be pulled through it safely, so the only way unions are
rewritten is to reorder operands and restructure nested unions. In principle
filters and subtraction could be pushed down through it, but it seems unlikely
to me that anyone will care if we can detect that `ks1.union(ks2).filter(cond)`
is equivalent to `ks1.filter(cond).union(ks2.filter(cond))`.

`tmlt.analytics.keyset._keyset` was also rewritten to use the pipe syntax for
unions instead of `typing.Union`, as the name conflict was confusing.
@tmager tmager self-assigned this Feb 8, 2026
+ textwrap.indent(str(self.right), " ")
)

def decompose(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Open question for another MR: do we need this decomposition logic anymore? I don't think anything that used it was open-sourced.

Copy link
Contributor

Choose a reason for hiding this comment

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

That matches my recollection; I think we can probably get rid of it.

+ textwrap.indent(str(self.right), " ")
)

def decompose(
Copy link
Contributor

Choose a reason for hiding this comment

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

That matches my recollection; I think we can probably get rid of it.

Comment on lines +427 to +429
# TODO(tumult-labs/tumult#3384): Mention the behavior of this method in
# terms of its interation with KeySetPlans in the docstring and to
# the below error message.
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this mean exactly?

Copy link
Contributor Author

@tmager tmager Feb 10, 2026

Choose a reason for hiding this comment

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

Ah, this was a copy from the other methods on the class -- we should recreate the relevant issue and point this at it, but it's a reminder to update the documentation/exception text for these methods when KeySet.detect becomes usable.

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.

2 participants