2016-06-22 10 views
0

私たちには何があるか見てみましょう。まずファイル[インターフェイスクラス]:カスケード経由で2つのファイルを1つのキーで結合することはできません

list arrayList 
list linkedList 

セカンドファイル[Class1の量]:

arrayList 120 
linkedList 4 
私は、各インターフェイスごとにカウントキー[クラス]で、この2つのファイルを結合し、取得したいと思い

list arraylist 120 
list linkedlist 4 

コード:

public class Main 
{ 
public static void main(String[] args) 
{ 
String docPath = args[ 0 ]; 
String wcPath = args[ 1 ]; 
String doc2Path = args[ 2 ]; 

Properties properties = new Properties(); 
AppProps.setApplicationJarClass(properties, Main.class); 
AppProps.setApplicationName(properties, "Part 1"); 
AppProps.addApplicationTag(properties, "lets:do:it"); 
AppProps.addApplicationTag(properties, "technology:Cascading"); 
FlowConnector flowConnector = new Hadoop2MR1FlowConnector(properties); 

// create source and sink taps 
Tap wcTap = new Hfs(new TextDelimited(true, ","), wcPath); 


    Fields classInterfaceFiles = new Fields("interface", "class"); 
    Tap classInterfaceTap = new Hfs(new TextDelimited(classInterfaceFiles, true, ","), docPath); 

    Fields classAmountFields = new Fields("class1", "amount"); 
    Tap classAmountFileTap = new Hfs(new TextDelimited(classAmountFields, true, ","), doc2Path); 

    Tap outTap = new MultiSinkTap(); // just saying, create your own tap 
    Pipe classInterfaceFilePipe = new Pipe("classInterfaceFilePipe"); 

    Pipe classIAmountFilePipe = new Pipe("classIAmountFilePipe"); 

    Fields groupFields = new Fields("class"); 
    Fields groupFields1 = new Fields("class1"); // fields used as joining keys 
    Pipe outPipe = new CoGroup(classInterfaceFilePipe, groupFields, classIAmountFilePipe, groupFields1, new InnerJoin()); 


// build flow definition 
    FlowDef flowDef = FlowDef.flowDef().setName("myFlow") 
      .addSource(classInterfaceFilePipe, classInterfaceTap) 
      .addSource(classIAmountFilePipe, classAmountFileTap) 
      .addTailSink(outPipe, wcTap); 
     // .addTailSink(outPipe, wcTap); 


// write a DOT file and run the flow 
Flow wcFlow = flowConnector.connect(flowDef); 
wcFlow.writeDOT("dot/wc.dot"); 
wcFlow.complete(); 
} 

}

を使用すると、すなわち、「クラス」接合される2本のパイプ内の同じフィールドを持っているので、これが起こっている

答えて

1

[これは大きな課題の一の工程です]。おそらく、それらの名前を "class_interface"と "class_amount"に変更することができます。また、CoGroupパイプで使用したgroupFieldsを変更する必要があります。

+0

あなたの提案といくつかの改善コードがうまくいきます。だから私は更新されたコードを与え、質問では作業コードです。 – user3650408

関連する問題