私は特定のPCollectionを特定のPTableに変換しているutilクラスにこれらのメソッドを持っています。Apache CrunchのPCollectionをPTableに変換する一般的な方法はありますか?
public static PTable<IdDetails, CASegmentsForModification> getPTableForCASegments(PCollection<CASegmentsForModification> aggregatedPCollectionForCASegments) {
return aggregatedPCollectionForCASegments.parallelDo(new CASegmentsPTableConverter(),
Avros.tableOf(Avros.records(IdDetails.class), Avros.records(CASegmentsForModification.class)));
}
public static PTable<IdDetails, UserPrimaryIdMapping> getPTableForPrimaryIdMapping(PCollection<UserPrimaryIdMapping> pCollectionOfUserPrimaryIdMapping) {
return pCollectionOfUserPrimaryIdMapping.parallelDo(new UserPrimaryIdMappingPTableConverter(),
Avros.tableOf(Avros.records(IdDetails.class), Avros.records(UserPrimaryIdMapping.class)));
}
public static PTable<IdDetails, UserGroupSegments> getPTableForUserGroupSegments(PCollection<UserGroupSegments> pCollectionOfUserGroupSegments) {
return pCollectionOfUserGroupSegments.parallelDo(new UserGroupSegmentsPTableConverter(),
Avros.tableOf(Avros.records(IdDetails.class), Avros.records(UserGroupSegments.class)));
}
上記の方法の1つの一般的な方法を実装するにはどうすればよいですか?
しかし、私のPCollectionはその唯一のVのペア、ではない「asPTable」、私が最初に私を変換する必要がありますPCollection ~PCollection も冗長コードになります。 例えば、私はいくつかのアブロのPCollectionを読み取って取得するには、この一般的な方法を使用することができる: - パブリック静的PCollection getPCollection(パイプラインのパイプライン、文字列パス、クラス clazz){ 戻りpipeline.read (より.avroFile(path、clazz)); } –
あなたのPCollectionにExtractKeyFnを使用するのはどうですか?? genericRecordsを使用するgenerate関数を作成し、フィールド名に基づいてキーを抽出する場合でも、クラスからキーを抽出する方法を常に提供する必要があります。キーを生成する方法はありません。キーを抽出するロジック –
hlagos
同じように、上記のユースケースに対して1つの汎用メソッドを記述することは可能ですか? –