php小編小新在這裡跟大家介紹一下Go語言中的Apache Beam左邊連結。 Apache Beam是一種分散式資料處理框架,它提供了一種通用的程式設計模型,用於在不同的分散式資料處理引擎上執行批次和串流處理任務。而左連接是一種常見的資料處理操作,它可以將兩個資料集按照某個鍵進行關聯,傳回左側資料集中的所有記錄,以及與之相符的右側資料集中的記錄。本文將詳細介紹Go語言中如何使用Apache Beam進行左連線操作。
問題內容
有沒有簡單的方法可以使用 go 執行 2 個 pcollection 的左連接? 我發現 sql 連線僅在 java 中可用。
package main import ( "context" "flag" "github.com/apache/beam/sdks/v2/go/pkg/beam" "github.com/apache/beam/sdks/v2/go/pkg/beam/log" "github.com/apache/beam/sdks/v2/go/pkg/beam/x/beamx" ) type customer struct { CustID int FName string } type order struct { OrderID int Amount int Cust_ID int } func main() { flag.Parse() beam.Init() ctx := context.Background() p := beam.NewPipeline() s := p.Root() var custList = []customer{ {1, "Bob"}, {2, "Adam"}, {3, "John"}, {4, "Ben"}, {5, "Jose"}, {6, "Bryan"}, {7, "Kim"}, {8, "Tim"}, } var orderList = []order{ {123, 100, 1}, {125, 30, 3}, {128, 50, 7}, } custPCol := beam.CreateList(s, custList) orderPCol := beam.CreateList(s, orderList) // Left Join custPcol with orderPCol // Expected Result // CustID | FName |OrderID| Amount // 1 | Bob | 123 | 100 // 2 | Adam | | // 3 | John | 125 | 100 // 4 | Ben | | // 5 | Jose | | // 6 | Bryan | | // 7 | Kim | 125 | 100 // 8 | Tim | | if err := beamx.Run(ctx, p); err != nil { log.Exitf(ctx, "Failed to execute job: %v", err) } }
我想加入這 2 個 pcollection 並執行進一步的操作。我看到了有關 cogroupbykey 的文檔,但無法將其轉換為普通 sql join 可以執行的格式。
對此有什麼建議嗎?
解決方法
嘗試這樣
type resulttype struct { custid int fname string orderid int amount int } result := beam.pardo(s, func(c customer, iterorder func(*order) bool) resulttype { var o order for iterorder(&o) { if c.custid == o.cust_id { return resulttype{ custid: c.custid, fname: c.fname, orderid: o.orderid, amount: o.amount, } } } return resulttype{ custid: c.custid, fname: c.fname, } }, custpcol, beam.sideinput{input: orderpcol})
或如果您想使用 cogroupbykey ...
custWithKeyPCol := beam.ParDo(s, func(c customer) (int, customer) { return c.CustID, c }, custPCol) orderWithKeyPCol := beam.ParDo(s, func(o order) (int, order) { return o.Cust_ID, o }, orderPCol) resultPCol := beam.CoGroupByKey(s, custWithKeyPCol, orderWithKeyPCol) beam.ParDo0(s, func(CustID int, custIter func(*customer) bool, orderIter func(*order) bool) { c, o := customer{}, order{} for custIter(&c) { if ok := orderIter(&o); ok { fmt.Println(CustID, c.FName, o.OrderID, o.Amount) } fmt.Println(CustID, c.FName) } }, resultPCol)
以上是Go 中的 Apache Beam 左連接的詳細內容。更多資訊請關注PHP中文網其他相關文章!

你應該關心Go語言中的"strings"包,因為它提供了處理文本數據的工具,從基本的字符串拼接到高級的正則表達式匹配。 1)"strings"包提供了高效的字符串操作,如Join函數用於拼接字符串,避免性能問題。 2)它包含高級功能,如ContainsAny函數,用於檢查字符串是否包含特定字符集。 3)Replace函數用於替換字符串中的子串,需注意替換順序和大小寫敏感性。 4)Split函數可以根據分隔符拆分字符串,常用於正則表達式處理。 5)使用時需考慮性能,如

“編碼/二進制”軟件包interingoisentialForHandlingBinaryData,oferingToolSforreDingingAndWritingBinaryDataEfficely.1)Itsupportsbothlittle-endianandBig-endianBig-endianbyteorders,CompialforOss-System-System-System-compatibility.2)

掌握Go語言中的bytes包有助於提高代碼的效率和優雅性。 1)bytes包對於解析二進制數據、處理網絡協議和內存管理至關重要。 2)使用bytes.Buffer可以逐步構建字節切片。 3)bytes包提供了搜索、替換和分割字節切片的功能。 4)bytes.Reader類型適用於從字節切片讀取數據,特別是在I/O操作中。 5)bytes包與Go的垃圾回收器協同工作,提高了大數據處理的效率。

你可以使用Go語言中的"strings"包來操縱字符串。 1)使用strings.TrimSpace去除字符串兩端的空白字符。 2)用strings.Split將字符串按指定分隔符拆分成切片。 3)通過strings.Join將字符串切片合併成一個字符串。 4)用strings.Contains檢查字符串是否包含特定子串。 5)利用strings.ReplaceAll進行全局替換。注意使用時要考慮性能和潛在的陷阱。

ThebytespackageinGoishighlyeffectiveforbyteslicemanipulation,offeringfunctionsforsearching,splitting,joining,andbuffering.1)Usebytes.Containstosearchforbytesequences.2)bytes.Splithelpsbreakdownbyteslicesusingdelimiters.3)bytes.Joinreconstructsbytesli

thealternativestogo'sbytespackageincageincludethestringspackage,bufiopackage和customstructs.1)thestringspackagecanbeusedforbytemanipulationforbytemanipulationbybyconvertingbytestostostostostostrings.2))

“字節”包裝封裝forefforeflyManipulatingByteslices,CocialforbinaryData,網絡交易和andfilei/o.itoffersfunctionslikeIndexForsearching,BufferForhandLinglaRgedLargedLargedAtaTasets,ReaderForsimulatingStreamReadReadImreAmreadReamReadinging,以及Joineffiter和Joineffiter和Joineffore

go'sstringspackageIscialforficientficientsTringManipulation,uperingToolSlikestrings.split(),strings.join(),strings.replaceall(),andStrings.contains.contains.contains.contains.contains.contains.split.split(split()strings.split()dividesStringoSubSubStrings; 2)strings.joins.joins.joinsillise.joinsinelline joinsiline joinsinelline; 3);


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

WebStorm Mac版
好用的JavaScript開發工具

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具