mirror of
https://github.com/OpenSPG/openspg.git
synced 2025-06-27 03:20:10 +00:00
fix(builder): bug fix (#336)
This commit is contained in:
parent
7280befe89
commit
c2184b645f
12
.github/CODEOWNERS
vendored
12
.github/CODEOWNERS
vendored
@ -9,11 +9,11 @@
|
||||
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
# or implied.
|
||||
|
||||
@baifuyu @leywar @yixianlzz
|
||||
@andylau-55 @leywar @caszkgui @matthewhyx
|
||||
|
||||
/cloudext fuyu.bfy@antgroup.com leywar.liang@antgroup.com
|
||||
/python qy266141@antgroup.com julin.jl@antgroup.com leywar.liang@antgroup.com huaidong.xhd@antgroup.com
|
||||
/reasoner donghai.ydh@antgroup.com chengqiang.cq@antgroup.com peilong.zpl@antgroup.com zhizhen.lzz@antgroup.com wangshaofei.wsf@antgroup.com fuyu.bfy@antgroup.com
|
||||
/builder fuyu.bfy@antgroup.com leywar.liang@antgroup.com
|
||||
/server fuyu.bfy@antgroup.com matthew.hyx@antgroup.com leywar.liang@antgroup.com
|
||||
/cloudext andy.yj@antgroup.com leywar.liang@antgroup.com caszkgui@gmail.com matthew.hyx@antgroup.com
|
||||
/python qy266141@antgroup.com julin.jl@antgroup.com leywar.liang@antgroup.com huaidong.xhd@antgroup.com andy.yj@antgroup.com caszkgui@gmail.com matthew.hyx@antgroup.com
|
||||
/reasoner donghai.ydh@antgroup.com chengqiang.cq@antgroup.com peilong.zpl@antgroup.com zhizhen.lzz@antgroup.com wangshaofei.wsf@antgroup.com andy.yj@antgroup.com caszkgui@gmail.com matthew.hyx@antgroup.com
|
||||
/builder andy.yj@antgroup.com leywar.liang@antgroup.com caszkgui@gmail.com matthew.hyx@antgroup.com
|
||||
/server andy.yj@antgroup.com matthew.hyx@antgroup.com leywar.liang@antgroup.com caszkgui@gmail.com
|
||||
|
||||
|
@ -78,6 +78,9 @@ public class ReasonerProcessorUtils {
|
||||
Map<String, String> properties = toProps(vertex.getValue());
|
||||
BaseSPGType spgType = catalog.getSPGType(SPGTypeIdentifier.parse(vertexId.getType()));
|
||||
|
||||
if (spgType == null) {
|
||||
return;
|
||||
}
|
||||
BaseAdvancedRecord advancedRecord =
|
||||
VertexRecordConvertor.toAdvancedRecord(spgType, vertexId.getBizId(), properties);
|
||||
results.add(advancedRecord);
|
||||
@ -88,6 +91,9 @@ public class ReasonerProcessorUtils {
|
||||
Relation relationType = catalog.getRelation(RelationIdentifier.parse(edge.getType()));
|
||||
Map<String, String> properties = toProps(edge.getValue());
|
||||
|
||||
if (relationType == null) {
|
||||
return;
|
||||
}
|
||||
RelationRecord relationRecord =
|
||||
EdgeRecordConvertor.toRelationRecord(
|
||||
relationType,
|
||||
|
@ -44,8 +44,13 @@ import com.antgroup.openspg.core.schema.model.type.StandardType;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.ToNumberPolicy;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.google.gson.typeadapters.RuntimeTypeAdapterFactory;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class SchemaJsonUtils {
|
||||
|
||||
@ -100,9 +105,22 @@ public class SchemaJsonUtils {
|
||||
// BaseReasonerReceipt
|
||||
.setObjectToNumberStrategy(ToNumberPolicy.LONG_OR_DOUBLE)
|
||||
.setDateFormat(DATA_FORMAT)
|
||||
.registerTypeAdapter(Pattern.class, new SchemaJsonUtils.PatternTypeAdapter())
|
||||
.create();
|
||||
}
|
||||
|
||||
public static class PatternTypeAdapter extends TypeAdapter<Pattern> {
|
||||
@Override
|
||||
public void write(JsonWriter out, Pattern pattern) throws IOException {
|
||||
out.value(pattern.pattern());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern read(JsonReader in) throws IOException {
|
||||
return Pattern.compile(in.nextString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the given Java object into JSON string.
|
||||
*
|
||||
|
@ -13,31 +13,16 @@
|
||||
|
||||
package com.antgroup.openspg.test.kgschema
|
||||
|
||||
import com.antgroup.openspg.cloudext.impl.graphstore.tugraph.TuGraphConstants
|
||||
|
||||
import com.antgroup.openspg.cloudext.impl.graphstore.tugraph.TuGraphStoreClient
|
||||
import com.antgroup.openspg.cloudext.interfaces.graphstore.impl.DefaultLPGTypeNameConvertor
|
||||
import com.antgroup.openspg.core.schema.model.predicate.Property
|
||||
import com.antgroup.openspg.core.schema.model.predicate.PropertyAdvancedConfig
|
||||
import com.antgroup.openspg.core.schema.model.predicate.PropertyRef
|
||||
import com.antgroup.openspg.core.schema.model.predicate.Relation
|
||||
import com.antgroup.openspg.core.schema.model.predicate.SubProperty
|
||||
import com.antgroup.openspg.core.schema.model.type.BaseSPGType
|
||||
import com.antgroup.openspg.core.schema.model.type.ConceptLayerConfig
|
||||
import com.antgroup.openspg.core.schema.model.type.ConceptTaxonomicConfig
|
||||
import com.antgroup.openspg.core.schema.model.type.ConceptType
|
||||
import com.antgroup.openspg.core.schema.model.type.EntityType
|
||||
import com.antgroup.openspg.core.schema.model.type.ParentTypeInfo
|
||||
import com.antgroup.openspg.core.schema.model.type.SPGTypeAdvancedConfig
|
||||
import com.antgroup.openspg.core.schema.model.type.SPGTypeEnum
|
||||
import com.antgroup.openspg.core.schema.model.type.SPGTypeRef
|
||||
import com.antgroup.openspg.server.api.facade.ApiConstants
|
||||
import com.antgroup.openspg.server.common.model.datasource.connection.GraphStoreConnectionInfo
|
||||
import com.antgroup.openspg.core.schema.model.BasicInfo
|
||||
import com.antgroup.openspg.core.schema.model.SPGSchema
|
||||
import com.antgroup.openspg.core.schema.model.SPGSchemaAlterCmd
|
||||
import com.antgroup.openspg.core.schema.model.alter.AlterOperationEnum
|
||||
import com.antgroup.openspg.core.schema.model.identifier.PredicateIdentifier
|
||||
import com.antgroup.openspg.core.schema.model.identifier.SPGTypeIdentifier
|
||||
import com.antgroup.openspg.core.schema.model.predicate.*
|
||||
import com.antgroup.openspg.core.schema.model.type.*
|
||||
import com.google.common.collect.Lists
|
||||
import com.google.common.collect.Sets
|
||||
import spock.lang.Specification
|
||||
@ -354,21 +339,6 @@ class SPGSchema2LpgServiceSpec extends Specification {
|
||||
1 == 1
|
||||
}
|
||||
|
||||
private static TuGraphStoreClient genTuGraphStoreClient() {
|
||||
GraphStoreConnectionInfo connInfo = new GraphStoreConnectionInfo();
|
||||
connInfo.setScheme("tugraph");
|
||||
|
||||
Map<String, Object> params = new HashMap<>(5);
|
||||
params.put(TuGraphConstants.GRAPH_NAME, "Spg2LpgTest")
|
||||
params.put(ApiConstants.TIMEOUT, 5000d)
|
||||
params.put(ApiConstants.HOST, "127.0.0.1:9090")
|
||||
params.put(ApiConstants.ACCESS_ID, "admin")
|
||||
params.put(ApiConstants.ACCESS_KEY, "73@TuGraph")
|
||||
|
||||
connInfo.setParams(params)
|
||||
return new TuGraphStoreClient(connInfo, new DefaultLPGTypeNameConvertor())
|
||||
}
|
||||
|
||||
private static SubProperty mockSingle(String objectType, PropertyRef propertyTypeRef) {
|
||||
BasicInfo<PredicateIdentifier> basicInfo = new BasicInfo<>(
|
||||
new PredicateIdentifier("sub_proper" + objectType), "子属性", "desc");
|
||||
|
@ -1,197 +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.test.kgschema
|
||||
|
||||
import com.antgroup.openspg.server.api.facade.ApiResponse
|
||||
import com.antgroup.openspg.server.api.http.client.HttpConceptFacade
|
||||
import com.antgroup.openspg.server.api.http.client.HttpSchemaFacade
|
||||
import com.antgroup.openspg.server.api.http.client.util.ConnectionInfo
|
||||
import com.antgroup.openspg.server.api.http.client.util.HttpClientBootstrap
|
||||
import com.antgroup.openspg.cloudext.impl.graphstore.tugraph.TuGraphStoreClient
|
||||
import com.antgroup.openspg.cloudext.impl.searchengine.elasticsearch.ElasticSearchEngineClient
|
||||
import com.antgroup.openspg.server.common.service.datasource.DataSourceService
|
||||
import com.antgroup.openspg.core.schema.model.alter.SchemaDraft
|
||||
import com.antgroup.openspg.core.schema.model.predicate.Property
|
||||
import com.antgroup.openspg.core.schema.model.predicate.Relation
|
||||
import com.antgroup.openspg.core.schema.model.semantic.request.DefineDynamicTaxonomyRequest
|
||||
import com.antgroup.openspg.core.schema.model.semantic.request.DefineLogicalCausationRequest
|
||||
import com.antgroup.openspg.core.schema.model.semantic.request.RemoveDynamicTaxonomyRequest
|
||||
import com.antgroup.openspg.core.schema.model.semantic.request.RemoveLogicalCausationRequest
|
||||
import com.antgroup.openspg.core.schema.model.type.BaseSPGType
|
||||
import com.antgroup.openspg.core.schema.model.type.ConceptList
|
||||
import com.antgroup.openspg.core.schema.model.type.ProjectSchema
|
||||
import com.antgroup.openspg.core.schema.model.type.SPGTypeEnum
|
||||
import com.antgroup.openspg.test.sofaboot.SofaBootTestApplication
|
||||
import org.mockito.Mockito
|
||||
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.boot.test.mock.mockito.MockBean
|
||||
import spock.lang.Shared
|
||||
import spock.lang.Specification
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull
|
||||
|
||||
@SpringBootTest(classes = SofaBootTestApplication, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||
@AutoConfigureTestDatabase
|
||||
class SPGSchemaFacadeTest extends Specification {
|
||||
@Shared
|
||||
Long projectId = 1L
|
||||
@Shared
|
||||
spgSchemaFacade = new HttpSchemaFacade()
|
||||
@Shared
|
||||
conceptFacade = new HttpConceptFacade()
|
||||
|
||||
@MockBean
|
||||
private DataSourceService dataSourceService
|
||||
|
||||
def setupSpec() {
|
||||
HttpClientBootstrap.init(new ConnectionInfo("http://127.0.0.1:8887")
|
||||
.setConnectTimeout(60000).setReadTimeout(60000)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* step 1: query project schema, check system built-in BasicType and Standard is inited;
|
||||
* step 2: create new StandardType、EntityType、ConceptType、EventType;
|
||||
* step 3: define taxonomy semantic and logic causation semantic on concept;
|
||||
* step 4: update or delete some StandardType、EntityType、ConceptType、EventType;
|
||||
* step 5: query a single spg type, query a single relation;
|
||||
* step 6: delete all customized StandardType、EntityType、ConceptType、EventType;
|
||||
*/
|
||||
def "test"() {
|
||||
given:
|
||||
Mockito.doReturn(Mock(TuGraphStoreClient.class))
|
||||
.when(dataSourceService)
|
||||
.buildSharedKgStoreClient()
|
||||
Mockito.doReturn(Mock(ElasticSearchEngineClient.class))
|
||||
.when(dataSourceService)
|
||||
.buildSharedSearchEngineClient()
|
||||
|
||||
when:
|
||||
// step 1
|
||||
ProjectSchema projectSchema = this.getProjectSchema()
|
||||
MockSchemaResultValidator.checkInitResult(projectSchema.getSpgTypes())
|
||||
|
||||
BuiltInPropertyRequest builtInPropertyRequest = new BuiltInPropertyRequest(
|
||||
spgTypeEnum: SPGTypeEnum.CONCEPT_TYPE.name()
|
||||
)
|
||||
ApiResponse<List<Property>> apiResponse = spgSchemaFacade.queryBuiltInProperty(builtInPropertyRequest)
|
||||
assertEquals(2, apiResponse.getData().size())
|
||||
|
||||
// step 2
|
||||
SchemaDraft createDraft = MockSchemaDraftFactory.buildCreateDraft()
|
||||
SchemaAlterRequest schemaAlterRequest = new SchemaAlterRequest(
|
||||
projectId: projectId, schemaDraft: createDraft)
|
||||
spgSchemaFacade.alterSchema(schemaAlterRequest)
|
||||
|
||||
projectSchema = this.getProjectSchema()
|
||||
MockSchemaResultValidator.checkCreateResult(projectSchema.getSpgTypes())
|
||||
|
||||
//step 3
|
||||
DefineDynamicTaxonomyRequest defineDynamicTaxonomyRequest1 = new DefineDynamicTaxonomyRequest(
|
||||
conceptTypeName: MockSpgTypeNameEnum.DEFAULT_TAXOMOMY_OF_PERSON.getName(),
|
||||
conceptName: "中产阶级",
|
||||
dsl: "Define (s:DEFAULT.Person)-[p:belongTo]->(o:`DEFAULT.TaxonomyOfPerson`/`中产阶级`) " +
|
||||
"{GraphStructure{} Rule{ R1: s.age >= 40 and s.age < 50}}")
|
||||
conceptFacade.defineDynamicTaxonomy(defineDynamicTaxonomyRequest1)
|
||||
|
||||
DefineDynamicTaxonomyRequest defineDynamicTaxonomyRequest2 = new DefineDynamicTaxonomyRequest(
|
||||
conceptTypeName: MockSpgTypeNameEnum.DEFAULT_TAXOMOMY_OF_PERSON.getName(),
|
||||
conceptName: "资产阶级",
|
||||
dsl: "Define (s:DEFAULT.Person)-[p:belongTo]->" +
|
||||
"(o:`DEFAULT.TaxonomyOfPerson`/`资产阶级`) " +
|
||||
"{GraphStructure{} Rule{ R1: s.age >= 50}}")
|
||||
conceptFacade.defineDynamicTaxonomy(defineDynamicTaxonomyRequest2)
|
||||
|
||||
DefineLogicalCausationRequest defineLogicalCausationRequest = new DefineLogicalCausationRequest(
|
||||
subjectConceptTypeName: MockSpgTypeNameEnum.DEFAULT_TAXOMOMY_OF_PERSON.getName(),
|
||||
subjectConceptName: "中产阶级",
|
||||
objectConceptTypeName: MockSpgTypeNameEnum.DEFAULT_TAXOMOMY_OF_PERSON.getName(),
|
||||
objectConceptName: "资产阶级",
|
||||
predicateName: "leadTo",
|
||||
dsl: "Define (s:`DEFAULT.TaxonomyOfPerson`/`中产阶级`)-[p:leadTo]->" +
|
||||
"(o:`DEFAULT.TaxonomyOfPerson`/`资产阶级`) " +
|
||||
"{GraphStructure{} Rule{ R1: s.age=50} \n Action {}}")
|
||||
conceptFacade.defineLogicalCausation(defineLogicalCausationRequest)
|
||||
|
||||
ConceptRequest conceptRequest = new ConceptRequest(
|
||||
conceptTypeName: MockSpgTypeNameEnum.DEFAULT_TAXOMOMY_OF_PERSON.getName(),
|
||||
conceptName: "中产阶级"
|
||||
)
|
||||
ApiResponse<ConceptList> conceptResponse = conceptFacade.queryConcept(conceptRequest)
|
||||
assertEquals(1, conceptResponse.getData().getConcepts().size())
|
||||
assertEquals(2, conceptResponse.getData().getConcepts().get(0).getSemantics().size())
|
||||
|
||||
RemoveDynamicTaxonomyRequest removeDynamicTaxonomyRequest = new RemoveDynamicTaxonomyRequest(
|
||||
objectConceptTypeName: MockSpgTypeNameEnum.DEFAULT_TAXOMOMY_OF_PERSON.getName())
|
||||
conceptFacade.removeDynamicTaxonomy(removeDynamicTaxonomyRequest)
|
||||
|
||||
RemoveLogicalCausationRequest removeLogicalCausationRequest = new RemoveLogicalCausationRequest(
|
||||
subjectConceptTypeName: MockSpgTypeNameEnum.DEFAULT_TAXOMOMY_OF_PERSON.getName(),
|
||||
subjectConceptName: "中产阶级",
|
||||
objectConceptTypeName: MockSpgTypeNameEnum.DEFAULT_TAXOMOMY_OF_PERSON.getName(),
|
||||
objectConceptName: "资产阶级",
|
||||
predicateName: "leadTo")
|
||||
conceptFacade.removeLogicalCausation(removeLogicalCausationRequest)
|
||||
|
||||
conceptResponse = conceptFacade.queryConcept(conceptRequest)
|
||||
assertEquals(0, conceptResponse.getData().getConcepts().size())
|
||||
|
||||
// step 4
|
||||
SchemaDraft updateDraft = MockSchemaDraftFactory.buildUpdateDraft(projectSchema)
|
||||
schemaAlterRequest = new SchemaAlterRequest(
|
||||
projectId: projectId, schemaDraft: updateDraft)
|
||||
spgSchemaFacade.alterSchema(schemaAlterRequest)
|
||||
|
||||
projectSchema = this.getProjectSchema()
|
||||
MockSchemaResultValidator.checkUpdateResult(projectSchema.getSpgTypes())
|
||||
|
||||
// step 5
|
||||
SPGTypeRequest request = new SPGTypeRequest(name: MockSpgTypeNameEnum.DEFAULT_ALIPAY_USER.getName())
|
||||
ApiResponse<BaseSPGType> response = spgSchemaFacade.querySPGType(request)
|
||||
assertNotNull(response.getData())
|
||||
assertEquals(MockSpgTypeNameEnum.DEFAULT_ALIPAY_USER.getName(), response.getData().getName())
|
||||
|
||||
RelationRequest relationRequest = new RelationRequest(
|
||||
sName: MockSpgTypeNameEnum.DEFAULT_ALIPAY_USER.getName(),
|
||||
relation: "regAddress",
|
||||
oName: MockSpgTypeNameEnum.DEFAULT_ADMINISTRATION.getName())
|
||||
ApiResponse<Relation> relationResponse = spgSchemaFacade.queryRelation(relationRequest)
|
||||
assertNotNull(relationResponse.getData())
|
||||
|
||||
// step 6
|
||||
projectSchema = this.getProjectSchema()
|
||||
SchemaDraft deleteDraft = MockSchemaDraftFactory.buildDeleteDraft(projectSchema)
|
||||
schemaAlterRequest = new SchemaAlterRequest(
|
||||
projectId: projectId, schemaDraft: deleteDraft)
|
||||
spgSchemaFacade.alterSchema(schemaAlterRequest)
|
||||
|
||||
projectSchema = this.getProjectSchema()
|
||||
MockSchemaResultValidator.checkInitResult(projectSchema.getSpgTypes())
|
||||
|
||||
then:
|
||||
assertNotNull(this.getProjectSchema())
|
||||
}
|
||||
|
||||
ProjectSchema getProjectSchema() {
|
||||
ProjectSchemaRequest projectSchemaRequest = new ProjectSchemaRequest(projectId: projectId)
|
||||
ApiResponse<ProjectSchema> projectSchemaResponse =
|
||||
spgSchemaFacade.queryProjectSchema(projectSchemaRequest)
|
||||
|
||||
assertNotNull(projectSchemaResponse)
|
||||
return projectSchemaResponse.getData()
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user