package org.talend.dataprep.transformation.pipeline.node;

import java.util.function.Function;
import java.util.function.Predicate;

import org.talend.dataprep.api.dataset.DataSetRow;
import org.talend.dataprep.api.dataset.RowMetadata;

public class FilteredNode extends BasicNode {

    private final Function<RowMetadata, Predicate<DataSetRow>> filter;

    private Predicate<DataSetRow> instance;

    public FilteredNode(Function<RowMetadata, Predicate<DataSetRow>> filter) {
        this.filter = filter;
    }

    @Override
    public void receive(DataSetRow row, RowMetadata metadata) {
        synchronized (filter) {
            if (instance == null) {
                instance = filter.apply(metadata);
            }
        }
        if (instance.test(row)) {
            super.receive(row, metadata);
        }
    }

}

@@ -48,24 +48,54 @@
 line.node;%0A%0A
+import java.util.Collections;%0A
 import java.
@@ -258,16 +258,75 @@
 etadata;
+%0Aimport org.talend.dataprep.transformation.pipeline.Signal;
 %0A%0Apublic
@@ -483,16 +483,105 @@
 tance;%0A%0A
+    private boolean hasMatchedFilter = false;%0A%0A    private RowMetadata lastRowMetadata;%0A%0A
     publ
@@ -939,24 +939,61 @@
 est(row)) %7B%0A
+            hasMatchedFilter = true;%0A
             
@@ -1031,18 +1031,456 @@
        %7D
+ else %7B%0A            lastRowMetadata = metadata;%0A        %7D%0A    %7D%0A%0A    @Override%0A    public void signal(Signal signal) %7B%0A        if (signal == Signal.END_OF_STREAM && !hasMatchedFilter) %7B%0A            // Ensure next steps at least receives metadata information.%0A            final DataSetRow row = new DataSetRow(lastRowMetadata, Collections.emptyMap());%0A            super.receive(row, lastRowMetadata);%0A        %7D%0A        super.signal(signal);
 %0A    %7D%0A
-%0A
 %7D%0A

Fix issue in filter out node for empty content