Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fdGuLCUX] Add type constraint support #424

Merged
merged 3 commits into from
Jun 1, 2023

Conversation

gem-neo4j
Copy link
Contributor

@gem-neo4j gem-neo4j commented May 29, 2023

Add support for new type constraints as well as tests.

I also noticed that the unique column was not correct for constraints that were being dropped, so fixed that (so the behaviour is the same for created/dropped constraints of the same type)

@gem-neo4j gem-neo4j force-pushed the dev_add_type_constraints_support branch 3 times, most recently from 4931e21 to 5b93233 Compare May 29, 2023 11:31
@gem-neo4j gem-neo4j force-pushed the dev_add_type_constraints_support branch 4 times, most recently from b2719eb to 708699c Compare May 30, 2023 11:03
@gem-neo4j gem-neo4j force-pushed the dev_add_type_constraints_support branch from 708699c to d02247a Compare May 30, 2023 11:39
@gem-neo4j gem-neo4j marked this pull request as ready for review May 30, 2023 11:40
@@ -149,6 +149,7 @@ private static Neo4jContainerExtension createNeo4jContainer(List<ApocPackage> ap
.withNeo4jConfig("dbms.logs.http.enabled", "true")
.withNeo4jConfig("dbms.logs.debug.level", "DEBUG")
.withNeo4jConfig("dbms.routing.driver.logging.level", "DEBUG")
.withNeo4jConfig("internal.dbms.type_constraints", "true")
Copy link
Collaborator

@ncordon ncordon May 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to leave the tests as they are so we can get the work in, but isn't there any way to test this with unit tests instead of integration tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well they are enterprise edition only features, so thought they needed to be done this way due to that? I got errors at least when trying with unit tests, and didn't try much more than that. Is there a way to do them that you know of?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhhh, I overlooked DDL commands are enterprise only. All good 👍

Map<String, Object> r = result.next();
assertEquals("Movie", r.get("label"));
assertEquals(List.of("first"), r.get("properties"));
assertEquals(":Movie(first)", r.get("name"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems incorrect as name of the type constraint?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave up questioning APOC :P It is consistent with how it works today (see docs herehttps://neo4j.com/docs/apoc/current/overview/apoc.schema/apoc.schema.nodes/). I agree it is weird, but I wouldn't change it here, would you like me to make a card for it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make a card for it please

Comment on lines +211 to +228
testResult(session, "CALL apoc.schema.assert({},{Movie:[[\"first\"]]})", (result) -> {
while (result.hasNext()) {
Map<String, Object> r = result.next();
AssertSchemaResult con = new AssertSchemaResult(r.get("label"), (List<String>) r.get("keys"));
con.unique = (boolean) r.get("unique");
con.action = (String) r.get("action");
actualResult.add(con);

assertEquals(1, expectedResult.stream().filter(
c -> c.keys.containsAll(con.keys) &&
c.action.equals(con.action) &&
c.label.equals(con.label) &&
c.unique == con.unique
).toList().size());
}

assertEquals(expectedResult.size(), actualResult.size());
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain me what we are trying to test here 🙏 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I copied the style for each type of test as I figured being consistent per test type was less confusing than per constraint type. But what happens with this one is that above the loop is written the 2 expected results, and this checks that both results exist in the result set. The first constraint is in the constraint list of the CALL so should be kept, the second constraint is not mentioned so should be dropped. So the test checks one is kept and one is dropped :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants