fix(knext&server)query vertex if return null

This commit is contained in:
秉初 2024-11-27 18:10:48 +08:00
parent 193ecf8ac8
commit f0673fa5bd
14 changed files with 188 additions and 72 deletions

View File

@ -1 +1 @@
0.6.0.20241125.1
0.6.0.20241127.1

View File

@ -11,7 +11,7 @@
__package_name__ = "openspg-knext"
__version__ = "0.6.0.20241125.1"
__version__ = "0.6.0.20241127.1"
from knext.common.env import init_env

View File

@ -51,5 +51,6 @@ from knext.graph.rest.models.edge_type_name import EdgeTypeName
from knext.graph.rest.models.expend_one_hop_request import ExpendOneHopRequest
from knext.graph.rest.models.lpg_property_record import LpgPropertyRecord
from knext.graph.rest.models.query_vertex_request import QueryVertexRequest
from knext.graph.rest.models.query_vertex_response import QueryVertexResponse
from knext.graph.rest.models.vertex_record import VertexRecord
from knext.graph.rest.models.expend_one_hop_response import ExpendOneHopResponse

View File

@ -106,7 +106,7 @@ if __name__ == "__main__":
# test ant main-site
client = GraphClient("https://spgservice-standard-pre.alipay.com", 644000146)
v = client.query_vertex("Antwork.EntityName", "千三")
# print(v)
print(v)
edge_name = EdgeTypeName(
start_vertex_type="BCTEST.DeleteDataEntity3",
@ -115,9 +115,9 @@ if __name__ == "__main__":
)
client2 = GraphClient("https://spgservice-standard-pre.alipay.com", 363000133)
edge_type_name_constraint = []
edge_type_name_constraint.append(edge_name)
# edge_type_name_constraint.append(edge_name)
g1 = client2.expend_one_hop(
"BCTEST.DeleteDataEntity3", "秉初测试", edge_type_name_constraint
"BCTEST.DeleteDataEntity3", "秉初测试321", edge_type_name_constraint
)
# g1 = client2.expend_one_hop("BCTEST.DeleteDataEntity3", "秉初测试", [edge_name])
print(g1)
# print(g1)

View File

@ -51,5 +51,6 @@ from knext.graph.rest.models.edge_type_name import EdgeTypeName
from knext.graph.rest.models.expend_one_hop_request import ExpendOneHopRequest
from knext.graph.rest.models.lpg_property_record import LpgPropertyRecord
from knext.graph.rest.models.query_vertex_request import QueryVertexRequest
from knext.graph.rest.models.query_vertex_response import QueryVertexResponse
from knext.graph.rest.models.vertex_record import VertexRecord
from knext.graph.rest.models.expend_one_hop_response import ExpendOneHopResponse

View File

@ -889,7 +889,7 @@ class GraphApi(object):
number provided, it will be total request
timeout. It can also be a pair (tuple) of
(connection, read) timeouts.
:return: VertexRecord
:return: QueryVertexResponse
If the method is called asynchronously,
returns the request thread.
"""
@ -915,7 +915,7 @@ class GraphApi(object):
number provided, it will be total request
timeout. It can also be a pair (tuple) of
(connection, read) timeouts.
:return: tuple(VertexRecord, status_code(int), headers(HTTPHeaderDict))
:return: tuple(QueryVertexResponse, status_code(int), headers(HTTPHeaderDict))
If the method is called asynchronously,
returns the request thread.
"""
@ -979,7 +979,7 @@ class GraphApi(object):
body=body_params,
post_params=form_params,
files=local_var_files,
response_type="VertexRecord", # noqa: E501
response_type="QueryVertexResponse", # noqa: E501
auth_settings=auth_settings,
async_req=local_var_params.get("async_req"),
_return_http_data_only=local_var_params.get(

View File

@ -35,5 +35,6 @@ from knext.graph.rest.models.edge_type_name import EdgeTypeName
from knext.graph.rest.models.expend_one_hop_request import ExpendOneHopRequest
from knext.graph.rest.models.lpg_property_record import LpgPropertyRecord
from knext.graph.rest.models.query_vertex_request import QueryVertexRequest
from knext.graph.rest.models.query_vertex_response import QueryVertexResponse
from knext.graph.rest.models.vertex_record import VertexRecord
from knext.graph.rest.models.expend_one_hop_response import ExpendOneHopResponse

View File

@ -80,10 +80,14 @@ class EdgeRecord(object):
self._properties = None
self.discriminator = None
self.record_type = record_type
self.edge_type = edge_type
self.src_id = src_id
self.dst_id = dst_id
if record_type is not None:
self.record_type = record_type
if edge_type is not None:
self.edge_type = edge_type
if src_id is not None:
self.src_id = src_id
if dst_id is not None:
self.dst_id = dst_id
if properties is not None:
self.properties = properties
@ -105,12 +109,6 @@ class EdgeRecord(object):
:param record_type: The record_type of this EdgeRecord. # noqa: E501
:type: str
"""
if (
self.local_vars_configuration.client_side_validation and record_type is None
): # noqa: E501
raise ValueError(
"Invalid value for `record_type`, must not be `None`"
) # noqa: E501
self._record_type = record_type
@ -132,12 +130,6 @@ class EdgeRecord(object):
:param edge_type: The edge_type of this EdgeRecord. # noqa: E501
:type: EdgeTypeName
"""
if (
self.local_vars_configuration.client_side_validation and edge_type is None
): # noqa: E501
raise ValueError(
"Invalid value for `edge_type`, must not be `None`"
) # noqa: E501
self._edge_type = edge_type
@ -159,12 +151,6 @@ class EdgeRecord(object):
:param src_id: The src_id of this EdgeRecord. # noqa: E501
:type: str
"""
if (
self.local_vars_configuration.client_side_validation and src_id is None
): # noqa: E501
raise ValueError(
"Invalid value for `src_id`, must not be `None`"
) # noqa: E501
self._src_id = src_id
@ -186,12 +172,6 @@ class EdgeRecord(object):
:param dst_id: The dst_id of this EdgeRecord. # noqa: E501
:type: str
"""
if (
self.local_vars_configuration.client_side_validation and dst_id is None
): # noqa: E501
raise ValueError(
"Invalid value for `dst_id`, must not be `None`"
) # noqa: E501
self._dst_id = dst_id

View File

@ -0,0 +1,129 @@
# coding: utf-8
# 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.
"""
knext
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) # noqa: E501
The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech
"""
import pprint
import re # noqa: F401
import six
from knext.common.rest.configuration import Configuration
class QueryVertexResponse(object):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
"""
Attributes:
openapi_types (dict): The key is attribute name
and the value is attribute type.
attribute_map (dict): The key is attribute name
and the value is json key in definition.
"""
openapi_types = {"vertex": "VertexRecord"}
attribute_map = {"vertex": "vertex"}
def __init__(self, vertex=None, local_vars_configuration=None): # noqa: E501
"""QueryVertexResponse - a model defined in OpenAPI""" # noqa: E501
if local_vars_configuration is None:
local_vars_configuration = Configuration()
self.local_vars_configuration = local_vars_configuration
self._vertex = None
self.discriminator = None
if vertex is not None:
self.vertex = vertex
@property
def vertex(self):
"""Gets the vertex of this QueryVertexResponse. # noqa: E501
:return: The vertex of this QueryVertexResponse. # noqa: E501
:rtype: VertexRecord
"""
return self._vertex
@vertex.setter
def vertex(self, vertex):
"""Sets the vertex of this QueryVertexResponse.
:param vertex: The vertex of this QueryVertexResponse. # noqa: E501
:type: VertexRecord
"""
self._vertex = vertex
def to_dict(self):
"""Returns the model properties as a dict"""
result = {}
for attr, _ in six.iteritems(self.openapi_types):
value = getattr(self, attr)
if isinstance(value, list):
result[attr] = list(
map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value)
)
elif hasattr(value, "to_dict"):
result[attr] = value.to_dict()
elif isinstance(value, dict):
result[attr] = dict(
map(
lambda item: (item[0], item[1].to_dict())
if hasattr(item[1], "to_dict")
else item,
value.items(),
)
)
else:
result[attr] = value
return result
def to_str(self):
"""Returns the string representation of the model"""
return pprint.pformat(self.to_dict())
def __repr__(self):
"""For `print` and `pprint`"""
return self.to_str()
def __eq__(self, other):
"""Returns true if both objects are equal"""
if not isinstance(other, QueryVertexResponse):
return False
return self.to_dict() == other.to_dict()
def __ne__(self, other):
"""Returns true if both objects are not equal"""
if not isinstance(other, QueryVertexResponse):
return True
return self.to_dict() != other.to_dict()

View File

@ -76,10 +76,14 @@ class VertexRecord(object):
self._properties = None
self.discriminator = None
self.record_type = record_type
self.vertex_type = vertex_type
self.id = id
self.properties = properties
if record_type is not None:
self.record_type = record_type
if vertex_type is not None:
self.vertex_type = vertex_type
if id is not None:
self.id = id
if properties is not None:
self.properties = properties
@property
def record_type(self):
@ -99,12 +103,6 @@ class VertexRecord(object):
:param record_type: The record_type of this VertexRecord. # noqa: E501
:type: str
"""
if (
self.local_vars_configuration.client_side_validation and record_type is None
): # noqa: E501
raise ValueError(
"Invalid value for `record_type`, must not be `None`"
) # noqa: E501
self._record_type = record_type
@ -126,12 +124,6 @@ class VertexRecord(object):
:param vertex_type: The vertex_type of this VertexRecord. # noqa: E501
:type: str
"""
if (
self.local_vars_configuration.client_side_validation and vertex_type is None
): # noqa: E501
raise ValueError(
"Invalid value for `vertex_type`, must not be `None`"
) # noqa: E501
self._vertex_type = vertex_type
@ -153,10 +145,6 @@ class VertexRecord(object):
:param id: The id of this VertexRecord. # noqa: E501
:type: str
"""
if (
self.local_vars_configuration.client_side_validation and id is None
): # noqa: E501
raise ValueError("Invalid value for `id`, must not be `None`") # noqa: E501
self._id = id
@ -178,12 +166,6 @@ class VertexRecord(object):
:param properties: The properties of this VertexRecord. # noqa: E501
:type: list[LpgPropertyRecord]
"""
if (
self.local_vars_configuration.client_side_validation and properties is None
): # noqa: E501
raise ValueError(
"Invalid value for `properties`, must not be `None`"
) # noqa: E501
self._properties = properties

View File

@ -0,0 +1,18 @@
/*
* Ant Group
* Copyright (c) 2004-2024 All Rights Reserved.
*/
package com.antgroup.openspg.server.api.facade.dto.service.response;
import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.record.VertexRecord;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class QueryVertexResponse {
private VertexRecord vertex;
}

View File

@ -24,7 +24,6 @@ import com.antgroup.openspg.builder.model.record.RecordAlterOperationEnum;
import com.antgroup.openspg.builder.model.record.SubGraphRecord;
import com.antgroup.openspg.builder.runner.local.physical.sink.impl.GraphStoreSinkWriter;
import com.antgroup.openspg.builder.runner.local.physical.sink.impl.Neo4jSinkWriter;
import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.record.VertexRecord;
import com.antgroup.openspg.core.schema.model.identifier.SPGTypeIdentifier;
import com.antgroup.openspg.core.schema.model.type.BaseSPGType;
import com.antgroup.openspg.core.schema.model.type.ConceptList;
@ -33,6 +32,7 @@ import com.antgroup.openspg.server.api.facade.dto.service.request.*;
import com.antgroup.openspg.server.api.facade.dto.service.response.ExpendOneHopResponse;
import com.antgroup.openspg.server.api.facade.dto.service.response.ManipulateDataResponse;
import com.antgroup.openspg.server.api.facade.dto.service.response.PageRankScoreInstance;
import com.antgroup.openspg.server.api.facade.dto.service.response.QueryVertexResponse;
import com.antgroup.openspg.server.api.http.server.HttpBizCallback;
import com.antgroup.openspg.server.api.http.server.HttpBizTemplate;
import com.antgroup.openspg.server.api.http.server.HttpResult;
@ -259,9 +259,9 @@ public class GraphController {
@RequestMapping(value = "/queryVertex", method = RequestMethod.POST)
@ResponseBody
public HttpResult<VertexRecord> queryVertex(@RequestBody QueryVertexRequest request) {
public HttpResult<QueryVertexResponse> queryVertex(@RequestBody QueryVertexRequest request) {
return HttpBizTemplate.execute2(
new HttpBizCallback<VertexRecord>() {
new HttpBizCallback<QueryVertexResponse>() {
@Override
public void check() {
AssertUtils.assertParamObjectIsNotNull("request", request);
@ -271,7 +271,7 @@ public class GraphController {
}
@Override
public VertexRecord action() {
public QueryVertexResponse action() {
return graphManager.queryVertex(request);
}
});

View File

@ -13,11 +13,11 @@
package com.antgroup.openspg.server.biz.service;
import com.antgroup.openspg.cloudext.interfaces.graphstore.model.lpg.record.VertexRecord;
import com.antgroup.openspg.server.api.facade.dto.service.request.*;
import com.antgroup.openspg.server.api.facade.dto.service.response.ExpendOneHopResponse;
import com.antgroup.openspg.server.api.facade.dto.service.response.ManipulateDataResponse;
import com.antgroup.openspg.server.api.facade.dto.service.response.PageRankScoreInstance;
import com.antgroup.openspg.server.api.facade.dto.service.response.QueryVertexResponse;
import java.util.List;
public interface GraphManager {
@ -34,7 +34,7 @@ public interface GraphManager {
List<PageRankScoreInstance> getPageRankScores(GetPageRankScoresRequest request);
VertexRecord queryVertex(QueryVertexRequest request);
QueryVertexResponse queryVertex(QueryVertexRequest request);
ExpendOneHopResponse expendOneHop(ExpendOneHopRequest request);
}

View File

@ -28,6 +28,7 @@ import com.antgroup.openspg.server.api.facade.dto.service.request.*;
import com.antgroup.openspg.server.api.facade.dto.service.response.ExpendOneHopResponse;
import com.antgroup.openspg.server.api.facade.dto.service.response.ManipulateDataResponse;
import com.antgroup.openspg.server.api.facade.dto.service.response.PageRankScoreInstance;
import com.antgroup.openspg.server.api.facade.dto.service.response.QueryVertexResponse;
import com.antgroup.openspg.server.biz.common.ProjectManager;
import com.antgroup.openspg.server.biz.service.GraphManager;
import com.antgroup.openspg.server.biz.service.convertor.InstanceConvertor;
@ -230,7 +231,7 @@ public class GraphManagerImpl implements GraphManager {
}
@Override
public VertexRecord queryVertex(QueryVertexRequest request) {
public QueryVertexResponse queryVertex(QueryVertexRequest request) {
String graphStoreUrl = projectManager.getGraphStoreUrl(request.getProjectId());
BaseLPGGraphStoreClient lpgGraphStoreClient =
(BaseLPGGraphStoreClient) GraphStoreClientDriverManager.getClient(graphStoreUrl);
@ -238,9 +239,12 @@ public class GraphManagerImpl implements GraphManager {
VertexLPGRecordQuery query =
new VertexLPGRecordQuery(request.getBizId(), request.getTypeName());
GraphLPGRecordStruct struct = (GraphLPGRecordStruct) lpgGraphStoreClient.queryRecord(query);
QueryVertexResponse response = new QueryVertexResponse();
if (struct == null || struct.getVertices().isEmpty()) {
return null;
return response;
}
return struct.getVertices().get(0);
response.setVertex(struct.getVertices().get(0));
return response;
}
}