Skip to content

Commit

Permalink
hop graph model improvements. apache#3032
Browse files Browse the repository at this point in the history
  • Loading branch information
bamaer committed Nov 17, 2023
1 parent ba86833 commit 4c9596d
Show file tree
Hide file tree
Showing 17 changed files with 98 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.apache.hop.core.encryption.Encr;
import org.apache.hop.core.exception.HopConfigException;
import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.graph.model.GraphNode;
import org.apache.hop.core.graph.model.GraphRelationship;
import org.apache.hop.core.gui.plugin.GuiElementType;
import org.apache.hop.core.gui.plugin.GuiWidgetElement;
import org.apache.hop.core.logging.ILogChannel;
Expand All @@ -41,7 +43,6 @@
import org.neo4j.driver.Session;
import org.neo4j.driver.SessionConfig;
import org.neo4j.driver.Value;

import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
Expand Down Expand Up @@ -813,6 +814,30 @@ public void writeUnwindData(
String[] toPropNames,
boolean[] toPropPrimary
){
}

@Override
public void writeToGraph(
List<GraphNode> fromNodes,
List<GraphNode> toNodes,
List<Object[]> fromNodeProperties,
List<Object[]> toNodeProperties,
List<GraphRelationship> graphRelationships,
List<Object[]> relationshipProperties
){
String dummy = "";
}

@Override
public void writeNode(
List<GraphNode> fromNodes,
List<Object[]> fromNodeProperties
){
StringBuilder cypher = new StringBuilder();

cypher.append("CREATE(");



}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.hop.core.graph;

import org.apache.hop.core.graph.model.GraphNode;
import org.apache.hop.core.graph.model.GraphRelationship;
import org.apache.hop.core.gui.plugin.GuiElementType;
import org.apache.hop.core.gui.plugin.GuiWidgetElement;
import org.apache.hop.core.logging.ILogChannel;
Expand Down Expand Up @@ -244,4 +246,21 @@ public List<String> getSupportedProtocols(ILogChannel log, IHopMetadataProvider
return protocols;
}

@Override
public void writeToGraph(
List<GraphNode> fromNodes,
List<GraphNode> toNodes,
List<Object[]> fromNodeProperties,
List<Object[]> toNodeProperties,
List<GraphRelationship> graphRelationships,
List<Object[]> relationshipProperties
){}

@Override
public void writeNode(
List<GraphNode> nodes,
List<Object[]> nodeProperties
){
}

}
15 changes: 15 additions & 0 deletions core/src/main/java/org/apache/hop/core/graph/IGraphDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import org.apache.hop.core.exception.HopConfigException;
import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.graph.model.GraphNode;
import org.apache.hop.core.graph.model.GraphRelationship;
import org.apache.hop.core.variables.IVariables;
import org.apache.hop.metadata.api.HopMetadataObject;

Expand Down Expand Up @@ -129,4 +131,17 @@ public interface IGraphDatabase extends Cloneable{

void writeData(IVariables variables, String query, Map<String, Object> properties);

void writeToGraph(
List<GraphNode> fromNodes,
List<GraphNode> toNodes,
List<Object[]> fromNodeProperties,
List<Object[]> toNodeProperties,
List<GraphRelationship> graphRelationships,
List<Object[]> relationshipProperties
);

void writeNode(
List<GraphNode> nodes,
List<Object[]> nodeProperties
);
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package org.apache.hop.graphdatabases.core;
package org.apache.hop.core.graph.model;


import org.apache.hop.core.row.IValueMeta;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public abstract class GraphEntity implements IGraphEntity{

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package org.apache.hop.graphdatabases.core;

import org.apache.hop.core.row.IValueMeta;
package org.apache.hop.core.graph.model;

import java.util.Collection;
import java.util.List;
import java.util.Map;

public class GraphNode extends GraphEntity implements IGraphNode{

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.apache.hop.graphdatabases.core;
package org.apache.hop.core.graph.model;

import org.apache.hop.core.row.IValueMeta;
import org.apache.hop.core.variables.IVariables;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.apache.hop.graphdatabases.core;
package org.apache.hop.core.graph.model;

import org.apache.hop.core.row.IValueMeta;
import org.apache.hop.core.variables.IVariables;

public abstract class GraphPropertiesMeta implements IGraphProperties{

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.apache.hop.graphdatabases.core;

import org.apache.hop.core.row.IValueMeta;
package org.apache.hop.core.graph.model;

import java.util.List;
import java.util.Map;

public class GraphRelationship extends GraphEntity implements IGraphRelationship {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.apache.hop.graphdatabases.core;
package org.apache.hop.core.graph.model;

import org.apache.hop.core.row.IValueMeta;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
*/

package org.apache.hop.graphdatabases.core;
package org.apache.hop.core.graph.model;

public enum GraphUsage {
NODE_CREATE,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.apache.hop.graphdatabases.core;
package org.apache.hop.core.graph.model;

import org.apache.hop.core.row.IValueMeta;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.apache.hop.graphdatabases.core;
package org.apache.hop.core.graph.model;

public interface IGraphNode extends IGraphEntity{

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.apache.hop.graphdatabases.core;
package org.apache.hop.core.graph.model;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.apache.hop.graphdatabases.core;
package org.apache.hop.core.graph.model;

import org.apache.hop.core.row.IValueMeta;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.apache.hop.graphdatabases.core;
package org.apache.hop.core.graph.model;

public interface IGraphRelationship extends IGraphEntity{

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.apache.hop.graphdatabases.core;
package org.apache.hop.core.graph.model;

public interface IGraphRelationshipMeta extends IGraphProperties{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@
import org.apache.hop.core.graph.IGraphDatabase;
import org.apache.hop.core.row.IRowMeta;
import org.apache.hop.core.row.IValueMeta;
import org.apache.hop.core.row.RowDataUtil;
import org.apache.hop.core.row.value.ValueMetaDate;
import org.apache.hop.core.row.value.ValueMetaInteger;
import org.apache.hop.core.row.value.ValueMetaString;
import org.apache.hop.core.util.StringUtil;
import org.apache.hop.graphdatabases.core.GraphNodePropertiesMeta;
import org.apache.hop.graphdatabases.core.GraphRelationship;
import org.apache.hop.graphdatabases.core.GraphRelationshipPropertiesMeta;
import org.apache.hop.graphdatabases.core.GraphUsage;
import org.apache.hop.graphdatabases.core.GraphNode;
import org.apache.hop.core.graph.model.GraphNodePropertiesMeta;
import org.apache.hop.core.graph.model.GraphRelationship;
import org.apache.hop.core.graph.model.GraphRelationshipPropertiesMeta;
import org.apache.hop.core.graph.model.GraphUsage;
import org.apache.hop.core.graph.model.GraphNode;
import org.apache.hop.graphdatabases.model.GraphPropertyType;
import org.apache.hop.graphdatabases.shared.GraphConnectionUtils;
import org.apache.hop.graphdatabases.transforms.BaseGraphTransform;
Expand All @@ -58,6 +56,7 @@ public class GraphOutput extends BaseGraphTransform<GraphOutputMeta, GraphOutput
private GraphRelationshipPropertiesMeta relationshipPropertiesMeta;
private List<GraphNode> fromNodes, toNodes;
private List<GraphRelationship> relationships;
private GraphOutputMeta meta;
private String[] fromNodePropertyNames, toNodePropertyNames;
private Object[] fromNodePropertyValues, toNodePropertyValues;
// private Map<String, IValueMeta> fromNodeProps;
Expand Down Expand Up @@ -86,6 +85,8 @@ public GraphOutput(
super(s, meta, data, c, t, dis);
fromNodes = new ArrayList<>();
toNodes = new ArrayList<>();
relationships = new ArrayList<>();
this.meta = meta;
// fromNodeProps = new HashMap<>();
// toNodeProps = new HashMap<>();
//
Expand Down Expand Up @@ -422,8 +423,10 @@ public boolean processRow() throws HopException {

} else {


boolean changedLabel = calculateLabelsAndDetectChanges(row);
if (changedLabel || data.unwindList.size() >= data.batchSize) {
writeToGraph();
emptyUnwindList();
}

Expand Down Expand Up @@ -547,6 +550,20 @@ private void addPropertiesToMap(
}
}

private void writeToGraph() throws HopException {

IGraphDatabase graphDatabase = data.graphDatabaseMeta.getIGraphDatabase();
graphDatabase.writeNode(fromNodes, fromNodePropertyObjects);
// graphDatabase.writeToGraph(
// fromNodes,
// toNodes,
// fromNodePropertyObjects,
// toNodePropertyObjects,
// relationships,
// relationshipPropertyObjects
// );

}
private void emptyUnwindList() throws HopException {

try {
Expand Down Expand Up @@ -1240,6 +1257,7 @@ private void wrapUpTransaction() throws HopException {

if (!isStopped()) {
if (data.unwindList != null && data.unwindList.size() > 0) {
writeToGraph();
emptyUnwindList(); // force write!
}
}
Expand Down

0 comments on commit 4c9596d

Please sign in to comment.