How to update view column in DatasetB from table column in DatasetA automate approach logic ? |bigquery|cloud function

Question:

I have a tableA in DatasetA

DatasetA TableA

cd xcd value
1 x1 one
2 x2
3 x3 three

And below is viewA created on tableA in DatasetB where value is empty

DatasetB ViewA

cd value
1
2
3

How to automate the process of updating value in viewA which is in DatasetB from value of Dataset A Table A ? If there is no data in value , put some other value such as ‘no value

**Expected Final Output of ViewA**
cd value
1 one
2 no value
3 three
Asked By: curious2learn

||

Answers:

One way to do this is you can use Cloud Function to automate your Bigquery update by attaching a Pub-Sub Trigger, then create a Cloud Scheduler Job that invokes the Pub/Sub trigger.

Another way to simply eliminate the need to use Cloud Function, Pub-Sub and Cloud Scheduler is to use the available tool in Bigquery – SCHEDULE feature in your query editor:
enter image description here

Then create a new scheduled query:

enter image description here

You can use the following SQL query to update the view:

select viewA.cd,
if(tableA.value = '','no_value',tableA.value) as value
from `my-project.my_datasetA.my_table` as tableA
inner join `my-project.my_datasetB.my_view` as viewA
on cast(viewA.cd as string)  = tableA.cd;

Result:

enter image description here

Answered By: Anjela B