Skip to content

Commit

Permalink
Graph stores don't know about Neo4j settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jjaderberg committed Aug 26, 2024
1 parent 83a3af1 commit 1823c02
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@
*/
package org.neo4j.gds.core.utils;

import org.neo4j.gds.settings.Neo4jSettings;

import java.time.Clock;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public final class TimeUtil {

public static ZonedDateTime now() {
var zoneId = Neo4jSettings.dbTemporalTimezone().defaultValue();
public static ZonedDateTime now(ZoneId zoneId) {
return ZonedDateTime.now(Clock.system(zoneId != null ? zoneId : ZoneId.systemDefault()));
}

private TimeUtil() {}
}
16 changes: 11 additions & 5 deletions core/src/main/java/org/neo4j/gds/core/loading/CSRGraphStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.neo4j.gds.core.utils.TimeUtil;
import org.neo4j.gds.utils.StringJoining;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -94,6 +95,7 @@ public final class CSRGraphStore implements GraphStore {

private NodePropertyStore nodeProperties;

private final ZoneId zoneId;
private final ZonedDateTime creationTime;
private ZonedDateTime modificationTime;

Expand All @@ -105,7 +107,8 @@ private CSRGraphStore(
NodePropertyStore nodeProperties,
Map<RelationshipType, SingleTypeRelationships> relationships,
GraphPropertyStore graphProperties,
Concurrency concurrency
Concurrency concurrency,
ZoneId zoneId
) {
this.databaseInfo = databaseInfo;
this.capabilities = capabilities;
Expand All @@ -121,7 +124,8 @@ private CSRGraphStore(
this.relationships = new HashMap<>(relationships);

this.concurrency = concurrency;
this.creationTime = TimeUtil.now();
this.zoneId = zoneId;
this.creationTime = TimeUtil.now(zoneId);
this.modificationTime = this.creationTime;
}

Expand All @@ -133,7 +137,8 @@ public static CSRGraphStore of(
Nodes nodes,
RelationshipImportResult relationshipImportResult,
Optional<GraphPropertyStore> graphProperties,
Concurrency concurrency
Concurrency concurrency,
Optional<ZoneId> zoneId
) {
return new CSRGraphStore(
databaseInfo,
Expand All @@ -143,7 +148,8 @@ public static CSRGraphStore of(
nodes.properties(),
relationshipImportResult.importResults(),
graphProperties.orElseGet(GraphPropertyStore::empty),
concurrency
concurrency,
zoneId.orElseGet(ZoneId::systemDefault)
);
}

Expand Down Expand Up @@ -585,7 +591,7 @@ public long nodeCount() {

private synchronized void updateGraphStore(Consumer<CSRGraphStore> updateFunction) {
updateFunction.accept(this);
this.modificationTime = TimeUtil.now();
this.modificationTime = TimeUtil.now(zoneId);
}

private CSRGraph createGraph(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.neo4j.gds.ml.models.automl.TunableTrainerConfig;
import org.neo4j.gds.core.utils.TimeUtil;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.EnumMap;
Expand Down Expand Up @@ -52,10 +53,10 @@ public static Map<String, List<Map<String, Object>>> toMapParameterSpace(Map<Tra
));
}

protected TrainingPipeline(TrainingType trainingType) {
protected TrainingPipeline(TrainingType trainingType, ZoneId zoneId) {
this.nodePropertySteps = new ArrayList<>();
this.featureSteps = new ArrayList<>();
this.creationTime = TimeUtil.now();
this.creationTime = TimeUtil.now(zoneId);

this.trainingParameterSpace = new EnumMap<>(TrainingMethod.class);
this.autoTuningConfig = AutoTuningConfig.DEFAULT_CONFIG;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.neo4j.gds.executor.ExecutionContext;
import org.neo4j.gds.ml.pipeline.ExecutableNodePropertyStep;
import org.neo4j.gds.ml.pipeline.TrainingPipeline;
import org.neo4j.gds.settings.Neo4jSettings;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -44,7 +45,7 @@ public class LinkPredictionTrainingPipeline extends TrainingPipeline<LinkFeature
private LinkPredictionSplitConfig splitConfig;

public LinkPredictionTrainingPipeline() {
super(TrainingType.CLASSIFICATION);
super(TrainingType.CLASSIFICATION, Neo4jSettings.dbTemporalTimezone().defaultValue());
this.splitConfig = LinkPredictionSplitConfig.DEFAULT_CONFIG;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.neo4j.gds.config.ToMapConvertible;
import org.neo4j.gds.ml.pipeline.TrainingPipeline;
import org.neo4j.gds.settings.Neo4jSettings;

import java.util.List;
import java.util.Map;
Expand All @@ -30,7 +31,7 @@ public abstract class NodePropertyTrainingPipeline extends TrainingPipeline<Node
protected NodePropertyPredictionSplitConfig splitConfig;

protected NodePropertyTrainingPipeline(TrainingType trainingType) {
super(trainingType);
super(trainingType, Neo4jSettings.dbTemporalTimezone().defaultValue());
this.splitConfig = NodePropertyPredictionSplitConfig.DEFAULT_CONFIG;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.neo4j.gds.logging.GdsTestLog;
import org.neo4j.gds.ml.pipeline.linkPipeline.LinkPredictionPredictPipeline;
import org.neo4j.gds.ml.pipeline.linkPipeline.linkfunctions.L2FeatureStep;
import org.neo4j.gds.settings.Neo4jSettings;

import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -259,7 +260,7 @@ protected String execute(Map<DatasetSplits, PipelineGraphFilter> dataSplits) {

private class BogusNodePropertyPipeline extends TrainingPipeline<FeatureStep> {

BogusNodePropertyPipeline() {super(TrainingType.REGRESSION);}
BogusNodePropertyPipeline() {super(TrainingType.REGRESSION, Neo4jSettings.dbTemporalTimezone().defaultValue());}

@Override
public List<ExecutableNodePropertyStep> nodePropertySteps() {
Expand Down Expand Up @@ -293,7 +294,7 @@ public void validateFeatureProperties(GraphStore graphStore, Collection<NodeLabe

private class FailingNodePropertyPipeline extends TrainingPipeline<FeatureStep> {

FailingNodePropertyPipeline() {super(TrainingType.CLASSIFICATION);}
FailingNodePropertyPipeline() {super(TrainingType.CLASSIFICATION, Neo4jSettings.dbTemporalTimezone().defaultValue());}

@Override
public List<ExecutableNodePropertyStep> nodePropertySteps() {
Expand Down

0 comments on commit 1823c02

Please sign in to comment.