Kategorie: Arrays
ARRAY_TO_STRING
ARRAY_TO_STRING verbindet die Elemente eines Arrays zu einem String, getrennt durch ein Trennzeichen. Das ist die dokumentierte Entsprechung zu ARRAY_JOIN.
Syntax
ARRAY_TO_STRING(array, separator_pattern)Besonderheiten in AMC
- Damit lassen sich Pfade lesbar ausgeben, etwa "sponsored_brands > sponsored_products", statt ein Array in die CSV zu schreiben.
- Eine Funktion namens ARRAY_JOIN führt Amazon in der AMC-Funktionsliste nicht auf.
Beispiel
Produktmix je Nutzer als lesbarer Text.
WITH paths AS (
SELECT
user_id,
ARRAY_DISTINCT(COLLECT_SORTED(ad_product_type)) AS products
FROM
sponsored_ads_traffic
GROUP BY
1
)
SELECT
ARRAY_TO_STRING(products, ' + ') AS product_mix,
COUNT(DISTINCT user_id) AS users
FROM
paths
GROUP BY
1 Gegen das AMC-Schema geprüft, nicht auf einer AMC-Instanz ausgeführt.