Skip to content

bigfunctions > create_materialized_view_w_flattened_json_column

create_materialized_view_w_flattened_json_column

Call or Deploy create_materialized_view_w_flattened_json_column ?

✅ You can call this create_materialized_view_w_flattened_json_column bigfunction directly from your Google Cloud Project (no install required).

  • This create_materialized_view_w_flattened_json_column function is deployed in bigfunctions GCP project in 39 datasets for all of the 39 BigQuery regions. You need to use the dataset in the same region as your datasets (otherwise you may have a function not found error).
  • Function is public, so it can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
  • You may prefer to deploy the BigFunction in your own project if you want to build and manage your own catalog of functions. This is particularly useful if you want to create private functions (for example calling your internal APIs). Discover the framework

Public BigFunctions Datasets:

Region Dataset
eu bigfunctions.eu
us bigfunctions.us
europe-west1 bigfunctions.europe_west1
asia-east1 bigfunctions.asia_east1
... ...

Description

Signature

create_materialized_view_w_flattened_json_column(fully_qualified_table, fully_qualified_materialized_view, json_column)

Description

Create a Materialized view of a table with json_column flattened .

It creates a materialized view with:

Examples

call bigfunctions.eu.create_materialized_view_w_flattened_json_column('your_project.your_dataset.your_table', 'your_project.your_dataset.your_materialized_view', 'data');
call bigfunctions.us.create_materialized_view_w_flattened_json_column('your_project.your_dataset.your_table', 'your_project.your_dataset.your_materialized_view', 'data');
call bigfunctions.europe_west1.create_materialized_view_w_flattened_json_column('your_project.your_dataset.your_table', 'your_project.your_dataset.your_materialized_view', 'data');
Need help using create_materialized_view_w_flattened_json_column?

The community can help! Engage the conversation on Slack

For professional suppport, don't hesitate to chat with us.

Found a bug using create_materialized_view_w_flattened_json_column?

If the function does not work as expected, please

  • report a bug so that it can be improved.
  • or open the discussion with the community on Slack.

For professional suppport, don't hesitate to chat with us.

Use cases

You have a BigQuery table containing a JSON column called data that stores user activity logs. The JSON structure varies slightly between records, making it difficult to query specific attributes efficiently. You want to create a materialized view that flattens this JSON column, allowing simpler and faster queries on these attributes.

Use Case:

Let's say your table your_project.your_dataset.your_table looks like this:

user_id event_timestamp data
1 2024-07-26 10:00 {"event_type":"page_view", "page":"/home"}
2 2024-07-26 10:01 {"event_type":"purchase", "item_id": 123}
1 2024-07-26 10:02 {"event_type":"page_view", "page":"/products"}

You can use the create_materialized_view_w_flattened_json_column function to create a materialized view your_project.your_dataset.your_materialized_view:

call bigfunctions.us.create_materialized_view_w_flattened_json_column('your_project.your_dataset.your_table', 'your_project.your_dataset.your_materialized_view', 'data');

This will create a materialized view with columns for user_id, event_timestamp, and the flattened JSON attributes, like event_type, page, and item_id. The resulting materialized view might look something like this (depending on the actual data and the function's implementation):

user_id event_timestamp event_type page item_id
1 2024-07-26 10:00 page_view /home NULL
2 2024-07-26 10:01 purchase NULL 123
1 2024-07-26 10:02 page_view /products NULL

Now, querying for all page views becomes significantly easier:

SELECT * FROM your_project.your_dataset.your_materialized_view WHERE event_type = 'page_view';

This query will be much faster than querying the original table and parsing the JSON within the WHERE clause. This improved query performance is the key benefit of using a materialized view with a flattened JSON column.

Spread the word

BigFunctions is fully open-source. Help make it a success by spreading the word!

Share on Add a on