Published — v. 9
/
処理実装

処理実装


ステップの処理ロジックを機能させるためには、数多くのメソッドを実装しなくてはいけません。一部のメソッドは、ロウ(行)ステップか、またはキャッシュステップかに応じて異なります。

一般的なメソッド


以下は、ステップのデータ処理方法を定義する一般的なメソッドの例です。


メソッド説明と例
public ETLStepAPIVersion getAPIVersion()

ステップの更新を維持するYellowfinステップAPIバージョンの定義に使用するメソッドです。これは通常、列挙型ETLStepAPIVersion内の最新のバージョンです。APIバージョンは、互換性を判断するために使用されます。

 
@Override
public ETLStepAPIVersion getAPIVersion() {
    return ETLStepAPIVersion.V1;
}



public Collection<ETLException> validate()

事前実行検証を行うメソッドです。実装は、必須オプションが設定されているか、資格情報は正確か、ホストに到達可能かを確認しなくてはいけません。エラーは、ETLExceptionのインスタンスに取得され、メソッドから返されるコレクションに追加されます。または、ETLExceptionを構築する代わりに、便宜メソッドであるgetInvalidConfigETLException()を使用することもできます。

 
@Override
public Collection<ETLException> validate() {
    List<ETLException> validationErrors = new ArrayList<>();
            
    String exampleOption = this.getStepOption("APPEND_VALUE");
    if (exampleOption == null) {
        // Add a generic message "Step not Properly Configured"
        validationErrors.add(this.getInvalidConfigETLException());
    }
  
    try {
        Integer.parseInt(exampleOption);
    } catch (NumberFormatException e) {
        ETLException ve = new ETLException(ETLElement.STEP, getUuid(), null, "Option is not a number", e);
        validationErrors.add(ve);
    }
    return validationErrors;
}

   

public Map<String, String> getValidatedStepOptions()

ステップオプションを有効にするメソッドです。optionKeyからoptionValueへのマッピングは、Yellowfinリポジトリデータベースに保存されます。こちらで、無効なオプション値を削除することができます。this.getStepOptions()により返されるマッピングの操作には影響しません。

 
@Override
public Map<String, String> getValidatedStepOptions() {
    Map<String, String> stepOptions = this.getStepOptions();
    String exampleOption = stepOptions.get("APPEND_VALUE");
    if (exampleOption == null) {
        // Remove option if the value is no longer set
        stepOptions.remove("APPEND_VALUE");
    } else {           
        try {
            Integer.parseInt(exampleOption);
        } catch (NumberFormatException e) {
            // Remove option if the value is not an integer
            stepOptions.remove("APPEND_VALUE");
        }
    }
    // Return the map of valid options
    return stepOptions;
}
public void setupGeneratedFields()

ステップが新規フィールドの出力を必要とする場合は、こちらのメソッドを実装します。新規フィールド内のデータは、他のフィールドを使用して生成されます。新規フィールドは既存フィールドを置き換えるか、複製する場合もあります。Yellowfinは、各操作に便宜メソッドを提供します。こちらのメソッドは、ETLStepMetadataFieldBeanの新規インスタンスを作成するか、既存フィールドを複製することが予想されます。フィールドが事前に設定されていないか、再度設定する必要がある場合にのみ、こちらのメソッドを実行することが重要です。オプション内の変更が原因でフィールドが再作成された場合は、古いフィールドを削除しなくてはいけません。削除をしない場合、ステップが再設定される度に新規フィールドが生成されることになります。

 
@Override
public void setupGeneratedFields() throws ETLException {
    if (getStepOption("NEW_FIELD") != null) {
        // The field was already set up.
        return;
    }
 
    ETLStepMetadataFieldBean newField = new ETLStepMetadataFieldBean();
    newField.setFieldName("Concatenated Field");
    newField.setFieldType(ETLDataType.TEXT.name());
 
    // The sort order is 0 based, so the new field will be at the end
    newField.setSortOrder(getDefaultMetadataFields().size());
     
    // Ensure that the new field is output from the step
    newField.setStepIncludeField(true);
    newField.setUserIncludeField(true);
     
    // This method assigns the field a new UUID and
    // adds a Step Option to help reference it elsewhere.
    this.addNewGeneratedField(newField, "NEW_FIELD");
}

上記は、新規フィールドを生成する例です。フィールドを複製するには、以下を使用します。

this.addGeneratedField(newFieldBean, ETLFieldLinkType.DUPLICATE, originalFieldUUID)


既存フィールドを置き換えるには、以下を使用します。

this.replaceDefaultField(fieldToReplace)

上記は、元のフィールドにリンクする、新規「置き換え」フィールドを返します。オブジェクトは変更しても構いませんが、linkFieldUUIDとlinkTypeは変更してはいけません。


元のフィールドに戻り、置き換えたフィールドを削除するには、以下のコードを使用します。

this.restoreReplacedField(replacementField)

public Integer getMinInputSteps()

public Integer getMaxInputSteps()

public Integer getMinOutputSteps()

public Integer getMaxOutputSteps()

ステップに複数のインプットやアウトプットがある場合、これらのメソッドを上書きしなくてはいけません。Yellowfinは、ステップカテゴリーに基づき最小値/最大値を返すデフォルト実装を提供します。これらの値は、これらのカテゴリーのETLStepCategory列挙型要素内で定義されます。

YFLogger

これはメソッドではありませんが、すべてのステップに共通します。ステップは、YFLoggerを使用して、データトランスフォーメーションログに書き込むことができます。これは、インスタンス変数として宣言する必要があります。YFLoggerは、log4jのロガーclassのラッパです。

 
private static final YFLogger log = YFLogger.getLogger(TestStep.class.getName());



ロウ(行)ステップ実装