Table-stream duality
We will conclude this chapter with something that should already feel natural but is worth noting explicitly – that is, table-stream duality. We will use this concept in the next chapter, but because we have already worked with primary keys, join keys, and values, the definition naturally fits into this chapter.
We have seen two types of streams supporting deletions – upsert streams and retract streams. The main difference is that the upsert stream has an explicit primary key, while the retract stream can contain exact duplicates. Let's define a specific reduction operation for each of these streams and see what would happen if we were to apply it to these particular streams:
- If the stream is a retract stream, then in addition, simply add the input element to a list and on retraction, find the matching element in the list and remove it.
- If the stream is an upsert stream, keep the data in a map with a key that's the primary...