10

Any idea how to call bigquery stored proc from Google data studio? I've a recursive query requirement which I've accomplished using Bigquery procedure. However need to pass parameters to this procedure from datastudio report and get results for the same and display in Data studio report. I have tried calling the procedure from Custom Query in Data studio no luck. Datastudio throws error. I tried calling procedure from a function however it doesn't work. ANy idea? How do I do I call procedure from Google Data studio?

Procedure that is written

DECLARE stop INT64 DEFAULT 30;
    DECLARE v_target string;
    DECLARE v_target_column_name string;
    DECLARE max_counter INT64;
    DECLARE min_counter INT64;
    DECLARE v_exists bool;
    SET v_target = 'v_target';
    SET v_target_column_name = 'v_target_col';
    create or replace table test.poc_sttm_resp as
    select ROW_NUMBER() OVER() as counter,'N' as flag,source,source_column_name,target,target_column_name from test.test_sttm where target = v_target and target_column_name = v_target_column_name;
    LOOP
    SET max_counter = (select max(counter) from test.poc_sttm_resp);
    SET min_counter = (select min(counter) from test.poc_sttm_resp where flag = 'N');
    SET v_exists = EXISTS(select s.source from test.test_sttm s inner join
      (select source,source_column_name from test.poc_sttm_resp where counter =  min_counter
      ) r
      on s.target = r.source and
      s.target_column_name = r.source_column_name);
      IF stop = 0  OR min_counter is null THEN
        LEAVE;
      END IF;
      IF v_exists then
      insert into test.poc_sttm_resp
      select ROW_NUMBER() OVER() + max_counter as counter,'N' as flag,s.source,s.source_column_name,target,target_column_name from test.test_sttm s inner join
      (select source,source_column_name from test.poc_sttm_resp where counter = (select min(counter) from test.poc_sttm_resp where flag = 'N')) r
      on s.target = r.source and
      s.target_column_name = r.source_column_name;
      END IF;
      update test.poc_sttm_resp set flag = 'Y' where counter = min_counter;
        SET stop = stop - 1;
    END LOOP;

I tried calling the procedure from Data Studio, call functions.testproc(); which didn't work

eshirvana
  • 23,227
  • 3
  • 22
  • 38
user15432774
  • 109
  • 4

3 Answers3

0

Have you try make the connection between Google Data Studio and BigQuery using the community connectors?
Using the community connectors you can trigger a stored procedure with parameters.

  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/30256695) – user12256545 Nov 05 '21 at 14:26
0

I've encountered this issue recently and this is a "workaround"/solution I found that worked for me.

You can create a table function that does the same thing as your stored procedure and still accept parameters (for example a date) to be used inside the query in the function.

Afterwards (still sticking with the date parameter) in DataStudio(LookerStudio at the time of writing) you create a custom query and use the DS_START/END_DATE parameter and a date control to pass in a date range for your query (if you need that)

The reason for using a table function is that in the custom query you can just write:

SELECT * FROM yourtablefunction(@DS_START_DATE, @DS_END_DATE)

And this will work just like a View or Table in DataStudio.

Some useful links that can help anyone reading this:

Calling Big Query Stored Procedure From GDS

BigQuery Table Functions Docs

Nik
  • 1
  • 3
-1

Double check you connected correctly

You need to create/add the parameter in the data source or inside Data Studio via add parameter

In a data source

1. Sign in to Data Studio.
2. Edit your data source.
3. In the upper right, click ADD A PARAMETER.
4. You can also create a parameter while editing a report by selecting a component, then in the bottom right, clicking ADD A PARAMETER. Be sure to select a component based on the desired data source.
5. Configure the parameter's options and default value (see below).

Also, scrolling down on the page, you will see an example on how to do this with a sample calculation.

Adding Parameter to BigQuery Google Studio Store Procedure

Transformer
  • 6,963
  • 2
  • 26
  • 52