/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.addthis.hydra.data.query.op;

import javax.annotation.Nullable;
import javax.annotation.Syntax;

import java.io.IOException;
import java.io.UncheckedIOException;

import com.addthis.bundle.core.Bundle;
import com.addthis.hydra.data.filter.bundle.BundleFilter;
import com.addthis.hydra.data.query.AbstractRowOp;

import io.netty.channel.ChannelProgressivePromise;

import static com.addthis.codec.config.Configs.decodeObject;

public class OpFilter extends AbstractRowOp {

    private final BundleFilter filter;

    public OpFilter(@Syntax("HOCON") String args, ChannelProgressivePromise queryPromise) {
        super(queryPromise);
        try {
            filter = decodeObject(BundleFilter.class, args);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }

    @Nullable @Override public Bundle rowOp(Bundle row) {
        if (filter.filter(row)) {
            return row;
        } else {
            return null;
        }
    }
}

@@ -989,16 +989,287 @@
 bject;%0A%0A
+/**%0A * %3Cp%3EThis query operation %3Cspan class=%22hydra-summary%22%3Eruns arbitrary bundle filters.%3C/span%3E.%0A * %3Cp/%3E%0A * %3Cp%3EExample:%3C/p%3E%0A * %3Cpre%3E%0A * hello 72%0A * hi 12%0A *%0A * filter=%7Bfrom.index:0, require:hello%7D%0A *%0A * hello 72%0A * %3C/pre%3E%0A *%0A * @user-reference%0A * @hydra-name filter%0A */%0A
 public c

add docs / user-ref flag to query op filter