// Path: strategy/src/main/java/com/msd/gin/halyard/vocab/HALYARD.java
// public final class HALYARD {
// 
//     HALYARD() {}
// 
//     private static final SimpleValueFactory SVF = SimpleValueFactory.getInstance();
// 
//     public static final String PREFIX = "halyard";
// 
//     public static final String NAMESPACE = "http://merck.github.io/Halyard/ns#";
// 
//     public static final IRI STATS_ROOT_NODE = SVF.createIRI(NAMESPACE, "statsRoot");
// 
//     public static final IRI STATS_GRAPH_CONTEXT = SVF.createIRI(NAMESPACE, "statsContext");
// 
//     public static final IRI SYSTEM_GRAPH_CONTEXT = SVF.createIRI(NAMESPACE, "system");
// 
//     public static final IRI NAMESPACE_PREFIX_PROPERTY = HALYARD.SVF.createIRI(NAMESPACE, "namespacePrefix");
// 
//     public final static IRI TABLE_NAME_PROPERTY = SVF.createIRI(NAMESPACE, "tableName");
// 
//     public final static IRI SPLITBITS_PROPERTY = SVF.createIRI(NAMESPACE, "splitBits");
// 
//     public final static IRI CREATE_TABLE_PROPERTY = SVF.createIRI(NAMESPACE, "createTable");
// 
//     public final static IRI PUSH_STRATEGY_PROPERTY = SVF.createIRI(NAMESPACE, "pushStrategy");
// 
//     public final static IRI EVALUATION_TIMEOUT_PROPERTY = SVF.createIRI(NAMESPACE, "evaluationTimeout");
// 
//     public final static IRI ELASTIC_INDEX_URL_PROPERTY = SVF.createIRI(NAMESPACE, "elasticIndexURL");
// 
//     public final static IRI SEARCH_TYPE = SVF.createIRI(NAMESPACE, "search");
// 
//     public final static IRI PARALLEL_SPLIT_FUNCTION = SVF.createIRI(NAMESPACE, "forkAndFilterBy");
// 
// }


import org.eclipse.rdf4j.query.algebra.evaluation.impl.QueryJoinOptimizer;
import org.eclipse.rdf4j.query.algebra.helpers.AbstractQueryModelVisitor;
import com.msd.gin.halyard.vocab.HALYARD;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.Dataset;
import org.eclipse.rdf4j.query.IncompatibleOperationException;
import org.eclipse.rdf4j.query.algebra.Extension;
import org.eclipse.rdf4j.query.algebra.FunctionCall;
import org.eclipse.rdf4j.query.algebra.Join;
import org.eclipse.rdf4j.query.algebra.TupleExpr;
import org.eclipse.rdf4j.query.algebra.ValueExpr;
import org.eclipse.rdf4j.query.algebra.Var;
/*
 * Copyright 2018 Merck Sharp & Dohme Corp. a subsidiary of Merck & Co.,
 * Inc., Kenilworth, NJ, USA.
 *
 * 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.msd.gin.halyard.optimizers;


/**
 *
 * @author Adam Sotona (MSD)
 */
public final class HalyardQueryJoinOptimizer extends QueryJoinOptimizer {

    public HalyardQueryJoinOptimizer(HalyardEvaluationStatistics statistics) {
        super(statistics);
    }

    @Override
    public void optimize(TupleExpr tupleExpr, Dataset dataset, BindingSet bindings) {
        final Set<String> parallelSplitBounds = new HashSet<>();
        tupleExpr.visit(new AbstractQueryModelVisitor<IncompatibleOperationException>() {
            @Override
            public void meet(FunctionCall node) throws IncompatibleOperationException {
// Path: strategy/src/main/java/com/msd/gin/halyard/vocab/HALYARD.java
// public final class HALYARD {
// 
//     HALYARD() {}
// 
//     private static final SimpleValueFactory SVF = SimpleValueFactory.getInstance();
// 
//     public static final String PREFIX = "halyard";
// 
//     public static final String NAMESPACE = "http://merck.github.io/Halyard/ns#";
// 
//     public static final IRI STATS_ROOT_NODE = SVF.createIRI(NAMESPACE, "statsRoot");
// 
//     public static final IRI STATS_GRAPH_CONTEXT = SVF.createIRI(NAMESPACE, "statsContext");
// 
//     public static final IRI SYSTEM_GRAPH_CONTEXT = SVF.createIRI(NAMESPACE, "system");
// 
//     public static final IRI NAMESPACE_PREFIX_PROPERTY = HALYARD.SVF.createIRI(NAMESPACE, "namespacePrefix");
// 
//     public final static IRI TABLE_NAME_PROPERTY = SVF.createIRI(NAMESPACE, "tableName");
// 
//     public final static IRI SPLITBITS_PROPERTY = SVF.createIRI(NAMESPACE, "splitBits");
// 
//     public final static IRI CREATE_TABLE_PROPERTY = SVF.createIRI(NAMESPACE, "createTable");
// 
//     public final static IRI PUSH_STRATEGY_PROPERTY = SVF.createIRI(NAMESPACE, "pushStrategy");
// 
//     public final static IRI EVALUATION_TIMEOUT_PROPERTY = SVF.createIRI(NAMESPACE, "evaluationTimeout");
// 
//     public final static IRI ELASTIC_INDEX_URL_PROPERTY = SVF.createIRI(NAMESPACE, "elasticIndexURL");
// 
//     public final static IRI SEARCH_TYPE = SVF.createIRI(NAMESPACE, "search");
// 
//     public final static IRI PARALLEL_SPLIT_FUNCTION = SVF.createIRI(NAMESPACE, "forkAndFilterBy");
// 
// }


// Path: strategy/src/main/java/com/msd/gin/halyard/optimizers/HalyardQueryJoinOptimizer.java
import org.eclipse.rdf4j.query.algebra.evaluation.impl.QueryJoinOptimizer;
import org.eclipse.rdf4j.query.algebra.helpers.AbstractQueryModelVisitor;
import com.msd.gin.halyard.vocab.HALYARD;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.Dataset;
import org.eclipse.rdf4j.query.IncompatibleOperationException;
import org.eclipse.rdf4j.query.algebra.Extension;
import org.eclipse.rdf4j.query.algebra.FunctionCall;
import org.eclipse.rdf4j.query.algebra.Join;
import org.eclipse.rdf4j.query.algebra.TupleExpr;
import org.eclipse.rdf4j.query.algebra.ValueExpr;
import org.eclipse.rdf4j.query.algebra.Var;

/*
 * Copyright 2018 Merck Sharp & Dohme Corp. a subsidiary of Merck & Co.,
 * Inc., Kenilworth, NJ, USA.
 *
 * 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.msd.gin.halyard.optimizers;


/**
 *
 * @author Adam Sotona (MSD)
 */
public final class HalyardQueryJoinOptimizer extends QueryJoinOptimizer {

    public HalyardQueryJoinOptimizer(HalyardEvaluationStatistics statistics) {
        super(statistics);
    }

    @Override
    public void optimize(TupleExpr tupleExpr, Dataset dataset, BindingSet bindings) {
        final Set<String> parallelSplitBounds = new HashSet<>();
        tupleExpr.visit(new AbstractQueryModelVisitor<IncompatibleOperationException>() {
            @Override
            public void meet(FunctionCall node) throws IncompatibleOperationException {
                if (HALYARD.PARALLEL_SPLIT_FUNCTION.toString().equals(node.getURI())) {