Skip to content

bigfunctions > array_union

array_union

Call or Deploy array_union ?

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

  • This array_union 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

array_union(array1, array2)

Description

Returns the union of two arrays.

Examples

select bigfunctions.eu.array_union([1, 2, 3], [2, 6, 7])
select bigfunctions.us.array_union([1, 2, 3], [2, 6, 7])
select bigfunctions.europe_west1.array_union([1, 2, 3], [2, 6, 7])
+-----------------+
| result          |
+-----------------+
| [1, 2, 3, 6, 7] |
+-----------------+

Need help using array_union?

The community can help! Engage the conversation on Slack

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

Found a bug using array_union?

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

Use Case: Combining Product Categories

Imagine you have an e-commerce platform, and you store product categories as arrays in a BigQuery table. You want to display all unique categories associated with a product, even if they come from different sources.

Table Schema:

CREATE OR REPLACE TABLE `your_project.your_dataset.products` (
  product_id STRING,
  categories_source1 ARRAY<STRING>,
  categories_source2 ARRAY<STRING>
);

INSERT INTO `your_project.your_dataset.products` (product_id, categories_source1, categories_source2) VALUES
('product1', ['Electronics', 'Smartphones'], ['Mobile Phones', 'Gadgets']),
('product2', ['Clothing', 'Shoes'], ['Footwear', 'Accessories']);

Query with array_union:

SELECT
    product_id,
    bigfunctions.your_region.array_union(categories_source1, categories_source2) AS all_categories
  FROM
    `your_project.your_dataset.products`;

Result:

+-----------+-------------------------------------+
| product_id | all_categories                     |
+-----------+-------------------------------------+
| product1   | ['Electronics', 'Smartphones', 'Mobile Phones', 'Gadgets'] |
| product2   | ['Clothing', 'Shoes', 'Footwear', 'Accessories']        |
+-----------+-------------------------------------+

Explanation:

The array_union function effectively combines the arrays from categories_source1 and categories_source2, eliminating duplicate category names. This gives you a single array (all_categories) containing all unique categories associated with each product. This can be beneficial for filtering, faceting, or displaying comprehensive product information on your website.

Other Use Cases:

  • Merging User Interests: Combining user interests from different sources (e.g., browsing history, explicit preferences) into a single unified list.
  • Consolidating Tags: Merging tags or keywords assigned to articles or other content from multiple sources.
  • Combining Lists of Features: Merging lists of product features from different databases or APIs. Basically anytime you need to create a distinct list from multiple lists, array_union is a good choice.

Spread the word

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

Share on Add a on