From 0ecf77058fa425137485a174bd5c89daca0abd59 Mon Sep 17 00:00:00 2001 From: Vaidik Garg Date: Sun, 25 Oct 2026 15:57:23 +0530 Subject: [PATCH] test(store): cover the id-only projection through QueryUtil.buildPlan The existing tests drive ProjectionStage by hand, so they would miss a change in how buildPlan wires the projection for a null_property request. The new case checks that buildPlan returns a projection-only plan for that request, feeds MapLimitIterator output through it, and checks each key comes out once with an empty value. It fails with "key 0 emitted twice" when the ProjectionStage fix from #3408 is reverted. --- .../node/grpc/query/ProjectionStageTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/hugegraph-store/hg-store-test/src/main/java/org/apache/hugegraph/store/node/grpc/query/ProjectionStageTest.java b/hugegraph-store/hg-store-test/src/main/java/org/apache/hugegraph/store/node/grpc/query/ProjectionStageTest.java index d23ee41ee0..663064ff2f 100644 --- a/hugegraph-store/hg-store-test/src/main/java/org/apache/hugegraph/store/node/grpc/query/ProjectionStageTest.java +++ b/hugegraph-store/hg-store-test/src/main/java/org/apache/hugegraph/store/node/grpc/query/ProjectionStageTest.java @@ -34,7 +34,10 @@ import org.apache.hugegraph.rocksdb.access.RocksDBSession.BackendColumn; import org.apache.hugegraph.rocksdb.access.ScanIterator; import org.apache.hugegraph.store.business.itrv2.MapLimitIterator; +import org.apache.hugegraph.store.grpc.query.QueryRequest; import org.apache.hugegraph.store.node.grpc.query.model.PipelineResult; +import org.apache.hugegraph.store.node.grpc.query.model.QueryPlan; +import org.apache.hugegraph.store.node.grpc.query.stages.EarlyStopException; import org.apache.hugegraph.store.node.grpc.query.stages.ProjectionStage; import org.junit.Test; @@ -81,6 +84,33 @@ public void testLimitDedupStillDropsCopiesAfterProjection() { assertEquals(IntStream.range(0, KEYS).boxed().collect(Collectors.toSet()), keys); } + @Test + public void testLimitDedupStillDropsCopiesThroughIdOnlyPlan() throws EarlyStopException { + // sample_factor defaults to 0.0, which builds a stop-only plan + QueryRequest request = QueryRequest.newBuilder() + .setSampleFactor(1.0) + .setNullProperty(true) + .build(); + QueryPlan plan = QueryUtil.buildPlan(request); + assertEquals("QueryPlan{stages=[PROJECTION_STAGE]}", plan.toString()); + ScanIterator dedup = new MapLimitIterator(scanTwice()); + + Set keys = new HashSet<>(); + try { + while (dedup.hasNext()) { + BackendColumn column = dedup.next(); + PipelineResult result = (PipelineResult) plan.execute(new PipelineResult(column)); + assertArrayEquals(new byte[0], result.getColumn().value); + int key = ByteBuffer.wrap(result.getColumn().name).getInt(); + assertTrue("key " + key + " emitted twice", keys.add(key)); + } + } finally { + dedup.close(); + } + + assertEquals(IntStream.range(0, KEYS).boxed().collect(Collectors.toSet()), keys); + } + private static ProjectionStage removeAllProperty() { ProjectionStage stage = new ProjectionStage(); stage.init(List.of(), true);