Skip to content

Will Continuous Top-N leak space forever? #68

Open
@Ocramius

Description

@Ocramius

I'm looking at this query:

```sql
CREATE TABLE spells_cast (
wizard STRING,
spell STRING
) WITH (
'connector' = 'faker',
'fields.wizard.expression' = '#{harry_potter.characters}',
'fields.spell.expression' = '#{harry_potter.spells}'
);
SELECT wizard, spell, times_cast
FROM (
SELECT *,
ROW_NUMBER() OVER (PARTITION BY wizard ORDER BY times_cast DESC) AS row_num
FROM (SELECT wizard, spell, COUNT(*) AS times_cast FROM spells_cast GROUP BY wizard, spell)
)
WHERE row_num <= 2;
```

I'm wondering if this will leak space forever?

An example about data size

Excluding the GROUP BY bit, and simplifying:

SELECT wizard, spell, times_cast
FROM (
    SELECT *,
    ROW_NUMBER() OVER (PARTITION BY wizard ORDER BY times_cast DESC) AS row_num
    FROM (SELECT wizard, spell, times_cast FROM spells_cast_source)
)
WHERE row_num <= 2; 

From a logical PoV, my brain tells me that Flink will have to forever keep a map of seen identifiers (wizard) somewhere, in order to track row_num continuously?

What happens if I have 300Gb of data? Will this leak that space?

Windowed aggregations and continuous streaming?

Looking at upstream docs for Flink 1.20:

https://nightlies.apache.org/flink/flink-docs-release-1.20/docs/dev/table/sql/queries/window-agg/

Unlike other aggregations on continuous tables, window aggregation do not emit intermediate results but only a final result, the total aggregation at the end of the window. Moreover, window aggregations purge all intermediate state when no longer needed.

So the tradeoff here is either "continuously, but leaking space", or "when window ends, but cleaning up after a window".

Is there a way to obtain continuous streaming over a window, whilst still cleaning up after a window is done?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions