Skip to content

Commit

Permalink
Align procedure results between different modes
Browse files Browse the repository at this point in the history
Co-authored-by: Veselin Nikolov <veselin.nikolov@neotechnology.com>
  • Loading branch information
IoannisPanagiotas and vnickolov committed Aug 8, 2024
1 parent 2693ab9 commit 15c4f32
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,58 +19,14 @@
*/
package org.neo4j.gds.procedures.algorithms.centrality;

import org.neo4j.gds.applications.algorithms.machinery.AlgorithmProcessingTimings;
import org.neo4j.gds.procedures.algorithms.results.StandardMutateResult;
import org.neo4j.gds.result.AbstractResultBuilder;

import java.util.Map;

public class ArticulationPointsMutateResult extends StandardMutateResult {
public final long articulationPointCount;
public final long nodePropertiesWritten;

public ArticulationPointsMutateResult(
long mutateMillis,
long nodePropertiesWritten,
long computeMillis,
Map<String, Object> configuration,
long articulationPointCount
) {
super(0,computeMillis,0,mutateMillis,configuration);
this.articulationPointCount = articulationPointCount;
this.nodePropertiesWritten = nodePropertiesWritten;
}
public static Builder builder() {
return new Builder();
}


public static ArticulationPointsMutateResult emptyFrom(AlgorithmProcessingTimings timings, Map<String, Object> configurationMap) {
return new ArticulationPointsMutateResult(
timings.mutateOrWriteMillis,
0,
timings.computeMillis,
configurationMap,
0
);
}

public static class Builder extends AbstractResultBuilder<ArticulationPointsMutateResult> {
private long articulationPointCount;;

public ArticulationPointsMutateResult.Builder withArticulationPointCount(long articulationPointCount) {
this.articulationPointCount = articulationPointCount;
return this;
}

public ArticulationPointsMutateResult build() {
return new ArticulationPointsMutateResult(
mutateMillis,
nodePropertiesWritten,
computeMillis,
config.toMap(),
articulationPointCount
);
}
}
public record ArticulationPointsMutateResult(
long articulationPointCount,
long nodePropertiesWritten,
long mutateMillis,
long computeMillis,
Map<String, Object> configuration
) {
public static final ArticulationPointsMutateResult EMPTY = new ArticulationPointsMutateResult(0, 0, 0, 0, Map.of());
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ public Stream<ArticulationPointsStatsResult> build(
Optional<Void> metadata
) {
if (result.isEmpty()) {
return Stream.of(ArticulationPointsStatsResult.emptyFrom(timings,configuration.toMap()));
return Stream.of(ArticulationPointsStatsResult.EMPTY);
}

var bitSet = result.get();
return Stream.of(
new ArticulationPointsStatsResult(
timings.computeMillis,
configuration.toMap(),
bitSet.cardinality()
)
bitSet.cardinality(),
timings.computeMillis,
configuration.toMap()
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public Stream<ArticulationPointsWriteResult> build(
metadata.map(n -> n.value).orElseThrow(),
timings.mutateOrWriteMillis,
timings.computeMillis,
graph.nodeCount(),
configuration.toMap()
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,12 @@
*/
package org.neo4j.gds.procedures.algorithms.centrality;

import org.neo4j.gds.applications.algorithms.machinery.AlgorithmProcessingTimings;
import org.neo4j.gds.procedures.algorithms.results.StandardStatsResult;
import org.neo4j.gds.result.AbstractResultBuilder;

import java.util.Map;

public class ArticulationPointsStatsResult extends StandardStatsResult {
public final long articulationPointCount;

public ArticulationPointsStatsResult(
long computeMillis,
Map<String, Object> configuration,
long articulationPointCount
) {
super(0,computeMillis,0,configuration);
this.articulationPointCount = articulationPointCount;
}
public static Builder builder() {
return new Builder();
}


public static ArticulationPointsStatsResult emptyFrom(AlgorithmProcessingTimings timings, Map<String, Object> configurationMap) {
return new ArticulationPointsStatsResult(
timings.computeMillis,
configurationMap,
0
);
}

public static class Builder extends AbstractResultBuilder<ArticulationPointsStatsResult> {
private long articulationPointCount;;

public ArticulationPointsStatsResult.Builder withArticulationPointCount(long articulationPointCount) {
this.articulationPointCount = articulationPointCount;
return this;
}

public ArticulationPointsStatsResult build() {
return new ArticulationPointsStatsResult(
computeMillis,
config.toMap(),
articulationPointCount
);
}
}
public record ArticulationPointsStatsResult(
long articulationPointCount,
long computeMillis,
Map<String, Object> configuration
) {
public static final ArticulationPointsStatsResult EMPTY = new ArticulationPointsStatsResult(0, 0, Map.of());
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public record ArticulationPointsWriteResult(
long nodePropertiesWritten,
long writeMillis,
long computeMillis,
long nodeCount,
Map<String, Object> configuration
) {
public static final ArticulationPointsWriteResult EMPTY = new ArticulationPointsWriteResult(0, 0, 0, 0, 0, Map.of());
public static final ArticulationPointsWriteResult EMPTY = new ArticulationPointsWriteResult(0, 0, 0, 0, Map.of());
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,16 @@ public ArticulationPointsMutateResult build(
AlgorithmProcessingTimings timings,
Optional<NodePropertiesWritten> metadata
) {
if (result.isEmpty()) return ArticulationPointsMutateResult.emptyFrom(timings, configuration.toMap());
if (result.isEmpty()) return ArticulationPointsMutateResult.EMPTY;

var articulationPointsResult = result.get();

return ArticulationPointsMutateResult.builder()
.withArticulationPointCount(articulationPointsResult.cardinality())
.withPreProcessingMillis(timings.preProcessingMillis)
.withComputeMillis(timings.computeMillis)
.withMutateMillis(timings.mutateOrWriteMillis)
.withNodePropertiesWritten(metadata.orElseThrow().value)
.withConfig(configuration)
.build();
var bitSet = result.get();
return new ArticulationPointsMutateResult(
bitSet.cardinality(),
metadata.map(n -> n.value).orElseThrow(),
timings.mutateOrWriteMillis,
timings.computeMillis,
configuration.toMap()
);
}
}

0 comments on commit 15c4f32

Please sign in to comment.