簡體   English   中英

Google Dataflow 內連接提供列表中的連接 [ ]

[英]Google Dataflow inner join gives joins in a list [ ]

我正在使用谷歌數據流 CoGbkResult 將兩個表作為內部連接連接起來。

我能夠成功加入桌子。 我正在將輸出寫入文本文件並能夠驗證連接。 但是,聯接將匹配結果放入列表中。

像這樣的東西。

301%103%203%2017-09-20 07:49:46[2%google, 3%google, 1%microsoft]
301%105%200%2017-09-17 11:48:59[2%google, 3%google, 1%microsoft]

301%103%203%2017-09-20 07:49:46來自 table_1。 2%google3%google1%microsoft是在 table_2 中加入的匹配結果。

以下是我的processElement方法:

public void processElement(ProcessContext c) {
  KV<String, CoGbkResult> e = c.element();
  String Ad_ID = e.getKey();
  Iterable<String> Ad_Info = null;
  Ad_Info = e.getValue().getAll(AdInfoTag);
  for (String ImpressionInfo : c.element().getValue().getAll(ImpressionInfoTag)) {
    // Generate a string that combines information from both collection values  
    c.output(KV.of(Ad_ID, "%" + ImpressionInfo + Ad_Info));
  }
}

我想知道如何在單行中獲得輸出。 例如:

301%103%203%2017-09-20 07:49:46 2%google
01%103%203%2017-09-20 07:49:46 3%google
01%103%203%2017-09-20 07:49:46 1%microsoft
301%105%200%2017-09-17 11:48:59 2%google 1%microsoft
301%105%200%2017-09-17 11:48:59 3%google
301%105%200%2017-09-17 11:48:59 1%microsoft

我對您想要輸出的內容的理解(部分猜測)是您想要為第一個和第二個可迭代中的每個條目輸出一行,但我不確定為什么您不能只使用兩個 for 循環而不是轉換可迭代到一個字符串,然后解析它。 例如:

public void processElement(ProcessContext c) {
  KV<String, CoGbkResult> e = c.element();
  String Ad_ID = e.getKey();
  Iterable<String> Ad_Infos = e.getValue().getAll(AdInfoTag);
  for (String ImpressionInfo : c.element().getValue().getAll(ImpressionInfoTag)) {
    for (String Ad_Info : Ad_Infos) { 
      c.output(KV.of(Ad_ID, "%" + ImpressionInfo + Ad_Info));
    }
  }
}

我設法通過解析器得到了這個。 然而 GCP 數據流是否為此提供了一種方法?

int jointbegin = outputstring.indexOf("["); String firsthalf = outputstring.substring(0,jointbegin); String secondhalf = outputstring.substring(outputstring.indexOf("[") + 1, outputstring.indexOf("]"));

            if (!secondhalf.isEmpty())
            {
                String[] ad_data = secondhalf.split(",");

                for (int i = 0; i < ad_data.length; i++)
                {
                    String final_string = firsthalf + ad_data[i];
                    c.output(final_string);
                }
            }
          }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM