package io.sigpipe.sing.query;

import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import io.sigpipe.sing.dataset.feature.FeatureType;
import io.sigpipe.sing.graph.Vertex;
import io.sigpipe.sing.serialization.SerializationInputStream;
import io.sigpipe.sing.serialization.SerializationOutputStream;

public class RelationalQuery extends Query {

    private Set<Vertex> pruned;

    public RelationalQuery() {

    }

    @Override
    public void execute(Vertex root)
    throws IOException, QueryException {
        this.pruned = new HashSet<Vertex>();
        System.out.println("expressions: " + expressions.size());
        prune(root, 0);
        System.out.println("Pruned " + pruned.size() + " vertices");
    }

    private void prune(Vertex vertex, int expressionsEvaluated)
    throws QueryException {
        if (expressionsEvaluated == this.expressions.size()) {
            return;
        }

        String childFeature = vertex.getFirstNeighbor().getLabel().getName();
        List<Expression> expList = this.expressions.get(childFeature);
        if (expList != null) {
            Set<Vertex> allNeighbors = new HashSet<>(vertex.getAllNeighbors());
            Set<Vertex> matches = evaluate(vertex, expList);
            for (Vertex match : matches) {
                if (match == null) {
                    continue;
                }

                if (match.getLabel().getType() == FeatureType.NULL) {
                    continue;
                }

                prune(match, expressionsEvaluated + 1);
            }

            allNeighbors.removeAll(matches);
            for (Vertex nonMatch : allNeighbors) {
                pruned.add(nonMatch);
            }
        } else {
            /* No expression operates on this vertex. Consider all children. */
            for (Vertex neighbor : vertex.getAllNeighbors()) {
                prune(neighbor, expressionsEvaluated);
            }
        }
    }

    @Deserialize
    public RelationalQuery(SerializationInputStream in)
    throws IOException {

    }

    @Override
    public void serialize(SerializationOutputStream out)
    throws IOException {

    }

}

@@ -1980,214 +1980,44 @@
   %7D%0A
-    %7D%0A%0A    @Deserialize%0A    public RelationalQuery(SerializationInputStream in)%0A    throws IOException %7B%0A%0A    %7D%0A%0A    @Override%0A    public void serialize(SerializationOutputStream out)%0A    throws IOException
+%0A        if (foundSubMatch == false)
  %7B%0A%0A
@@ -2022,11 +2022,10 @@
 %0A%0A    %7D%0A
-%0A
 %7D%0A

Remove serialization logic