|
| 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.beta.filter; |
| 21 | + |
| 22 | +import org.junit.jupiter.api.Test; |
| 23 | +import org.neo4j.gds.NodeLabel; |
| 24 | +import org.neo4j.gds.api.GraphStore; |
| 25 | +import org.neo4j.gds.beta.filter.expression.ExpressionParser; |
| 26 | +import org.neo4j.gds.core.concurrency.Pools; |
| 27 | +import org.neo4j.gds.core.utils.progress.tasks.ProgressTracker; |
| 28 | +import org.neo4j.gds.extension.GdlExtension; |
| 29 | +import org.neo4j.gds.extension.GdlGraph; |
| 30 | +import org.neo4j.gds.extension.IdFunction; |
| 31 | +import org.neo4j.gds.extension.Inject; |
| 32 | +import org.opencypher.v9_0.parser.javacc.ParseException; |
| 33 | + |
| 34 | +import java.util.ArrayList; |
| 35 | +import java.util.Map; |
| 36 | + |
| 37 | +import static org.assertj.core.api.Assertions.assertThat; |
| 38 | + |
| 39 | +@GdlExtension |
| 40 | +class NodesFilterTest { |
| 41 | + |
| 42 | + @GdlGraph(idOffset = 17) |
| 43 | + private static final String DB_CYPHER = |
| 44 | + "CREATE" + |
| 45 | + " (a:A {p: 1L})" + |
| 46 | + ", (b:A {p: 2L})" + |
| 47 | + ", (c:A {p: 3L})" + |
| 48 | + ", (d:B)"; |
| 49 | + |
| 50 | + @Inject |
| 51 | + GraphStore graphStore; |
| 52 | + |
| 53 | + @Inject |
| 54 | + IdFunction idFunction; |
| 55 | + |
| 56 | + @Test |
| 57 | + void basicFiltering() throws ParseException { |
| 58 | + var filteredNodes = NodesFilter.filterNodes( |
| 59 | + graphStore, |
| 60 | + ExpressionParser.parse("n:A AND n.p > 1.0", Map.of()), |
| 61 | + 1, |
| 62 | + Map.of(), |
| 63 | + Pools.DEFAULT_SINGLE_THREAD_POOL, |
| 64 | + ProgressTracker.NULL_TRACKER |
| 65 | + ); |
| 66 | + |
| 67 | + var idMap = filteredNodes.idMap(); |
| 68 | + var filteredNodeIds = new ArrayList<Long>(); |
| 69 | + |
| 70 | + assertThat(idMap.availableNodeLabels()) |
| 71 | + .containsExactly(NodeLabel.of("A")); |
| 72 | + |
| 73 | + idMap.forEachNode(n -> { |
| 74 | + filteredNodeIds.add(idMap.toOriginalNodeId(n)); |
| 75 | + return true; |
| 76 | + }); |
| 77 | + |
| 78 | + assertThat(filteredNodeIds) |
| 79 | + .containsExactlyInAnyOrder( |
| 80 | + idFunction.of("b"), |
| 81 | + idFunction.of("c") |
| 82 | + ); |
| 83 | + } |
| 84 | +} |
0 commit comments