Skip to content
Permalink
Browse files

Merge pull request #128 from mattcasters/master

Issues #124 and #125, bug fixes and performance tuning
  • Loading branch information...
mattcasters committed Apr 22, 2019
2 parents 5fdc05f + c0b560d commit 6179bbaa86ade929aeadbd3eec66bbe52fb3879b
@@ -309,7 +309,7 @@ private void runCypherStatement( Object[] row, String cypher, Map<String, Object
private StatementResult writeUnwindList() throws KettleException {
HashMap<String, Object> unwindMap = new HashMap<>();
unwindMap.put( data.unwindMapName, data.unwindList );
StatementResult result;
StatementResult result = null;
try {
try {
if ( meta.isReadOnly() ) {
@@ -328,6 +328,13 @@ private StatementResult writeUnwindList() throws KettleException {
result = data.session.writeTransaction( tx -> tx.run( data.cypher, unwindMap ) );
}
}

if (result!=null) {
List<Object[]> resultRows = writeResultRows( result, new Object[ 0 ], true );
for (Object[] resultRow : resultRows) {
putRow(data.outputRowMeta, resultRow);
}
}
} catch ( Exception e ) {
data.session.close();
stopAll();
@@ -244,14 +244,8 @@ private void addPropertiesToMap( Map<String, Object> rowMap, String alias, int[]
GraphPropertyType propertyType = propertyTypes[ i ];
Object neoValue = propertyType.convertFromKettle( valueMeta, valueData );

String propName;
if ( StringUtils.isNotEmpty( nodePropNames[ i ] ) ) {
propName = nodePropNames[ i ];
} else {
propName = valueMeta.getName(); // Take the name from the input field.
}

rowMap.put( alias + "_" + propName, neoValue );
String propName = "p"+nodePropIndexes[i];
rowMap.put( propName, neoValue );
}
}

@@ -275,11 +269,11 @@ private void emptyUnwindList( boolean changedLabel ) throws KettleException {
.append( "CREATE( " )
.append( data.fromLabelsClause )
.append( " " )
.append( getMatchClause( meta.getFromNodePropNames(), meta.getFromNodePropPrimary(), "f" ) )
.append( getMatchClause( meta.getFromNodePropNames(), meta.getFromNodePropPrimary(), data.fromNodePropIndexes, "f" ) )
.append( ") " )
.append( Const.CR )
;
String setClause = getSetClause( false, "f", meta.getFromNodePropNames(), meta.getFromNodePropPrimary() );
String setClause = getSetClause( false, "f", meta.getFromNodePropNames(), meta.getFromNodePropPrimary(), data.fromNodePropIndexes );
if ( StringUtils.isNotEmpty( setClause ) ) {
cypher
.append( setClause )
@@ -293,11 +287,11 @@ private void emptyUnwindList( boolean changedLabel ) throws KettleException {
.append( "MERGE( " )
.append( data.fromLabelsClause )
.append( " " )
.append( getMatchClause( meta.getFromNodePropNames(), meta.getFromNodePropPrimary(), "f" ) )
.append( getMatchClause( meta.getFromNodePropNames(), meta.getFromNodePropPrimary(), data.fromNodePropIndexes, "f" ) )
.append( ") " )
.append( Const.CR )
;
setClause = getSetClause( false, "f", meta.getFromNodePropNames(), meta.getFromNodePropPrimary() );
setClause = getSetClause( false, "f", meta.getFromNodePropNames(), meta.getFromNodePropPrimary(), data.fromNodePropIndexes );
if ( StringUtils.isNotEmpty( setClause ) ) {
cypher
.append( setClause )
@@ -311,7 +305,7 @@ private void emptyUnwindList( boolean changedLabel ) throws KettleException {
.append( "MATCH( " )
.append( data.fromLabelsClause )
.append( " " )
.append( getMatchClause( meta.getFromNodePropNames(), meta.getFromNodePropPrimary(), "f" ) )
.append( getMatchClause( meta.getFromNodePropNames(), meta.getFromNodePropPrimary(), data.fromNodePropIndexes, "f" ) )
.append( ") " )
.append( Const.CR )
;
@@ -331,11 +325,11 @@ private void emptyUnwindList( boolean changedLabel ) throws KettleException {
.append( "CREATE( " )
.append( data.toLabelsClause )
.append( " " )
.append( getMatchClause( meta.getToNodePropNames(), meta.getToNodePropPrimary(), "t" ) )
.append( getMatchClause( meta.getToNodePropNames(), meta.getToNodePropPrimary(), data.toNodePropIndexes, "t" ) )
.append( ") " )
.append( Const.CR )
;
String setClause = getSetClause( false, "t", meta.getToNodePropNames(), meta.getToNodePropPrimary() );
String setClause = getSetClause( false, "t", meta.getToNodePropNames(), meta.getToNodePropPrimary(), data.toNodePropIndexes );
if ( StringUtils.isNotEmpty( setClause ) ) {
cypher
.append( setClause )
@@ -349,11 +343,11 @@ private void emptyUnwindList( boolean changedLabel ) throws KettleException {
.append( "MERGE( " )
.append( data.toLabelsClause )
.append( " " )
.append( getMatchClause( meta.getToNodePropNames(), meta.getToNodePropPrimary(), "t" ) )
.append( getMatchClause( meta.getToNodePropNames(), meta.getToNodePropPrimary(), data.toNodePropIndexes, "t" ) )
.append( ") " )
.append( Const.CR )
;
setClause = getSetClause( false, "t", meta.getToNodePropNames(), meta.getToNodePropPrimary() );
setClause = getSetClause( false, "t", meta.getToNodePropNames(), meta.getToNodePropPrimary(), data.toNodePropIndexes );
if ( StringUtils.isNotEmpty( setClause ) ) {
cypher
.append( setClause )
@@ -367,7 +361,7 @@ private void emptyUnwindList( boolean changedLabel ) throws KettleException {
.append( "MATCH( " )
.append( data.toLabelsClause )
.append( " " )
.append( getMatchClause( meta.getToNodePropNames(), meta.getToNodePropPrimary(), "t" ) )
.append( getMatchClause( meta.getToNodePropNames(), meta.getToNodePropPrimary(),data.toNodePropIndexes, "t" ) )
.append( ") " )
.append( Const.CR )
;
@@ -389,7 +383,7 @@ private void emptyUnwindList( boolean changedLabel ) throws KettleException {
.append( data.relationshipLabel )
.append( "]->(t) " )
.append( Const.CR )
.append( getSetClause( false, "r", meta.getRelPropNames(), new boolean[ meta.getRelPropNames().length ] ) )
.append( getSetClause( false, "r", meta.getRelPropNames(), new boolean[ meta.getRelPropNames().length ], data.relPropIndexes ) )
.append( Const.CR )
;
updateUsageMap( Arrays.asList( data.relationshipLabel ), GraphUsage.RELATIONSHIP_UPDATE);
@@ -402,7 +396,7 @@ private void emptyUnwindList( boolean changedLabel ) throws KettleException {
.append( data.relationshipLabel )
.append( "]->(t) " )
.append( Const.CR )
.append( getSetClause( false, "r", meta.getRelPropNames(), new boolean[ meta.getRelPropNames().length ] ) )
.append( getSetClause( false, "r", meta.getRelPropNames(), new boolean[ meta.getRelPropNames().length ], data.relPropIndexes ) )
.append( Const.CR )
;
updateUsageMap( Arrays.asList( data.relationshipLabel ), GraphUsage.RELATIONSHIP_CREATE);
@@ -414,7 +408,7 @@ private void emptyUnwindList( boolean changedLabel ) throws KettleException {

// OK now we have the cypher statement, we can execute it...
//
if ( isDebug() ) {
if ( log.isDebug() ) {
logDebug( "Running Cypher: " + data.cypher );
logDebug( "properties list size : " + data.unwindList.size() );
}
@@ -431,7 +425,8 @@ private void emptyUnwindList( boolean changedLabel ) throws KettleException {
data.unwindList.clear();
}

private String getMatchClause( String[] propertyNames, boolean[] propertyPrimary, String alias ) {

private String getMatchClause( String[] propertyNames, boolean[] propertyPrimary, int[] nodePropIndexes, String alias ) {
StringBuilder clause = new StringBuilder();

for ( int i = 0; i < propertyNames.length; i++ ) {
@@ -441,10 +436,9 @@ private String getMatchClause( String[] propertyNames, boolean[] propertyPrimary
}
clause
.append( propertyNames[ i ] )
.append( ": pr." )
.append( alias )
.append( "_" )
.append( propertyNames[ i ] );
.append( ": pr.p" )
.append( nodePropIndexes[i] )
;
}
}

@@ -455,7 +449,7 @@ private String getMatchClause( String[] propertyNames, boolean[] propertyPrimary
}
}

private String getSetClause( boolean allProperties, String alias, String[] propertyNames, boolean[] propertyPrimary ) {
private String getSetClause( boolean allProperties, String alias, String[] propertyNames, boolean[] propertyPrimary, int[] nodePropIndexes ) {
StringBuilder clause = new StringBuilder();

for ( int i = 0; i < propertyNames.length; i++ ) {
@@ -467,10 +461,8 @@ private String getSetClause( boolean allProperties, String alias, String[] prope
.append( alias )
.append( "." )
.append( propertyNames[ i ] )
.append( "= pr." )
.append( alias )
.append( "_" )
.append( propertyNames[ i ] )
.append( "= pr.p" )
.append( nodePropIndexes[i])
;
}
}

0 comments on commit 6179bba

Please sign in to comment.
You can’t perform that action at this time.