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

#367: fix IllegalStateException when removing properties #401

Merged
merged 1 commit into from
Apr 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Collection<Consumer<Void>> beforeCommit(TransactionData data) throws Exce
getIndexesByLabelAndProperty();
Collection<Consumer<Void>> state = async ? new LinkedList<>() : null;

iterateNodePropertyChange(stream(data.assignedNodeProperties()),(index, node, key, value, oldValue) -> indexUpdate(state, aVoid -> {
iterateNodePropertyChange(stream(data.assignedNodeProperties()),false, (index, node, key, value, oldValue) -> indexUpdate(state, aVoid -> {
if (oldValue != null) {
index.remove(node, key);
index.remove(node, FreeTextSearch.KEY);
Expand All @@ -68,7 +68,7 @@ public Collection<Consumer<Void>> beforeCommit(TransactionData data) throws Exce
}));

// filter out removedNodeProperties from node deletions
iterateNodePropertyChange(stream(data.removedNodeProperties()).filter(nodePropertyEntry -> !contains(data.deletedNodes().iterator(), nodePropertyEntry.entity())), (index, node, key, value, oldValue) -> indexUpdate(state, aVoid -> {
iterateNodePropertyChange(stream(data.removedNodeProperties()).filter(nodePropertyEntry -> !contains(data.deletedNodes().iterator(), nodePropertyEntry.entity())), true, (index, node, key, value, oldValue) -> indexUpdate(state, aVoid -> {
index.remove(node, key);
index.remove(node, FreeTextSearch.KEY);
}));
Expand Down Expand Up @@ -99,12 +99,12 @@ public void afterCommit(TransactionData data, Collection<Consumer<Void>> state)
}
}

private void iterateNodePropertyChange(Stream<PropertyEntry<Node>> stream,
private void iterateNodePropertyChange(Stream<PropertyEntry<Node>> stream, boolean propertyRemoved,
IndexFunction<Index<Node>, Node, String, Object, Object> function) {
stream.forEach(nodePropertyEntry -> {
final Node entity = nodePropertyEntry.entity();
final String key = nodePropertyEntry.key();
final Object value = nodePropertyEntry.value();
final Object value = propertyRemoved ? null : nodePropertyEntry.value();
entity.getLabels().forEach(label -> {
final String labelName = label.name();
final Map<String, Collection<Index<Node>>> propertyIndexMap = indexesByLabelAndProperty.get(labelName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ public void shouldDeletingIndexedNodesSucceed() {

// nothing found in the index after deletion
testCallCount(db, "start n=node:search_index('City.name:\"Made Up\"') return n", null, 0);

}

@Test
public void shouldIndexFieldsBeUsedConsistently() throws InterruptedException {
public void shouldIndexFieldsBeUsedConsistently() {
// setup: add a node, index it and add another node
testCallEmpty(db, "create (c:City{name:\"Made Up City\",url:\"/places/nowhere/made-up-city\"})", null);

Expand All @@ -58,8 +57,17 @@ public void shouldIndexFieldsBeUsedConsistently() throws InterruptedException {
testCallCount(db, "call apoc.index.search('search_index', 'City.name:Made') yield node, weight return node, weight", null, 2);
testCallCount(db, "start n=node:search_index('name:\"Made Up\"') return n", null, 0);
testCallCount(db, "start n=node:search_index('City.name:\"Made Up\"') return n", null, 2);

}

@Test
public void shouldRemovingPropertiesWork() {
//setup
testCallEmpty(db, "call apoc.index.addAllNodesExtended('submarines',{Submarine:['color']},{autoUpdate:true})", null);
testCallEmpty(db, "create (s:Submarine{color:\"yellow\",periscope:true})", null);
testCallEmpty(db, "create (s:Submarine{color:\"green\"})", null);

// when & then
testCallCount(db, "match (s:Submarine) remove s.periscope return s", null, 2);
}

}