-
Notifications
You must be signed in to change notification settings - Fork 976
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix node target reference lookup and node match mode (#1961)
* Fix node target reference lookup and node match mode Make node match mode mandatory. Look up all active node targets when resolving start/end node target references, not just the active node targets sharing the relationship target's source. * Update to latest release of import-spec It contains a couple of required fixes around property helpers * fix: look up active node targets only * Simplify test spec Use simpler IDs, remove unused property types * fix: add missing start/node target as dependencies
- Loading branch information
Showing
7 changed files
with
339 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...main/java/com/google/cloud/teleport/v2/neo4j/model/validation/NodeMatchModeValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (C) 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.google.cloud.teleport.v2.neo4j.model.validation; | ||
|
||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
import org.neo4j.importer.v1.targets.RelationshipTarget; | ||
import org.neo4j.importer.v1.validation.SpecificationValidationResult.Builder; | ||
import org.neo4j.importer.v1.validation.SpecificationValidator; | ||
|
||
public class NodeMatchModeValidator implements SpecificationValidator { | ||
|
||
private static final String ERROR_CODE = "RNMM-001"; | ||
|
||
private final Set<String> paths; | ||
|
||
public NodeMatchModeValidator() { | ||
paths = new LinkedHashSet<>(); | ||
} | ||
|
||
@Override | ||
public void visitRelationshipTarget(int index, RelationshipTarget target) { | ||
if (target.getNodeMatchMode() == null) { | ||
paths.add(String.format("$.targets.relationships[%d].node_match_mode", index)); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean report(Builder builder) { | ||
paths.forEach( | ||
path -> | ||
builder.addError( | ||
path, | ||
ERROR_CODE, | ||
String.format("%s is missing: please specify a node match mode", path))); | ||
return paths.isEmpty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...ud-to-neo4j/src/test/java/com/google/cloud/teleport/v2/neo4j/templates/MovieImportIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright (C) 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.google.cloud.teleport.v2.neo4j.templates; | ||
|
||
import static com.google.cloud.teleport.v2.neo4j.templates.Connections.jsonBasicPayload; | ||
import static com.google.cloud.teleport.v2.neo4j.templates.Resources.contentOf; | ||
import static org.apache.beam.it.truthmatchers.PipelineAsserts.assertThatPipeline; | ||
import static org.apache.beam.it.truthmatchers.PipelineAsserts.assertThatResult; | ||
|
||
import com.google.cloud.teleport.metadata.TemplateIntegrationTest; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import net.jcip.annotations.NotThreadSafe; | ||
import org.apache.beam.it.common.PipelineLauncher.LaunchConfig; | ||
import org.apache.beam.it.common.PipelineLauncher.LaunchInfo; | ||
import org.apache.beam.it.common.TestProperties; | ||
import org.apache.beam.it.common.utils.ResourceManagerUtils; | ||
import org.apache.beam.it.gcp.TemplateTestBase; | ||
import org.apache.beam.it.neo4j.Neo4jResourceManager; | ||
import org.apache.beam.it.neo4j.conditions.Neo4jQueryCheck; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
@Category(TemplateIntegrationTest.class) | ||
@TemplateIntegrationTest(GoogleCloudToNeo4j.class) | ||
@RunWith(JUnit4.class) | ||
@NotThreadSafe | ||
public class MovieImportIT extends TemplateTestBase { | ||
private Neo4jResourceManager neo4jClient; | ||
|
||
@Before | ||
public void setup() { | ||
neo4jClient = | ||
Neo4jResourceManager.builder(testName) | ||
.setAdminPassword("letmein!") | ||
.setHost(TestProperties.hostIp()) | ||
.build(); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
ResourceManagerUtils.cleanResources(neo4jClient); | ||
} | ||
|
||
@Test | ||
public void importsMovieGraphFromInlineData() throws IOException { | ||
gcsClient.createArtifact( | ||
"spec.json", contentOf("/testing-specs/import-spec/movie-import/spec.json")); | ||
gcsClient.createArtifact("neo4j.json", jsonBasicPayload(neo4jClient)); | ||
|
||
LaunchConfig.Builder options = | ||
LaunchConfig.builder(testName, specPath) | ||
.addParameter("jobSpecUri", getGcsPath("spec.json")) | ||
.addParameter("neo4jConnectionUri", getGcsPath("neo4j.json")); | ||
LaunchInfo info = launchTemplate(options); | ||
|
||
assertThatPipeline(info).isRunning(); | ||
assertThatResult( | ||
pipelineOperator() | ||
.waitForConditionAndCancel( | ||
createConfig(info), | ||
Neo4jQueryCheck.builder(neo4jClient) | ||
.setQuery("MATCH (n:Person) RETURN count(n) AS count") | ||
.setExpectedResult(List.of(Map.of("count", 4L))) | ||
.build(), | ||
Neo4jQueryCheck.builder(neo4jClient) | ||
.setQuery("MATCH (n:Movie) RETURN count(n) AS count") | ||
.setExpectedResult(List.of(Map.of("count", 2L))) | ||
.build(), | ||
Neo4jQueryCheck.builder(neo4jClient) | ||
.setQuery("MATCH (:Person)-[r:ACTED_IN]->(:Movie) RETURN count(r) AS count") | ||
.setExpectedResult(List.of(Map.of("count", 2L))) | ||
.build(), | ||
Neo4jQueryCheck.builder(neo4jClient) | ||
.setQuery("MATCH (:Person)-[r:DIRECTED]->(:Movie) RETURN count(r) AS count") | ||
.setExpectedResult(List.of(Map.of("count", 2L))) | ||
.build())) | ||
.meetsConditions(); | ||
} | ||
} |
Oops, something went wrong.