[ 
https://issues.apache.org/jira/browse/RYA-416?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16321197#comment-16321197
 ] 

ASF GitHub Bot commented on RYA-416:
------------------------------------

Github user jessehatfield commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/254#discussion_r160811757
  
    --- Diff: 
dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/aggregation/AggregationPipelineQueryOptimizer.java
 ---
    @@ -0,0 +1,67 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you 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 org.apache.rya.mongodb.aggregation;
    +
    +import org.apache.hadoop.conf.Configurable;
    +import org.apache.hadoop.conf.Configuration;
    +import org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration;
    +import org.openrdf.query.BindingSet;
    +import org.openrdf.query.Dataset;
    +import org.openrdf.query.algebra.TupleExpr;
    +import org.openrdf.query.algebra.evaluation.QueryOptimizer;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +/**
    + * MongoDB-specific query optimizer that replaces part or all of a SPARQL 
query
    + * tree with a MongoDB aggregation pipeline.
    + * <p>
    + * Transforms query trees using {@link SparqlToPipelineTransformVisitor}. 
If
    + * possible, this visitor will replace portions of the query tree, or the 
entire
    + * query, with an equivalent aggregation pipeline (contained in an
    + * {@link AggregationPipelineQueryNode}), thereby allowing query logic to 
be
    + * evaluated by the MongoDB server rather than by the client.
    + */
    +public class AggregationPipelineQueryOptimizer implements QueryOptimizer, 
Configurable {
    +    private Configuration conf;
    +    private Logger logger = LoggerFactory.getLogger(getClass());
    +
    +    @Override
    +    public void optimize(TupleExpr tupleExpr, Dataset dataset, BindingSet 
bindings) {
    +        if (conf instanceof StatefulMongoDBRdfConfiguration) {
    +            StatefulMongoDBRdfConfiguration mongoConf = 
(StatefulMongoDBRdfConfiguration) conf;
    +            SparqlToPipelineTransformVisitor pipelineVisitor = new 
SparqlToPipelineTransformVisitor(mongoConf);
    +            try {
    +                tupleExpr.visit(pipelineVisitor);
    +            } catch (Exception e) {
    +                logger.error("Error attempting to transform query using 
the aggregation pipeline", e);
    +            }
    +        }
    +    }
    +
    +    @Override
    +    public void setConf(Configuration conf) {
    +        this.conf = conf;
    --- End diff --
    
    Agreed, fixed.


> Add the ability use the MongoDB aggregation pipeline to evaluate simple 
> SPARQL expressions
> ------------------------------------------------------------------------------------------
>
>                 Key: RYA-416
>                 URL: https://issues.apache.org/jira/browse/RYA-416
>             Project: Rya
>          Issue Type: New Feature
>            Reporter: Jesse Hatfield
>            Assignee: Jesse Hatfield
>
> MongoDB provides the [aggregation pipeline 
> framework|https://docs.mongodb.com/manual/core/aggregation-pipeline/] for 
> multi-stage data processing. Currently, the query engine invokes this 
> framework to apply individual statement patterns (using a "$match" expression 
> for each and iterating through the results), then applies higher-level query 
> operations (join, filter, select, project, etc) client-side.
> In principle, those high-level query operations could be rewritten as 
> aggregation pipeline stages as well ($group, $match, $project, etc). This 
> would allow more query evaluation logic to be executed by the MongoDB server 
> itself, enabling server-side optimization. This could be used as a general 
> query optimization, but would additionally be useful for any tool that only 
> needed to write query results back to the server: adding a write step to the 
> end of the resulting pipeline could obviate the need to communicate 
> individual results to the client at all.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to