From 2a370de45fc6f56d9e7ddc57739979a25aa27aa4 Mon Sep 17 00:00:00 2001 From: Donghai Date: Mon, 15 Jul 2024 10:25:29 +0800 Subject: [PATCH 1/6] fix olap result has repeat vertex --- .../reasoner/runner/local/rdg/LocalRDG.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/reasoner/runner/local-runner/src/main/java/com/antgroup/openspg/reasoner/runner/local/rdg/LocalRDG.java b/reasoner/runner/local-runner/src/main/java/com/antgroup/openspg/reasoner/runner/local/rdg/LocalRDG.java index 068bdcfac..b65a8131e 100644 --- a/reasoner/runner/local-runner/src/main/java/com/antgroup/openspg/reasoner/runner/local/rdg/LocalRDG.java +++ b/reasoner/runner/local-runner/src/main/java/com/antgroup/openspg/reasoner/runner/local/rdg/LocalRDG.java @@ -1490,31 +1490,31 @@ private LocalReasonerResult getRDGGraph() { debugStartNodeINfos); } LocalReasonerResult localReasonerResult = getResult(); + + java.util.Set> vertexSet = new HashSet<>(); + java.util.Set> edgeSet = new HashSet<>(); this.kgGraphList.forEach( graph -> { for (String alias : graph.getVertexAlias()) { - localReasonerResult.getVertexList().addAll(graph.getVertex(alias)); + vertexSet.addAll(graph.getVertex(alias)); } for (String alias : graph.getEdgeAlias()) { java.util.List> edges = graph.getEdge(alias); for (IEdge edge : edges) { if (edge instanceof PathEdge) { if (((PathEdge) edge).getVertexList() != null) { - localReasonerResult - .getVertexList() - .addAll(((PathEdge) edge).getVertexList()); + vertexSet.addAll(((PathEdge) edge).getVertexList()); } if (((PathEdge) edge).getEdgeList() != null) { - localReasonerResult - .getEdgeList() - .addAll(((PathEdge) edge).getEdgeList()); + edgeSet.addAll(((PathEdge) edge).getEdgeList()); } } - localReasonerResult.getEdgeList().add(edge); + edgeSet.add(edge); } - localReasonerResult.getEdgeList().addAll(graph.getEdge(alias)); } }); + localReasonerResult.getVertexList().addAll(vertexSet); + localReasonerResult.getEdgeList().addAll(edgeSet); return localReasonerResult; } From 16318f3bd788818a3da09a7eb41b213c27a1efbd Mon Sep 17 00:00:00 2001 From: Donghai Date: Mon, 15 Jul 2024 14:11:09 +0800 Subject: [PATCH 2/6] fomart --- .../antgroup/openspg/reasoner/runner/local/rdg/LocalRDG.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/reasoner/runner/local-runner/src/main/java/com/antgroup/openspg/reasoner/runner/local/rdg/LocalRDG.java b/reasoner/runner/local-runner/src/main/java/com/antgroup/openspg/reasoner/runner/local/rdg/LocalRDG.java index b65a8131e..241e4d8fa 100644 --- a/reasoner/runner/local-runner/src/main/java/com/antgroup/openspg/reasoner/runner/local/rdg/LocalRDG.java +++ b/reasoner/runner/local-runner/src/main/java/com/antgroup/openspg/reasoner/runner/local/rdg/LocalRDG.java @@ -1503,10 +1503,11 @@ private LocalReasonerResult getRDGGraph() { for (IEdge edge : edges) { if (edge instanceof PathEdge) { if (((PathEdge) edge).getVertexList() != null) { - vertexSet.addAll(((PathEdge) edge).getVertexList()); + vertexSet.addAll( + ((PathEdge) edge).getVertexList()); } if (((PathEdge) edge).getEdgeList() != null) { - edgeSet.addAll(((PathEdge) edge).getEdgeList()); + edgeSet.addAll(((PathEdge) edge).getEdgeList()); } } edgeSet.add(edge); From 772751455b0e2daca1bccb069c9fb44a2e82bb97 Mon Sep 17 00:00:00 2001 From: Donghai Date: Thu, 1 Aug 2024 10:39:33 +0800 Subject: [PATCH 3/6] udtf support vertex type --- .../reasoner/rdg/common/LinkEdgeImpl.java | 25 ++++++++++++++++--- .../reasoner/udf/model/LinkedUdtfResult.java | 3 +++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/reasoner/runner/runner-common/src/main/java/com/antgroup/openspg/reasoner/rdg/common/LinkEdgeImpl.java b/reasoner/runner/runner-common/src/main/java/com/antgroup/openspg/reasoner/rdg/common/LinkEdgeImpl.java index 2d0838278..ddd3ef939 100644 --- a/reasoner/runner/runner-common/src/main/java/com/antgroup/openspg/reasoner/rdg/common/LinkEdgeImpl.java +++ b/reasoner/runner/runner-common/src/main/java/com/antgroup/openspg/reasoner/rdg/common/LinkEdgeImpl.java @@ -47,6 +47,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.Set; @@ -92,6 +93,21 @@ public LinkEdgeImpl( this.initContext = RunnerUtil.getKgGraphInitContext(kgGraphSchema); } + private boolean isTargetVertexTypeEmpty(List targetVertexTypes) { + if (null == targetVertexTypes || targetVertexTypes.isEmpty()) { + return true; + } + for (String type : targetVertexTypes) { + if ("unknown".equals(type.toLowerCase(Locale.ROOT))) { + continue; + } + if (StringUtils.isNotEmpty(type)) { + return false; + } + } + return true; + } + public List> link(KgGraph kgGraph) { Iterator> it = kgGraph.getPath(staticParameters, null); List> mergeList = new ArrayList<>(); @@ -143,9 +159,12 @@ public List> link(KgGraph kgGraph) { String targetAlias = targetVertexMeta.alias(); List targetVertexTypes = new ArrayList<>(JavaConversions.setAsJavaSet(targetVertexMeta.typeNames())); - if (targetVertexTypes.size() == 0) { - throw new RuntimeException( - "Linked edge target vertex type must contains at least one type"); + if (isTargetVertexTypeEmpty(targetVertexTypes)) { + targetVertexTypes = Lists.newArrayList(linkedUdtfResult.getVertexType()); + if (isTargetVertexTypeEmpty(targetVertexTypes)) { + throw new RuntimeException( + "Linked edge target vertex type must contains at least one type"); + } } for (String targetVertexType : targetVertexTypes) { IVertexId targetId = new VertexId(targetIdStr, targetVertexType); diff --git a/reasoner/udf/src/main/java/com/antgroup/openspg/reasoner/udf/model/LinkedUdtfResult.java b/reasoner/udf/src/main/java/com/antgroup/openspg/reasoner/udf/model/LinkedUdtfResult.java index 11ea52597..944a15160 100644 --- a/reasoner/udf/src/main/java/com/antgroup/openspg/reasoner/udf/model/LinkedUdtfResult.java +++ b/reasoner/udf/src/main/java/com/antgroup/openspg/reasoner/udf/model/LinkedUdtfResult.java @@ -30,4 +30,7 @@ public class LinkedUdtfResult { /** edge type */ private String edgeType = null; + + /** vertex type */ + private String vertexType = null; } From 91fb9fcb8b4794d23ca6817c7c9301cb90d3e4f8 Mon Sep 17 00:00:00 2001 From: Donghai Date: Thu, 1 Aug 2024 10:44:03 +0800 Subject: [PATCH 4/6] update --- .../com/antgroup/openspg/reasoner/rdg/common/LinkEdgeImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reasoner/runner/runner-common/src/main/java/com/antgroup/openspg/reasoner/rdg/common/LinkEdgeImpl.java b/reasoner/runner/runner-common/src/main/java/com/antgroup/openspg/reasoner/rdg/common/LinkEdgeImpl.java index ddd3ef939..92823f7b3 100644 --- a/reasoner/runner/runner-common/src/main/java/com/antgroup/openspg/reasoner/rdg/common/LinkEdgeImpl.java +++ b/reasoner/runner/runner-common/src/main/java/com/antgroup/openspg/reasoner/rdg/common/LinkEdgeImpl.java @@ -98,7 +98,7 @@ private boolean isTargetVertexTypeEmpty(List targetVertexTypes) { return true; } for (String type : targetVertexTypes) { - if ("unknown".equals(type.toLowerCase(Locale.ROOT))) { + if ("RdfProperty".equals(type)) { continue; } if (StringUtils.isNotEmpty(type)) { From f1f7d0cfca7f935be53a8cff98fa5704e4ee3efb Mon Sep 17 00:00:00 2001 From: Donghai Date: Thu, 1 Aug 2024 11:04:02 +0800 Subject: [PATCH 5/6] update --- .../com/antgroup/openspg/reasoner/rdg/common/LinkEdgeImpl.java | 1 - 1 file changed, 1 deletion(-) diff --git a/reasoner/runner/runner-common/src/main/java/com/antgroup/openspg/reasoner/rdg/common/LinkEdgeImpl.java b/reasoner/runner/runner-common/src/main/java/com/antgroup/openspg/reasoner/rdg/common/LinkEdgeImpl.java index 92823f7b3..1c4b088c0 100644 --- a/reasoner/runner/runner-common/src/main/java/com/antgroup/openspg/reasoner/rdg/common/LinkEdgeImpl.java +++ b/reasoner/runner/runner-common/src/main/java/com/antgroup/openspg/reasoner/rdg/common/LinkEdgeImpl.java @@ -47,7 +47,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.Set; From dffcd5f762896b2562d14d695c90d6b9baad083c Mon Sep 17 00:00:00 2001 From: Donghai Date: Fri, 25 Oct 2024 17:00:26 +0800 Subject: [PATCH 6/6] update --- .../property/SPGPropertyValueTest.groovy | 40 ------------------- .../graphstore/RiskMiningLPGRecord.groovy | 32 --------------- .../util/VertexRecordConvertorTest.groovy | 30 -------------- 3 files changed, 102 deletions(-) delete mode 100644 builder/model/src/test/groovy/com/antgroup/openspg/builder/model/record/property/SPGPropertyValueTest.groovy delete mode 100644 cloudext/interface/graph-store/src/test/groovy/com/antgroup/openspg/cloudext/interfaces/graphstore/RiskMiningLPGRecord.groovy delete mode 100644 cloudext/interface/graph-store/src/test/groovy/com/antgroup/openspg/cloudext/interfaces/graphstore/adapter/util/VertexRecordConvertorTest.groovy diff --git a/builder/model/src/test/groovy/com/antgroup/openspg/builder/model/record/property/SPGPropertyValueTest.groovy b/builder/model/src/test/groovy/com/antgroup/openspg/builder/model/record/property/SPGPropertyValueTest.groovy deleted file mode 100644 index c6c0fdc5d..000000000 --- a/builder/model/src/test/groovy/com/antgroup/openspg/builder/model/record/property/SPGPropertyValueTest.groovy +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2023 OpenSPG Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. - */ - -package com.antgroup.openspg.builder.model.record.property - -import spock.lang.Specification - -class SPGPropertyValueTest extends Specification { - - def "testGetStdValue"() { - given: - def value = new SPGPropertyValue("bd8cc63024c7a1d4adb3d08f0f4d4827,1ef0e106653b871d429cfab0cd5ea70a") - value.setStds(["bd8cc63024c7a1d4adb3d08f0f4d4827", "1ef0e106653b871d429cfab0cd5ea70a"]) - - expect: - value.getStdValue() == 'bd8cc63024c7a1d4adb3d08f0f4d4827,1ef0e106653b871d429cfab0cd5ea70a' - } - - def "testMerge"() { - expect: - def otherValue = new SPGPropertyValue("bd8cc63024c7a1d4adb3d08f0f4d4827") - value.merge(otherValue) - value.getRaw() == expectRaw - - where: - value || expectRaw - new SPGPropertyValue(null) || "bd8cc63024c7a1d4adb3d08f0f4d4827" - new SPGPropertyValue("1ef0e106653b871d429cfab0cd5ea70a") || "1ef0e106653b871d429cfab0cd5ea70a,bd8cc63024c7a1d4adb3d08f0f4d4827" - } -} diff --git a/cloudext/interface/graph-store/src/test/groovy/com/antgroup/openspg/cloudext/interfaces/graphstore/RiskMiningLPGRecord.groovy b/cloudext/interface/graph-store/src/test/groovy/com/antgroup/openspg/cloudext/interfaces/graphstore/RiskMiningLPGRecord.groovy deleted file mode 100644 index 31e2e1a3e..000000000 --- a/cloudext/interface/graph-store/src/test/groovy/com/antgroup/openspg/cloudext/interfaces/graphstore/RiskMiningLPGRecord.groovy +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2023 OpenSPG Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. - */ - -package com.antgroup.openspg.cloudext.interfaces.graphstore - -import com.antgroup.openspg.builder.test.RiskMiningRecord -import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.record.LPGPropertyRecord -import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.record.VertexRecord -import spock.lang.Specification - -class RiskMiningLPGRecord extends Specification { - - public final static VertexRecord PERSON_RECORD1 = new VertexRecord( - RiskMiningRecord.PERSON_RECORD1.id, - RiskMiningRecord.PERSON_RECORD1.getName(), - [ - new LPGPropertyRecord("name", "裘**"), - new LPGPropertyRecord("age", 58L), - new LPGPropertyRecord("hasPhone", "154****7458"), - ] - ); -} diff --git a/cloudext/interface/graph-store/src/test/groovy/com/antgroup/openspg/cloudext/interfaces/graphstore/adapter/util/VertexRecordConvertorTest.groovy b/cloudext/interface/graph-store/src/test/groovy/com/antgroup/openspg/cloudext/interfaces/graphstore/adapter/util/VertexRecordConvertorTest.groovy deleted file mode 100644 index 638555a47..000000000 --- a/cloudext/interface/graph-store/src/test/groovy/com/antgroup/openspg/cloudext/interfaces/graphstore/adapter/util/VertexRecordConvertorTest.groovy +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2023 OpenSPG Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. - */ - -package com.antgroup.openspg.cloudext.interfaces.graphstore.adapter.util - -import com.antgroup.openspg.builder.test.RiskMiningRecord -import com.antgroup.openspg.cloudext.interfaces.graphstore.RiskMiningLPGRecord -import spock.lang.Specification - -class VertexRecordConvertorTest extends Specification { - - def testToVertexRecord() { - expect: - outputRecord == VertexRecordConvertor.toVertexRecord(inputRecord) - - where: - inputRecord || outputRecord - RiskMiningRecord.PERSON_RECORD1_NORMALIZED || RiskMiningLPGRecord.PERSON_RECORD1 - } -}