範例 - ARRAYSLICE 和 ARRAYMERGEELEMENTS 函式

本範例說明下列函式:

  • ARRAYSLICE - 根據提供的起始和結尾索引編號傳回一個陣列,該陣列為另一個陣列的一部分。請參閱 ARRAYSLICE 函式一文。
  • ARRAYMERGEELEMENTS - 將陣列的元素合併為一個字串。請參閱 ARRAYMERGEELEMENTS 函式一文。

來源:

以下的陣列包含一系列按順序排列的比賽成績。目標是從這個清單中擷取在各場比賽站上頒獎台的參賽者名單做為一個字串。

RaceIdRaceResults
1["racer3","racer5","racer2","racer1","racer6"]
2["racer6","racer4","racer2","racer1","racer3","racer5"]
3["racer4","racer3","racer5","racer2","racer6","racer1"]
4["racer1","racer2","racer3","racer5"]
5["racer5","racer2","racer4","racer6","racer3"]


轉換:

第一步是從陣列清單中收集每場比賽的前三名完賽者:

derive type: single value: ARRAYSLICE(RaceResults, 0, 3) as: 'arrPodium'

以上陳述式將 RaceResults 陣列的前三個值擷取到一組新的陣列中。

下一步是將這組新陣列合併為一個字串:

derive type: single value: ARRAYMERGEELEMENTS(arrPodium, ',') as: 'strPodium'

結果:

RaceIdRaceResultsarrPodiumstrPodium
1["racer3","racer5","racer2","racer1","racer6"]["racer3","racer5","racer2"]racer3,racer5,racer2
2["racer6","racer4","racer2","racer1","racer3","racer5"]["racer6","racer4","racer2"]racer6,racer4,racer2
3["racer4","racer3","racer5","racer2","racer6","racer1"]["racer4","racer3","racer5"]racer4,racer3,racer5
4["racer1","racer2","racer3","racer5"]["racer1","racer2","racer3"]racer1,racer2,racer3
5["racer5","racer2","racer4","racer6","racer3"]["racer5","racer2","racer4"]racer5,racer2,racer4


本頁內容對您是否有任何幫助?請提供意見:

傳送您對下列選項的寶貴意見...

這個網頁
Google Cloud Dataprep 說明文件
需要協助嗎?請前往我們的支援網頁