You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@rya.apache.org by meiercaleb <gi...@git.apache.org> on 2017/08/08 20:20:50 UTC

[GitHub] incubator-rya pull request #172: RYA-303 Mongo PCJ Support

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

    https://github.com/apache/incubator-rya/pull/172#discussion_r132020821
  
    --- Diff: extras/indexing/src/main/java/org/apache/rya/indexing/mongodb/pcj/BasePcjIndexer.java ---
    @@ -0,0 +1,138 @@
    +/*
    + * 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.indexing.mongodb.pcj;
    +
    +import static com.google.common.base.Preconditions.checkState;
    +import static java.util.Collections.singleton;
    +import static java.util.Objects.requireNonNull;
    +import static java.util.stream.Collectors.groupingBy;
    +
    +import java.io.IOException;
    +import java.util.Collection;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Map.Entry;
    +import java.util.Set;
    +import java.util.concurrent.atomic.AtomicReference;
    +
    +import org.apache.hadoop.conf.Configuration;
    +import org.apache.rya.api.domain.RyaStatement;
    +import org.apache.rya.api.domain.RyaURI;
    +import org.apache.rya.indexing.entity.model.Entity;
    +import org.apache.rya.indexing.entity.storage.EntityStorage;
    +import org.apache.rya.indexing.entity.storage.EntityStorage.EntityStorageException;
    +import org.apache.rya.indexing.pcj.storage.mongo.MongoPcjDocuments;
    +import org.apache.rya.mongodb.MongoDBRdfConfiguration;
    +import org.apache.rya.mongodb.MongoSecondaryIndex;
    +import org.openrdf.model.URI;
    +
    +import edu.umd.cs.findbugs.annotations.DefaultAnnotation;
    +import edu.umd.cs.findbugs.annotations.NonNull;
    +
    +/**
    + * A base class that may be used to update an {@link EntityStorage} as new
    + * {@link RyaStatement}s are added to/removed from the Rya instance.
    + */
    +@DefaultAnnotation(NonNull.class)
    +public abstract class BasePcjIndexer implements PcjIndexer, MongoSecondaryIndex {
    +
    +    private final AtomicReference<MongoDBRdfConfiguration> configuration = new AtomicReference<>();
    +    private final AtomicReference<MongoPcjDocuments> pcjDocs = new AtomicReference<>();
    +
    +    @Override
    +    public void setConf(final Configuration conf) {
    +        requireNonNull(conf);
    +        pcjDocs.set( getPcjStorage(conf) );
    +    }
    +
    +    @Override
    +    public Configuration getConf() {
    +        return configuration.get();
    +    }
    +
    +    @Override
    +    public void storeStatement(final RyaStatement statement) throws IOException {
    +        requireNonNull(statement);
    +        storeStatements( singleton(statement) );
    +    }
    +
    +    @Override
    +    public void storeStatements(final Collection<RyaStatement> statements) throws IOException {
    +        requireNonNull(statements);
    +
    +        final Map<RyaURI,List<RyaStatement>> groupedBySubject = statements.stream()
    +            .collect(groupingBy(RyaStatement::getSubject));
    +
    +        for(final Entry<RyaURI, List<RyaStatement>> entry : groupedBySubject.entrySet()) {
    +            try {
    +                updateEntity(entry.getKey(), entry.getValue());
    +            } catch (final EntityStorageException e) {
    +                throw new IOException("Failed to update the Entity index.", e);
    +            }
    +        }
    +    }
    +
    +    /**
    +     * Updates a {@link Entity} to reflect new {@link RyaStatement}s.
    +     *
    +     * @param subject - The Subject of the {@link Entity} the statements are for. (not null)
    +     * @param statements - Statements that the {@link Entity} will be updated with. (not null)
    +     */
    +    private void updateEntity(final RyaURI subject, final Collection<RyaStatement> statements) throws EntityStorageException {
    +        requireNonNull(subject);
    --- End diff --
    
    Agreed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---