question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add upsert/delete support via periodic MERGE statements

See original GitHub issue

Although it’s not a common use case for BigQuery, it’s come up that it’d be nice to support upserts and deletes with this connector. I’d like to propose the following way to allow the connector to optionally support that functionality, without negatively impacting existing users of the connector in append-only mode:

  1. Derive the key fields for the upsert and/or delete from the key of the message in Kafka, which will be required to be either a map or a struct. This will allow us to use the field names from that key and map them to columns in the destination BigQuery table.
  2. Insert all records received by the connector into an intermediate table, possibly named something like ${table}_tmp, where ${table} is the name of the table that the records are destined for.
  3. Periodically perform a MERGE operation that uses the intermediate table as its source and includes logic for upsert (if the value of the record is non-null) and/or delete (if the value of the record is null) based on the columns present in the record key.

This should only take place if the user enables upserts or deletes; otherwise, the connector will continue streaming directly to the intended table (or GCS bucket) as it does now.

There’s definitely some details that need to be ironed out here, such as what will happen if the fields in the record key change over time, how this would interact with table partitioning, and how/where the MERGE would be performed, but this is the overall idea.

@mtagle, @criccomini, what are your thoughts on this?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
C0urantecommented, May 28, 2020

Alright, design doc is up and anyone can comment on it here: https://docs.google.com/document/d/1p8_rLQqR9GIALIruB3-MjqR8EgYdaEw2rlFF1fxRJf0/edit

1reaction
criccominicommented, May 26, 2020

Is it safe to say that, if it can be implemented reasonably, you’d be amenable to seeing this in the connector?

Yep. I suggest a more detailed design document as a next step. That way, we can all get on the same page about implementation details.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using MERGE in SQL Server to insert, update and delete ...
The MERGE statement basically works as separate INSERT, UPDATE, and DELETE statements all within the same statement.
Read more >
15.10 - Rules for MERGE Statements with DELETE
The MERGE-INTO statement with the DELETE clause deletes the target table rows for which the condition evaluates to true.
Read more >
Merge statement to delete/update/insert data in Sql Server
The MERGE statement attempted to UPDATE or DELETE the same row more than once. This happens when a target row matches more than...
Read more >
MERGE: Insert New Rows, Update Existing Rows in One ...
Oracle's MERGE statement is tailor-made for situations when you want to do an "upsert" i.e. update existing rows in a table or insert...
Read more >
Efficient Upserts into Data Lakes with Databricks Delta
MERGE INTO USING ON [ WHEN MATCHED [ AND ] THEN ] [ WHEN MATCHED [ AND ] THEN ] [ WHEN NOT...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found