Search in sources :

Example 1 with COLUMN_ID

use of org.talend.dataprep.transformation.actions.common.ImplicitParameters.COLUMN_ID in project data-prep by Talend.

the class ActionsStaticProfiler method profile.

public ActionsProfile profile(final List<ColumnMetadata> columns, final List<RunnableAction> actions) {
    final Map<Action, ActionDefinition> metadataByAction = getActionMetadataByAction(actions);
    // Compile actions
    final Set<String> originalColumns = columns.stream().map(ColumnMetadata::getId).collect(toSet());
    final Set<String> valueModifiedColumns = new HashSet<>();
    final Set<String> metadataModifiedColumns = new HashSet<>();
    int createColumnActions = 0;
    // Analyze what columns to look at during analysis
    for (Map.Entry<Action, ActionDefinition> entry : metadataByAction.entrySet()) {
        final ActionDefinition actionMetadata = entry.getValue();
        final Action action = entry.getKey();
        Set<ActionDefinition.Behavior> behavior = actionMetadata.getBehavior();
        boolean createColumn = false;
        for (ActionDefinition.Behavior currentBehavior : behavior) {
            switch(currentBehavior) {
                case VALUES_ALL:
                    // All values are going to be changed, and all original columns are going to be modified.
                    valueModifiedColumns.addAll(originalColumns);
                    break;
                case METADATA_CHANGE_TYPE:
                    valueModifiedColumns.add(action.getParameters().get(COLUMN_ID.getKey()));
                    metadataModifiedColumns.add(action.getParameters().get(COLUMN_ID.getKey()));
                    break;
                case VALUES_COLUMN:
                    valueModifiedColumns.add(action.getParameters().get(COLUMN_ID.getKey()));
                    break;
                case VALUES_MULTIPLE_COLUMNS:
                    // Add the action's source column
                    valueModifiedColumns.add(action.getParameters().get(COLUMN_ID.getKey()));
                    // ... then add all column parameter (COLUMN_ID is string, not column)
                    final List<Parameter> parameters = actionMetadata.getParameters(Locale.US);
                    valueModifiedColumns.addAll(// 
                    parameters.stream().filter(// 
                    parameter -> ParameterType.valueOf(parameter.getType().toUpperCase()) == ParameterType.COLUMN).map(// 
                    parameter -> action.getParameters().get(parameter.getName())).collect(Collectors.toList()));
                    break;
                case METADATA_COPY_COLUMNS:
                case METADATA_CREATE_COLUMNS:
                    createColumn = true;
                    break;
                case METADATA_DELETE_COLUMNS:
                case METADATA_CHANGE_NAME:
                    // Do nothing: no need to re-analyze where only name was changed.
                    break;
                default:
                    break;
            }
        }
        if (createColumn || isCreateColumnParameterOn(action)) {
            createColumnActions++;
        }
    }
    // when values are modified, we need to do a full analysis (schema + invalid + stats)
    boolean needFullAnalysis = !valueModifiedColumns.isEmpty() || createColumnActions > 0;
    // when only metadata is modified, we need to re-evaluate the invalids entries
    boolean needOnlyInvalidAnalysis = !needFullAnalysis && !metadataModifiedColumns.isEmpty();
    // only the columns with modified values or new columns need the schema + stats analysis
    SerializablePredicate<ColumnMetadata> filterForFullAnalysis = new FilterForFullAnalysis(originalColumns, valueModifiedColumns);
    // only the columns with metadata change or value changes need to re-evaluate invalids
    Predicate<ColumnMetadata> filterForInvalidAnalysis = new FilterForInvalidAnalysis(filterForFullAnalysis, metadataModifiedColumns);
    return new ActionsProfile(needFullAnalysis, needOnlyInvalidAnalysis, filterForFullAnalysis, filterForInvalidAnalysis, filterForInvalidAnalysis, metadataByAction);
}
Also used : ImplicitParameters(org.talend.dataprep.transformation.actions.common.ImplicitParameters) java.util(java.util) ActionRegistry(org.talend.dataprep.transformation.pipeline.ActionRegistry) Parameter(org.talend.dataprep.parameters.Parameter) Predicate(java.util.function.Predicate) ParameterType(org.talend.dataprep.parameters.ParameterType) Collectors(java.util.stream.Collectors) ScopeCategory(org.talend.dataprep.transformation.actions.category.ScopeCategory) COLUMN_ID(org.talend.dataprep.transformation.actions.common.ImplicitParameters.COLUMN_ID) ActionDefinition(org.talend.dataprep.api.action.ActionDefinition) Action(org.talend.dataprep.api.preparation.Action) Collectors.toSet(java.util.stream.Collectors.toSet) ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) Action(org.talend.dataprep.api.preparation.Action) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) ActionDefinition(org.talend.dataprep.api.action.ActionDefinition) Parameter(org.talend.dataprep.parameters.Parameter)

Aggregations

java.util (java.util)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 ActionDefinition (org.talend.dataprep.api.action.ActionDefinition)1 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)1 Action (org.talend.dataprep.api.preparation.Action)1 Parameter (org.talend.dataprep.parameters.Parameter)1 ParameterType (org.talend.dataprep.parameters.ParameterType)1 ScopeCategory (org.talend.dataprep.transformation.actions.category.ScopeCategory)1 ImplicitParameters (org.talend.dataprep.transformation.actions.common.ImplicitParameters)1 COLUMN_ID (org.talend.dataprep.transformation.actions.common.ImplicitParameters.COLUMN_ID)1 RunnableAction (org.talend.dataprep.transformation.actions.common.RunnableAction)1 ActionRegistry (org.talend.dataprep.transformation.pipeline.ActionRegistry)1