All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.vertexium.accumulo.mapreduce.AccumuloVertexInputFormat Maven / Gradle / Ivy

There is a newer version: 4.10.0
Show newest version
package org.vertexium.accumulo.mapreduce;

import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.util.PeekingIterator;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.vertexium.*;
import org.vertexium.accumulo.AccumuloGraph;
import org.vertexium.accumulo.AccumuloVertex;
import org.vertexium.accumulo.iterator.VertexIterator;
import org.vertexium.accumulo.iterator.model.VertexElementData;
import org.vertexium.mutation.PropertyDeleteMutation;
import org.vertexium.mutation.PropertySoftDeleteMutation;

import javax.annotation.Nullable;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.Map;

public class AccumuloVertexInputFormat extends AccumuloElementInputFormatBase {
    private static VertexIterator vertexIterator;

    public static void setInputInfo(Job job, AccumuloGraph graph, String instanceName, String zooKeepers, String principal, AuthenticationToken token, String[] authorizations) throws AccumuloSecurityException {
        String tableName = graph.getVerticesTableName();
        setInputInfo(job, instanceName, zooKeepers, principal, token, authorizations, tableName);
    }

    @Override
    protected Vertex createElementFromRow(AccumuloGraph graph, PeekingIterator> row, Authorizations authorizations) {
        return createVertex(graph, row, authorizations);
    }

    public static Vertex createVertex(AccumuloGraph graph, Iterator> row, Authorizations authorizations) {
        try {
            FetchHints fetchHints = graph.getDefaultFetchHints();
            VertexElementData vertexElementData = getVertexIterator(graph).createElementDataFromRows(row);
            if (vertexElementData == null) {
                return null;
            }
            Visibility visibility = AccumuloGraph.accumuloVisibilityToVisibility(AccumuloGraph.visibilityToAccumuloVisibility(vertexElementData.visibility.toString()));
            Iterable properties = makePropertiesFromElementData(graph, vertexElementData, graph.toIteratorFetchHints(fetchHints));
            Iterable propertyDeleteMutations = null;
            Iterable propertySoftDeleteMutations = null;
            Iterable hiddenVisibilities = Iterables.transform(vertexElementData.hiddenVisibilities, new Function() {
                @Nullable
                @Override
                public Visibility apply(Text visibilityText) {
                    return AccumuloGraph.accumuloVisibilityToVisibility(AccumuloGraph.visibilityToAccumuloVisibility(visibilityText.toString()));
                }
            });
            ImmutableSet extendedDataTableNames = vertexElementData.extendedTableNames.size() > 0
                    ? ImmutableSet.copyOf(vertexElementData.extendedTableNames)
                    : null;
            return new AccumuloVertex(
                    graph,
                    vertexElementData.id.toString(),
                    visibility,
                    properties,
                    propertyDeleteMutations,
                    propertySoftDeleteMutations,
                    hiddenVisibilities,
                    extendedDataTableNames,
                    vertexElementData.inEdges,
                    vertexElementData.outEdges,
                    vertexElementData.timestamp,
                    fetchHints,
                    authorizations
            );
        } catch (Throwable ex) {
            throw new VertexiumException("Failed to create vertex", ex);
        }
    }

    private static VertexIterator getVertexIterator(AccumuloGraph graph) {
        if (vertexIterator == null) {
            vertexIterator = new VertexIterator(graph.toIteratorFetchHints(graph.getDefaultFetchHints()));
        }
        return vertexIterator;
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy