2017-03-21 4 views
0

スパーク1.6.1 のHadoop 2.6.2を次のように私の環境があるスパーク - ジャワ - foreachPartition

次のように私たちの要件である(すべてのでのJavaスパーク) 1. CSVファイルを読み、適用スキーマを作成し、これをデータフレームに変換します 2. Sparkでパーティション分割されたSQLを使用して、パーティション化されたすべてのデータを取得し、並列処理を繰り返します。

2番目の手順を実行するとエラーが発生します。

DataFrame sourceRowDF = hiveContext.createDataFrame(srcRowsRDD,source_Schema); 
    sourceRowDF.registerTempTable("sourcetable"); 
    DataFrame partitionedData = hiveContext.sql("select * from sourcetable distribute by region"); 

    partitionedData.foreachPartition(new ForeachPartitionFunc() { 
    @Override 
    public void call(Iterator<Row> it) { 
     while (it.hasNext()) { 
      System.out.println(it.next().toString()); 
     } 
    } 
}); 

public abstract class ForeachPartitionFunc extends AbstractFunction1<Iterator<Row>, BoxedUnit> implements Serializable { 
     @Override 
    public BoxedUnit apply(Iterator<Row> it) { 
     call(it); 
     return BoxedUnit.UNIT; 
    } 
    public abstract void call(Iterator<Row> it); 
} 

を次のように抽象的関数である私がしようとすると、このコードをコンパイルするときには、

Error:(254, 39) java: non-static variable this cannot be referenced from a static context 

私に次のエラーを与える私が間違って何をやっているしてください。

おかげ

バラ

+0

ようこそスタックオーバーフロー!良い質問をするので、良い答えを得るためにあなたを助けるために私たちの[SO質問チェックリスト](http://meta.stackoverflow.com/questions/260648/stack-overflow-question-checklist)を確認してください。 –

答えて

0

私は抽象実装でのpublic staticクラスを持っていました。私はコアの抽象実装を次のように変更しました。

public static class ForeachPartitionFunc extends AbstractFunction1<Iterator<Row>, BoxedUnit> implements Serializable { 
     @Override 
    public BoxedUnit apply(Iterator<Row> it) { 
     call(it); 
     return BoxedUnit.UNIT; 
    } 

    public void call(Iterator<Row> r) { 
     System.out.println("this is to test"); 
    } 
}