Skip to content

Commit 1872176

Browse files
authored
Merge pull request #6412 from knutwalker/cypher-agg-faster
Lower abstraction for CypherAggregation
2 parents e4c5098 + 5b7eb62 commit 1872176

File tree

9 files changed

+664
-199
lines changed

9 files changed

+664
-199
lines changed

annotations/src/main/java/org/neo4j/gds/core/ConfigKeyValidation.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,14 @@ public final class ConfigKeyValidation {
3232

3333
private ConfigKeyValidation() {}
3434

35-
public static void requireOnlyKeysFrom(Collection<String> allowedKeys, Collection<String> configKeys) {
35+
public static void requireOnlyKeysFrom(Collection<String> allowedKeys, Iterable<String> configKeys) {
3636
var unexpectedKeys = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
37-
unexpectedKeys.addAll(configKeys);
37+
if (configKeys instanceof Collection<?>) {
38+
unexpectedKeys.addAll((Collection<String>) configKeys);
39+
} else {
40+
configKeys.forEach(unexpectedKeys::add);
41+
}
42+
3843

3944
// We are doing the equivalent of `removeAll` here.
4045
// As of jdk16, TreeSet does not have a specialized removeAll implementation and reverts to use
@@ -54,15 +59,25 @@ public static void requireOnlyKeysFrom(Collection<String> allowedKeys, Collectio
5459
List<String> suggestions = unexpectedKeys.stream()
5560
.map(invalid -> {
5661
List<String> candidates = StringSimilarity.similarStringsIgnoreCase(invalid, allowedKeys);
57-
candidates.removeAll(configKeys);
62+
if (configKeys instanceof Collection<?>) {
63+
candidates.removeAll((Collection<String>) configKeys);
64+
} else {
65+
configKeys.forEach(candidates::remove);
66+
}
67+
5868

5969
if (candidates.isEmpty()) {
6070
return invalid;
6171
}
6272
if (candidates.size() == 1) {
6373
return String.format(Locale.ENGLISH, "%s (Did you mean [%s]?)", invalid, candidates.get(0));
6474
}
65-
return String.format(Locale.ENGLISH, "%s (Did you mean one of [%s]?)", invalid, String.join(", ", candidates));
75+
return String.format(
76+
Locale.ENGLISH,
77+
"%s (Did you mean one of [%s]?)",
78+
invalid,
79+
String.join(", ", candidates)
80+
);
6681
})
6782
.collect(Collectors.toList());
6883

core/src/main/java/org/neo4j/gds/core/loading/ValueConverter.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import org.jetbrains.annotations.NotNull;
2323
import org.neo4j.gds.api.nodeproperties.ValueType;
24-
import org.neo4j.kernel.impl.util.ValueUtils;
2524
import org.neo4j.values.AnyValue;
2625
import org.neo4j.values.storable.ArrayValue;
2726
import org.neo4j.values.storable.DoubleArray;
@@ -59,10 +58,6 @@ public static ValueType valueType(Value value) {
5958
}
6059
}
6160

62-
public static Value toValue(@NotNull Object valueObject) {
63-
return toValue(ValueUtils.of(valueObject));
64-
}
65-
6661
public static Value toValue(@NotNull AnyValue value) {
6762
if (value.isSequenceValue()) {
6863
return castToNumericArrayOrFail(value);

core/src/main/java/org/neo4j/gds/core/loading/construction/PropertyValues.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
*/
2020
package org.neo4j.gds.core.loading.construction;
2121

22+
import org.neo4j.gds.core.loading.ValueConverter;
2223
import org.neo4j.values.storable.Value;
24+
import org.neo4j.values.storable.Values;
2325
import org.neo4j.values.virtual.MapValue;
2426

2527
import java.util.Map;
@@ -67,8 +69,8 @@ private CypherPropertyValues(MapValue properties) {
6769
@Override
6870
public void forEach(BiConsumer<String, Value> consumer) {
6971
this.properties.foreach((k, v) -> {
70-
if (v instanceof Value) {
71-
consumer.accept(k, (Value) v);
72+
if (v != Values.NO_VALUE) {
73+
consumer.accept(k, ValueConverter.toValue(v));
7274
}
7375
});
7476
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.gds.projection;
21+
22+
import org.neo4j.values.ValueMapper;
23+
import org.neo4j.values.virtual.VirtualNodeValue;
24+
import org.neo4j.values.virtual.VirtualPathValue;
25+
import org.neo4j.values.virtual.VirtualRelationshipValue;
26+
27+
public final class AsJavaObject extends ValueMapper.JavaMapper {
28+
29+
private static final AsJavaObject INSTANCE = new AsJavaObject();
30+
31+
public static AsJavaObject instance() {
32+
return INSTANCE;
33+
}
34+
35+
private AsJavaObject() {
36+
}
37+
38+
public Object mapPath(VirtualPathValue value) {
39+
throw new UnsupportedOperationException("Cannot map paths to Java object");
40+
}
41+
42+
public Object mapNode(VirtualNodeValue value) {
43+
throw new UnsupportedOperationException("Cannot map nodes to Java object");
44+
}
45+
46+
public Object mapRelationship(VirtualRelationshipValue value) {
47+
throw new UnsupportedOperationException("Cannot map relationships to Java object");
48+
}
49+
}

0 commit comments

Comments
 (0)