NebulaGraph Python Client 5.3.0
Loading...
Searching...
No Matches
data.py
1# Copyright 2025 vesoft-inc
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15from dataclasses import dataclass, field
16from typing import List, Optional
17
18from nebulagraph_python.proto.graph_pb2 import PlanInfo
19
20
21@dataclass
23 """Represents a NebulaGraph service address"""
24
25 host: str
26 port: int
27
28 def __str__(self):
29 """Return string representation with proper IPv6 formatting"""
30 # IPv6 addresses contain colons, so wrap them in brackets
31 if ":" in self.hosthost and not self.hosthost.startswith("["):
32 return f"[{self.host}]:{self.port}"
33 return f"{self.host}:{self.port}"
34
35 def __hash__(self):
36 return hash((self.hosthost, self.portport))
37
38 def __eq__(self, other):
39 return self.__hash__() == other.__hash__()
40
41
42@dataclass()
44 """SSL parameters for secure connections"""
45
46 ca_crt: Optional[bytes] = field(default=None)
47 private_key: Optional[bytes] = field(default=None)
48 cert: Optional[bytes] = field(default=None)
49
50 @classmethod
52 cls,
53 ca_crt_file_path: Optional[str] = None,
54 crt_file_path: Optional[str] = None,
55 key_file_path: Optional[str] = None,
56 ) -> "SSLParam":
57 """
58 Create SSLParam instance for CA-signed certificates
59
60 Args:
61 ca_crt_file_path: Path to the CA certificate file
62 crt_file_path: Path to the certificate file
63 key_file_path: Path to the private key file
64
65 Returns:
66 SSLParam instance configured for CA-signed certificates
67 """
68 if ca_crt_file_path:
69 with open(ca_crt_file_path, "rb") as f:
70 ca_crt = f.read()
71 else:
72 ca_crt = None
73
74 if crt_file_path:
75 with open(crt_file_path, "rb") as f:
76 cert = f.read()
77 else:
78 cert = None
79
80 if key_file_path:
81 with open(key_file_path, "rb") as f:
82 private_key = f.read()
83 else:
84 private_key = None
85
86 return cls(
87 ca_crt=ca_crt,
88 private_key=private_key,
89 cert=cert,
90 )
91
92
94 def __init__(self, plan_info: PlanInfo):
95 self.plan_info = plan_info
96 self.id = plan_info.id.decode()
97 self.name = plan_info.name.decode()
98 self.details = plan_info.details.decode()
99 self.time_ms = plan_info.time_ms
100 self.rows = plan_info.rows
101 self.memory_kib = plan_info.memory_kib
102 self.blocked_ms = plan_info.blocked_ms
103 self.queued_ms = plan_info.queued_ms
104 self.consume_ms = plan_info.consume_ms
105 self.produce_ms = plan_info.produce_ms
106 self.finish_ms = plan_info.finish_ms
107 self.batches = plan_info.batches
108 self.concurrency = plan_info.concurrency
109 self.other_stats_json = plan_info.other_stats_json.decode()
110 self.children = [PlanInfoNode(plan) for plan in plan_info.children]
111
112 def get_plan_id(self) -> str:
113 return self.id
114
115 def get_id(self) -> str:
116 return self.id
117
118 def get_name(self) -> str:
119 return self.name
120
121 def get_details(self) -> str:
122 return self.details
123
124 def get_time_ms(self) -> float:
125 return self.time_ms
126
127 def get_rows(self) -> int:
128 return self.rows
129
130 def get_memory_kib(self) -> float:
131 return self.memory_kib
132
133 def get_blocked_ms(self) -> float:
134 return self.blocked_ms
135
136 def get_children(self) -> List["PlanInfoNode"]:
137 return self.children
138
139
140@dataclass
142 """Class that maintains additional information for execution result."""
143
144 cursor: Optional[str] = None
145 affected_nodes: int = 0
146 affected_edges: int = 0
147 total_server_time_us: int = 0
148 build_time_us: int = 0
149 optimize_time_us: int = 0
150 serialize_time_us: int = 0
151
152 def __str__(self) -> str:
153 return (
154 f"ExtraInfo{{cursor='{self.cursor}', "
155 f"affectedNodes={self.affected_nodes}, "
156 f"affectedEdges={self.affected_edges}, "
157 f"totalServerTimeUs={self.total_server_time_us}, "
158 f"buildTimeUs={self.build_time_us}, "
159 f"optimizeTimeUs={self.optimize_time_us}, "
160 f"serializeTimeUs={self.serialize_time_us}}}"
161 )
"SSLParam" from_files(cls, Optional[str] ca_crt_file_path=None, Optional[str] crt_file_path=None, Optional[str] key_file_path=None)
Definition data.py:56