/** * {@inheritDoc} * * The factory is passed from {@link GradoopFlinkConfig} at the moment. */ @Override public EPGMGraphHeadFactory<GraphHead> getGraphHeadFactory() { return config.getGraphHeadFactory(); }
/** * {@inheritDoc} * * The factory is passed from {@link GradoopFlinkConfig} at the moment. */ @Override public EPGMGraphHeadFactory<GraphHead> getGraphHeadFactory() { return config.getGraphHeadFactory(); }
/** * {@inheritDoc} * * The factory is passed from {@link GradoopFlinkConfig} at the moment. */ @Override public EPGMGraphHeadFactory<GraphHead> getGraphHeadFactory() { return config.getGraphHeadFactory(); }
/** * {@inheritDoc} * * The factory is passed from {@link GradoopFlinkConfig} at the moment. */ @Override public EPGMGraphHeadFactory<GraphHead> getGraphHeadFactory() { return config.getGraphHeadFactory(); }
/** * Constructor. * * @param config Gradoop configuration */ public SubgraphDecoder(GradoopFlinkConfig config) { vertexFactory = config.getVertexFactory(); graphHeadFactory = config.getGraphHeadFactory(); edgeFactory = config.getEdgeFactory(); }
/** * Valued constructor. * * @param config gradoop flink config */ public GraphTransactionFromText(GradoopFlinkConfig config) { this.graphHeadFactory = config.getGraphHeadFactory(); this.vertexFactory = config.getVertexFactory(); this.edgeFactory = config.getEdgeFactory(); }
/** * Valued constructor. * * @param config gradoop flink config */ public GraphTransactionFromText(GradoopFlinkConfig config) { this.graphHeadFactory = config.getGraphHeadFactory(); this.vertexFactory = config.getVertexFactory(); this.edgeFactory = config.getEdgeFactory(); }
/** * Constructor. * * @param config Gradoop configuration */ public SubgraphDecoder(GradoopFlinkConfig config) { vertexFactory = config.getVertexFactory(); graphHeadFactory = config.getGraphHeadFactory(); edgeFactory = config.getEdgeFactory(); }
@Override public LogicalGraphLayout<GraphHead, Vertex, Edge> fromIndexedDataSets( Map<String, DataSet<Vertex>> vertices, Map<String, DataSet<Edge>> edges) { GraphHead graphHead = getConfig() .getGraphHeadFactory() .createGraphHead(); DataSet<GraphHead> graphHeadSet = getConfig().getExecutionEnvironment() .fromElements(graphHead); Map<String, DataSet<GraphHead>> graphHeads = Maps.newHashMap(); graphHeads.put(graphHead.getLabel(), graphHeadSet); // update vertices and edges with new graph head id vertices = vertices.entrySet().stream() .collect(Collectors.toMap( Map.Entry::getKey, e -> e.getValue().map(new AddToGraph<>(graphHead)) .withForwardedFields("id;label;properties"))); edges = edges.entrySet().stream() .collect(Collectors.toMap( Map.Entry::getKey, e -> e.getValue().map(new AddToGraph<>(graphHead)) .withForwardedFields("id;sourceId;targetId;label;properties"))); return create(graphHeads, vertices, edges); }
/** * Creates a graph head dataset from a given collection. * Encapsulates the workaround for dataset creation from an empty collection. * * @param graphHeads graph heads * @return graph head dataset */ protected DataSet<GraphHead> createGraphHeadDataSet(Collection<GraphHead> graphHeads) { ExecutionEnvironment env = getConfig().getExecutionEnvironment(); DataSet<GraphHead> graphHeadSet; if (graphHeads.isEmpty()) { graphHeadSet = env .fromElements(getConfig().getGraphHeadFactory().createGraphHead()) .filter(new False<>()); } else { graphHeadSet = env.fromCollection(graphHeads); } return graphHeadSet; }
/** * Creates a graph head dataset from a given collection. * Encapsulates the workaround for dataset creation from an empty collection. * * @param graphHeads graph heads * @return graph head dataset */ protected DataSet<GraphHead> createGraphHeadDataSet(Collection<GraphHead> graphHeads) { ExecutionEnvironment env = getConfig().getExecutionEnvironment(); DataSet<GraphHead> graphHeadSet; if (graphHeads.isEmpty()) { graphHeadSet = env .fromElements(getConfig().getGraphHeadFactory().createGraphHead()) .filter(new False<>()); } else { graphHeadSet = env.fromCollection(graphHeads); } return graphHeadSet; }
@Override public GVELayout fromDataSets(DataSet<Vertex> vertices, DataSet<Edge> edges) { Objects.requireNonNull(vertices, "Vertex DataSet was null"); Objects.requireNonNull(edges, "Edge DataSet was null"); GraphHead graphHead = getConfig() .getGraphHeadFactory() .createGraphHead(); DataSet<GraphHead> graphHeadSet = getConfig().getExecutionEnvironment() .fromElements(graphHead); // update vertices and edges with new graph head id vertices = vertices .map(new AddToGraph<>(graphHead)) .withForwardedFields("id;label;properties"); edges = edges .map(new AddToGraph<>(graphHead)) .withForwardedFields("id;sourceId;targetId;label;properties"); return new GVELayout(graphHeadSet, vertices, edges); }
@Override public GVELayout fromDataSets(DataSet<Vertex> vertices, DataSet<Edge> edges) { Objects.requireNonNull(vertices, "Vertex DataSet was null"); Objects.requireNonNull(edges, "Edge DataSet was null"); GraphHead graphHead = getConfig() .getGraphHeadFactory() .createGraphHead(); DataSet<GraphHead> graphHeadSet = getConfig().getExecutionEnvironment() .fromElements(graphHead); // update vertices and edges with new graph head id vertices = vertices .map(new AddToGraph<>(graphHead)) .withForwardedFields("id;label;properties"); edges = edges .map(new AddToGraph<>(graphHead)) .withForwardedFields("id;sourceId;targetId;label;properties"); return new GVELayout(graphHeadSet, vertices, edges); }
/** * Extracts a {@link GraphCollection} from a set of {@link Element}. * * @param elements EPGM elements * @param config Gradoop Flink config * @param mayOverlap elements may be contained in multiple graphs * @return Graph collection */ @SuppressWarnings("unchecked") public static GraphCollection extractGraphCollection( DataSet<Element> elements, GradoopFlinkConfig config, boolean mayOverlap) { Class<GraphHead> graphHeadType = config.getGraphHeadFactory().getType(); Class<Vertex> vertexType = config.getVertexFactory().getType(); Class<Edge> edgeType = config.getEdgeFactory().getType(); return config.getGraphCollectionFactory().fromDataSets( extractGraphHeads(elements, graphHeadType), extractVertices(elements, vertexType, mayOverlap), extractEdges(elements, edgeType, mayOverlap) ); }
/** * Returns a logical graph containing the complete vertex and edge space of * the database. * * @param withGraphContainment true, if vertices and edges shall be updated to * be contained in the logical graph representing * the database * @return logical graph of vertex and edge space */ public LogicalGraph getLogicalGraph(boolean withGraphContainment) { if (withGraphContainment) { return config.getLogicalGraphFactory().fromCollections(getVertices(), getEdges()) .transformGraphHead(new RenameLabel<>(GradoopConstants.DEFAULT_GRAPH_LABEL, GradoopConstants.DB_GRAPH_LABEL)); } else { GraphHead graphHead = config.getGraphHeadFactory() .createGraphHead(GradoopConstants.DB_GRAPH_LABEL); return config.getLogicalGraphFactory().fromCollections(graphHead, getVertices(), getEdges()); } }
/** * Returns a logical graph containing the complete vertex and edge space of * the database. * * @param withGraphContainment true, if vertices and edges shall be updated to * be contained in the logical graph representing * the database * @return logical graph of vertex and edge space */ public LogicalGraph getLogicalGraph(boolean withGraphContainment) { if (withGraphContainment) { return config.getLogicalGraphFactory().fromCollections(getVertices(), getEdges()) .transformGraphHead(new RenameLabel<>(GradoopConstants.DEFAULT_GRAPH_LABEL, GradoopConstants.DB_GRAPH_LABEL)); } else { GraphHead graphHead = config.getGraphHeadFactory() .createGraphHead(GradoopConstants.DB_GRAPH_LABEL); return config.getLogicalGraphFactory().fromCollections(graphHead, getVertices(), getEdges()); } }
@BeforeClass public static void setup() { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); GradoopFlinkConfig config = GradoopFlinkConfig.createConfig(env); GraphHead g0 = config.getGraphHeadFactory().createGraphHead("A"); GraphHead g1 = config.getGraphHeadFactory().createGraphHead("B"); Vertex v0 = config.getVertexFactory().createVertex("A"); Vertex v1 = config.getVertexFactory().createVertex("B"); Vertex v2 = config.getVertexFactory().createVertex("C"); Edge e0 = config.getEdgeFactory().createEdge("a", v0.getId(), v1.getId()); Edge e1 = config.getEdgeFactory().createEdge("b", v1.getId(), v2.getId()); v0.addGraphId(g0.getId()); v1.addGraphId(g0.getId()); v1.addGraphId(g1.getId()); v2.addGraphId(g1.getId()); e0.addGraphId(g0.getId()); e1.addGraphId(g1.getId()); tx0 = new GraphTransaction(g0, Sets.newHashSet(v0, v1), Sets.newHashSet(e0)); tx1 = new GraphTransaction(g1, Sets.newHashSet(v1, v2), Sets.newHashSet(e1)); }
@BeforeClass public static void setup() { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); GradoopFlinkConfig config = GradoopFlinkConfig.createConfig(env); g0 = config.getGraphHeadFactory().createGraphHead("A"); g1 = config.getGraphHeadFactory().createGraphHead("B"); v0 = config.getVertexFactory().createVertex("A"); v1 = config.getVertexFactory().createVertex("B"); v2 = config.getVertexFactory().createVertex("C"); e0 = config.getEdgeFactory().createEdge("a", v0.getId(), v1.getId()); e1 = config.getEdgeFactory().createEdge("b", v1.getId(), v2.getId()); v0.addGraphId(g0.getId()); v1.addGraphId(g0.getId()); v1.addGraphId(g1.getId()); v2.addGraphId(g1.getId()); e0.addGraphId(g0.getId()); e1.addGraphId(g1.getId()); }
@Override public GraphCollection getGraphCollection() { DataSet<Tuple3<String, String, String>> metaData = new CSVMetaDataSource().readDistributed(getMetaDataPath(), getConfig()); DataSet<GraphHead> graphHeads = getConfig().getExecutionEnvironment() .readTextFile(getGraphHeadCSVPath()) .map(new CSVLineToGraphHead(getConfig().getGraphHeadFactory())) .withBroadcastSet(metaData, BC_METADATA); DataSet<Vertex> vertices = getConfig().getExecutionEnvironment() .readTextFile(getVertexCSVPath()) .map(new CSVLineToVertex(getConfig().getVertexFactory())) .withBroadcastSet(metaData, BC_METADATA); DataSet<Edge> edges = getConfig().getExecutionEnvironment() .readTextFile(getEdgeCSVPath()) .map(new CSVLineToEdge(getConfig().getEdgeFactory())) .withBroadcastSet(metaData, BC_METADATA); return getConfig().getGraphCollectionFactory().fromDataSets(graphHeads, vertices, edges); } }
@Override public GraphCollection getGraphCollection() { DataSet<Tuple3<String, String, String>> metaData = new CSVMetaDataSource().readDistributed(getMetaDataPath(), getConfig()); DataSet<GraphHead> graphHeads = getConfig().getExecutionEnvironment() .readTextFile(getGraphHeadCSVPath()) .map(new CSVLineToGraphHead(getConfig().getGraphHeadFactory())) .withBroadcastSet(metaData, BC_METADATA); DataSet<Vertex> vertices = getConfig().getExecutionEnvironment() .readTextFile(getVertexCSVPath()) .map(new CSVLineToVertex(getConfig().getVertexFactory())) .withBroadcastSet(metaData, BC_METADATA); DataSet<Edge> edges = getConfig().getExecutionEnvironment() .readTextFile(getEdgeCSVPath()) .map(new CSVLineToEdge(getConfig().getEdgeFactory())) .withBroadcastSet(metaData, BC_METADATA); return getConfig().getGraphCollectionFactory().fromDataSets(graphHeads, vertices, edges); } }