@Override
    public <P extends Pipeline> P optimize(
        final P initialPipeline,
        final SqlStreamOptimizerInfo<ENTITY> info,
        final AsynchronousQueryResult<ENTITY> query
    ) {
        requireNonNull(initialPipeline);
        requireNonNull(info);
        requireNonNull(query);

        final List<FilterAction<ENTITY>> filters = new ArrayList<>();
        traverse(initialPipeline, filters::add);

        final List<Object> values = new ArrayList<>();
        final StringBuilder sql = new StringBuilder();

        sql.append(info.getSqlSelect());

        if (!filters.isEmpty()) {
            @SuppressWarnings("unchecked")
            List<Predicate<ENTITY>> predicates = filters.stream()
                .map(FilterAction::getPredicate)
                .map(p -> (Predicate<ENTITY>) p)
                .collect(toList());

            final StreamTerminatorUtil.RenderResult rr = StreamTerminatorUtil.renderSqlWhere(
                info.getDbmsType(),
                info.getSqlColumnNamer(),
                info.getSqlDatabaseTypeFunction(),
                predicates
            );

            final String whereFragmentSql = rr.getSql();
            if (!whereFragmentSql.isEmpty()) {
                sql.append(" WHERE ").append(whereFragmentSql);
                values.addAll(rr.getValues());
            }
        }

        query.setSql(sql.toString());
        query.setValues(values);

        initialPipeline.removeIf(filters::contains);
        return initialPipeline;
    }
This Optimizer can take care of the case where there is a mix of Field
predicates and other predicates. Field predicates will be optimized and other
predicates will be applied in the stream.

@author Per Minborg
@param <ENTITY> the entity type
runtime-parent/runtime-core/src/main/java/com/speedment/runtime/core/internal/component/sql/optimizer/InitialFilterOptimizer.java