Skip to content

[FAQ] Session window aggregation fails with “declare primary key for sink table” error #248

@AsherJD-io

Description

@AsherJD-io

Course

data-engineering-zoomcamp

Question

Why does the PyFlink session window job fail with the error “please declare primary key for sink table when query contains update/delete record”?

Answer

Session window aggregations produce updates while the session is still open. The JDBC sink needs a primary key so it knows which row should be updated in the table. Without a primary key, Flink cannot apply the updates and the job fails. Define a primary key in the sink table using the window boundaries and the grouping key (for example window_start, window_end, and PULocationID).

Checklist

  • I have searched existing FAQs and this question is not already answered
  • The answer provides accurate, helpful information
  • I have included any relevant code examples or links

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions