DaNeSh
DaNeSh

Reputation: 1062

Move data from one column to another in a single transaction/api call

I'm using the NodeJs library for bigtable.

I have two columns. ColumnA and ColumnB.

In a single call/transaction I want to move the data from ColumnA to ColumnB, and at the same time delete the data in the ColumnA.

I can do that in 3 steps:

1.. Get ColumnA from bigtable

2.. Update ColumnB

3.. Delete ColumnA

But I was wondering if it's possible to do all these steps in a single call (and ideally single transaction)?

Thanks

Upvotes: 1

Views: 116

Answers (1)

Billy Jacobson
Billy Jacobson

Reputation: 1703

You can turn these three API calls into two with a batch mutation, but there is no way to get the value while performing the mutation.

Follow this example to update and delete in the same bulk mutation, but note that the operations are non-atomic

const entries = [
  {
    method: 'insert',
    key: 'your#key',
    data: {
      yourQualifier: {
        ColB: ColAValue
      }
    }
  }, {
    method: 'delete',
    key: 'your#key',
    data: [
      'yourQualifier:ColA'
    ]
  }
];

table.mutate(entries, callback);

For more information check out the Cloud Bigtable writing data documentation and the write concept page.

Upvotes: 1

Related Questions