fauna.encoding.wire_protocol
1from dataclasses import dataclass 2from typing import Optional, Mapping, Any, List 3 4 5class QueryStats: 6 """Query stats""" 7 8 @property 9 def compute_ops(self) -> int: 10 """The amount of Transactional Compute Ops consumed by the query.""" 11 return self._compute_ops 12 13 @property 14 def read_ops(self) -> int: 15 """The amount of Transactional Read Ops consumed by the query.""" 16 return self._read_ops 17 18 @property 19 def write_ops(self) -> int: 20 """The amount of Transactional Write Ops consumed by the query.""" 21 return self._write_ops 22 23 @property 24 def query_time_ms(self) -> int: 25 """The query run time in milliseconds.""" 26 return self._query_time_ms 27 28 @property 29 def storage_bytes_read(self) -> int: 30 """The amount of data read from storage, in bytes.""" 31 return self._storage_bytes_read 32 33 @property 34 def storage_bytes_write(self) -> int: 35 """The amount of data written to storage, in bytes.""" 36 return self._storage_bytes_write 37 38 @property 39 def contention_retries(self) -> int: 40 """The number of times the transaction was retried due to write contention.""" 41 return self._contention_retries 42 43 @property 44 def attempts(self) -> int: 45 """The number of attempts made by the client to run the query.""" 46 return self._attempts 47 48 @attempts.setter 49 def attempts(self, value): 50 self._attempts = value 51 52 def __init__(self, stats: Mapping[str, Any]): 53 self._compute_ops = stats.get("compute_ops", 0) 54 self._read_ops = stats.get("read_ops", 0) 55 self._write_ops = stats.get("write_ops", 0) 56 self._query_time_ms = stats.get("query_time_ms", 0) 57 self._storage_bytes_read = stats.get("storage_bytes_read", 0) 58 self._storage_bytes_write = stats.get("storage_bytes_write", 0) 59 self._contention_retries = stats.get("contention_retries", 0) 60 self._attempts = 0 61 62 def __repr__(self): 63 stats = { 64 "compute_ops": self._compute_ops, 65 "read_ops": self._read_ops, 66 "write_ops": self._write_ops, 67 "query_time_ms": self._query_time_ms, 68 "storage_bytes_read": self._storage_bytes_read, 69 "storage_bytes_write": self._storage_bytes_write, 70 "contention_retries": self._contention_retries, 71 "attempts": self._attempts, 72 } 73 74 return f"{self.__class__.__name__}(stats={repr(stats)})" 75 76 def __eq__(self, other): 77 return type(self) == type(other) \ 78 and self.compute_ops == other.compute_ops \ 79 and self.read_ops == other.read_ops \ 80 and self.write_ops == other.write_ops \ 81 and self.query_time_ms == other.query_time_ms \ 82 and self.storage_bytes_read == other.storage_bytes_read \ 83 and self.storage_bytes_write == other.storage_bytes_write \ 84 and self.contention_retries == other.contention_retries \ 85 and self.attempts == other.attempts 86 87 def __ne__(self, other): 88 return not self.__eq__(other) 89 90 91class QueryInfo: 92 93 @property 94 def query_tags(self) -> Mapping[str, Any]: 95 """The tags associated with the query.""" 96 return self._query_tags 97 98 @property 99 def summary(self) -> str: 100 """A comprehensive, human readable summary of any errors, warnings and/or logs returned from the query.""" 101 return self._summary 102 103 @property 104 def stats(self) -> QueryStats: 105 """Query stats associated with the query.""" 106 return self._stats 107 108 @property 109 def txn_ts(self) -> int: 110 """The last transaction timestamp of the query. A Unix epoch in microseconds.""" 111 return self._txn_ts 112 113 @property 114 def schema_version(self) -> int: 115 """The schema version that was used for the query execution.""" 116 return self._schema_version 117 118 def __init__( 119 self, 120 query_tags: Optional[Mapping[str, str]] = None, 121 stats: Optional[QueryStats] = None, 122 summary: Optional[str] = None, 123 txn_ts: Optional[int] = None, 124 schema_version: Optional[int] = None, 125 ): 126 self._query_tags = query_tags or {} 127 self._stats = stats or QueryStats({}) 128 self._summary = summary or "" 129 self._txn_ts = txn_ts or 0 130 self._schema_version = schema_version or 0 131 132 def __repr__(self): 133 return f"{self.__class__.__name__}(" \ 134 f"query_tags={repr(self.query_tags)}," \ 135 f"stats={repr(self.stats)}," \ 136 f"summary={repr(self.summary)}," \ 137 f"txn_ts={repr(self.txn_ts)}," \ 138 f"schema_version={repr(self.schema_version)})" 139 140 141class QuerySuccess(QueryInfo): 142 """The result of the query.""" 143 144 @property 145 def data(self) -> Any: 146 """The data returned by the query. This is the result of the FQL query.""" 147 return self._data 148 149 @property 150 def static_type(self) -> Optional[str]: 151 """If typechecked, the query's inferred static result type, if the query was typechecked.""" 152 return self._static_type 153 154 @property 155 def traceparent(self) -> Optional[str]: 156 """The traceparent for the query.""" 157 return self._traceparent 158 159 def __init__( 160 self, 161 data: Any, 162 query_tags: Optional[Mapping[str, str]], 163 static_type: Optional[str], 164 stats: Optional[QueryStats], 165 summary: Optional[str], 166 traceparent: Optional[str], 167 txn_ts: Optional[int], 168 schema_version: Optional[int], 169 ): 170 171 super().__init__( 172 query_tags=query_tags, 173 stats=stats, 174 summary=summary, 175 txn_ts=txn_ts, 176 schema_version=schema_version, 177 ) 178 179 self._traceparent = traceparent 180 self._static_type = static_type 181 self._data = data 182 183 def __repr__(self): 184 return f"{self.__class__.__name__}(" \ 185 f"query_tags={repr(self.query_tags)}," \ 186 f"static_type={repr(self.static_type)}," \ 187 f"stats={repr(self.stats)}," \ 188 f"summary={repr(self.summary)}," \ 189 f"traceparent={repr(self.traceparent)}," \ 190 f"txn_ts={repr(self.txn_ts)}," \ 191 f"schema_version={repr(self.schema_version)}," \ 192 f"data={repr(self.data)})" 193 194 195@dataclass 196class ConstraintFailure: 197 message: str 198 name: Optional[str] = None 199 paths: Optional[List[Any]] = None 200 201 202class QueryTags: 203 204 @staticmethod 205 def encode(tags: Mapping[str, str]) -> str: 206 return ",".join([f"{k}={v}" for k, v in tags.items()]) 207 208 @staticmethod 209 def decode(tag_str: str) -> Mapping[str, str]: 210 res: dict[str, str] = {} 211 for pair in tag_str.split(","): 212 kv = pair.split("=") 213 res[kv[0]] = kv[1] 214 return res
class
QueryStats:
6class QueryStats: 7 """Query stats""" 8 9 @property 10 def compute_ops(self) -> int: 11 """The amount of Transactional Compute Ops consumed by the query.""" 12 return self._compute_ops 13 14 @property 15 def read_ops(self) -> int: 16 """The amount of Transactional Read Ops consumed by the query.""" 17 return self._read_ops 18 19 @property 20 def write_ops(self) -> int: 21 """The amount of Transactional Write Ops consumed by the query.""" 22 return self._write_ops 23 24 @property 25 def query_time_ms(self) -> int: 26 """The query run time in milliseconds.""" 27 return self._query_time_ms 28 29 @property 30 def storage_bytes_read(self) -> int: 31 """The amount of data read from storage, in bytes.""" 32 return self._storage_bytes_read 33 34 @property 35 def storage_bytes_write(self) -> int: 36 """The amount of data written to storage, in bytes.""" 37 return self._storage_bytes_write 38 39 @property 40 def contention_retries(self) -> int: 41 """The number of times the transaction was retried due to write contention.""" 42 return self._contention_retries 43 44 @property 45 def attempts(self) -> int: 46 """The number of attempts made by the client to run the query.""" 47 return self._attempts 48 49 @attempts.setter 50 def attempts(self, value): 51 self._attempts = value 52 53 def __init__(self, stats: Mapping[str, Any]): 54 self._compute_ops = stats.get("compute_ops", 0) 55 self._read_ops = stats.get("read_ops", 0) 56 self._write_ops = stats.get("write_ops", 0) 57 self._query_time_ms = stats.get("query_time_ms", 0) 58 self._storage_bytes_read = stats.get("storage_bytes_read", 0) 59 self._storage_bytes_write = stats.get("storage_bytes_write", 0) 60 self._contention_retries = stats.get("contention_retries", 0) 61 self._attempts = 0 62 63 def __repr__(self): 64 stats = { 65 "compute_ops": self._compute_ops, 66 "read_ops": self._read_ops, 67 "write_ops": self._write_ops, 68 "query_time_ms": self._query_time_ms, 69 "storage_bytes_read": self._storage_bytes_read, 70 "storage_bytes_write": self._storage_bytes_write, 71 "contention_retries": self._contention_retries, 72 "attempts": self._attempts, 73 } 74 75 return f"{self.__class__.__name__}(stats={repr(stats)})" 76 77 def __eq__(self, other): 78 return type(self) == type(other) \ 79 and self.compute_ops == other.compute_ops \ 80 and self.read_ops == other.read_ops \ 81 and self.write_ops == other.write_ops \ 82 and self.query_time_ms == other.query_time_ms \ 83 and self.storage_bytes_read == other.storage_bytes_read \ 84 and self.storage_bytes_write == other.storage_bytes_write \ 85 and self.contention_retries == other.contention_retries \ 86 and self.attempts == other.attempts 87 88 def __ne__(self, other): 89 return not self.__eq__(other)
Query stats
QueryStats(stats: Mapping[str, Any])
53 def __init__(self, stats: Mapping[str, Any]): 54 self._compute_ops = stats.get("compute_ops", 0) 55 self._read_ops = stats.get("read_ops", 0) 56 self._write_ops = stats.get("write_ops", 0) 57 self._query_time_ms = stats.get("query_time_ms", 0) 58 self._storage_bytes_read = stats.get("storage_bytes_read", 0) 59 self._storage_bytes_write = stats.get("storage_bytes_write", 0) 60 self._contention_retries = stats.get("contention_retries", 0) 61 self._attempts = 0
compute_ops: int
9 @property 10 def compute_ops(self) -> int: 11 """The amount of Transactional Compute Ops consumed by the query.""" 12 return self._compute_ops
The amount of Transactional Compute Ops consumed by the query.
read_ops: int
14 @property 15 def read_ops(self) -> int: 16 """The amount of Transactional Read Ops consumed by the query.""" 17 return self._read_ops
The amount of Transactional Read Ops consumed by the query.
write_ops: int
19 @property 20 def write_ops(self) -> int: 21 """The amount of Transactional Write Ops consumed by the query.""" 22 return self._write_ops
The amount of Transactional Write Ops consumed by the query.
query_time_ms: int
24 @property 25 def query_time_ms(self) -> int: 26 """The query run time in milliseconds.""" 27 return self._query_time_ms
The query run time in milliseconds.
storage_bytes_read: int
29 @property 30 def storage_bytes_read(self) -> int: 31 """The amount of data read from storage, in bytes.""" 32 return self._storage_bytes_read
The amount of data read from storage, in bytes.
storage_bytes_write: int
34 @property 35 def storage_bytes_write(self) -> int: 36 """The amount of data written to storage, in bytes.""" 37 return self._storage_bytes_write
The amount of data written to storage, in bytes.
class
QueryInfo:
92class QueryInfo: 93 94 @property 95 def query_tags(self) -> Mapping[str, Any]: 96 """The tags associated with the query.""" 97 return self._query_tags 98 99 @property 100 def summary(self) -> str: 101 """A comprehensive, human readable summary of any errors, warnings and/or logs returned from the query.""" 102 return self._summary 103 104 @property 105 def stats(self) -> QueryStats: 106 """Query stats associated with the query.""" 107 return self._stats 108 109 @property 110 def txn_ts(self) -> int: 111 """The last transaction timestamp of the query. A Unix epoch in microseconds.""" 112 return self._txn_ts 113 114 @property 115 def schema_version(self) -> int: 116 """The schema version that was used for the query execution.""" 117 return self._schema_version 118 119 def __init__( 120 self, 121 query_tags: Optional[Mapping[str, str]] = None, 122 stats: Optional[QueryStats] = None, 123 summary: Optional[str] = None, 124 txn_ts: Optional[int] = None, 125 schema_version: Optional[int] = None, 126 ): 127 self._query_tags = query_tags or {} 128 self._stats = stats or QueryStats({}) 129 self._summary = summary or "" 130 self._txn_ts = txn_ts or 0 131 self._schema_version = schema_version or 0 132 133 def __repr__(self): 134 return f"{self.__class__.__name__}(" \ 135 f"query_tags={repr(self.query_tags)}," \ 136 f"stats={repr(self.stats)}," \ 137 f"summary={repr(self.summary)}," \ 138 f"txn_ts={repr(self.txn_ts)}," \ 139 f"schema_version={repr(self.schema_version)})"
QueryInfo( query_tags: Optional[Mapping[str, str]] = None, stats: Optional[QueryStats] = None, summary: Optional[str] = None, txn_ts: Optional[int] = None, schema_version: Optional[int] = None)
119 def __init__( 120 self, 121 query_tags: Optional[Mapping[str, str]] = None, 122 stats: Optional[QueryStats] = None, 123 summary: Optional[str] = None, 124 txn_ts: Optional[int] = None, 125 schema_version: Optional[int] = None, 126 ): 127 self._query_tags = query_tags or {} 128 self._stats = stats or QueryStats({}) 129 self._summary = summary or "" 130 self._txn_ts = txn_ts or 0 131 self._schema_version = schema_version or 0
summary: str
99 @property 100 def summary(self) -> str: 101 """A comprehensive, human readable summary of any errors, warnings and/or logs returned from the query.""" 102 return self._summary
A comprehensive, human readable summary of any errors, warnings and/or logs returned from the query.
stats: QueryStats
104 @property 105 def stats(self) -> QueryStats: 106 """Query stats associated with the query.""" 107 return self._stats
Query stats associated with the query.
142class QuerySuccess(QueryInfo): 143 """The result of the query.""" 144 145 @property 146 def data(self) -> Any: 147 """The data returned by the query. This is the result of the FQL query.""" 148 return self._data 149 150 @property 151 def static_type(self) -> Optional[str]: 152 """If typechecked, the query's inferred static result type, if the query was typechecked.""" 153 return self._static_type 154 155 @property 156 def traceparent(self) -> Optional[str]: 157 """The traceparent for the query.""" 158 return self._traceparent 159 160 def __init__( 161 self, 162 data: Any, 163 query_tags: Optional[Mapping[str, str]], 164 static_type: Optional[str], 165 stats: Optional[QueryStats], 166 summary: Optional[str], 167 traceparent: Optional[str], 168 txn_ts: Optional[int], 169 schema_version: Optional[int], 170 ): 171 172 super().__init__( 173 query_tags=query_tags, 174 stats=stats, 175 summary=summary, 176 txn_ts=txn_ts, 177 schema_version=schema_version, 178 ) 179 180 self._traceparent = traceparent 181 self._static_type = static_type 182 self._data = data 183 184 def __repr__(self): 185 return f"{self.__class__.__name__}(" \ 186 f"query_tags={repr(self.query_tags)}," \ 187 f"static_type={repr(self.static_type)}," \ 188 f"stats={repr(self.stats)}," \ 189 f"summary={repr(self.summary)}," \ 190 f"traceparent={repr(self.traceparent)}," \ 191 f"txn_ts={repr(self.txn_ts)}," \ 192 f"schema_version={repr(self.schema_version)}," \ 193 f"data={repr(self.data)})"
The result of the query.
QuerySuccess( data: Any, query_tags: Optional[Mapping[str, str]], static_type: Optional[str], stats: Optional[QueryStats], summary: Optional[str], traceparent: Optional[str], txn_ts: Optional[int], schema_version: Optional[int])
160 def __init__( 161 self, 162 data: Any, 163 query_tags: Optional[Mapping[str, str]], 164 static_type: Optional[str], 165 stats: Optional[QueryStats], 166 summary: Optional[str], 167 traceparent: Optional[str], 168 txn_ts: Optional[int], 169 schema_version: Optional[int], 170 ): 171 172 super().__init__( 173 query_tags=query_tags, 174 stats=stats, 175 summary=summary, 176 txn_ts=txn_ts, 177 schema_version=schema_version, 178 ) 179 180 self._traceparent = traceparent 181 self._static_type = static_type 182 self._data = data
data: Any
145 @property 146 def data(self) -> Any: 147 """The data returned by the query. This is the result of the FQL query.""" 148 return self._data
The data returned by the query. This is the result of the FQL query.
static_type: Optional[str]
150 @property 151 def static_type(self) -> Optional[str]: 152 """If typechecked, the query's inferred static result type, if the query was typechecked.""" 153 return self._static_type
If typechecked, the query's inferred static result type, if the query was typechecked.
traceparent: Optional[str]
155 @property 156 def traceparent(self) -> Optional[str]: 157 """The traceparent for the query.""" 158 return self._traceparent
The traceparent for the query.
Inherited Members
@dataclass
class
ConstraintFailure:
class
QueryTags:
203class QueryTags: 204 205 @staticmethod 206 def encode(tags: Mapping[str, str]) -> str: 207 return ",".join([f"{k}={v}" for k, v in tags.items()]) 208 209 @staticmethod 210 def decode(tag_str: str) -> Mapping[str, str]: 211 res: dict[str, str] = {} 212 for pair in tag_str.split(","): 213 kv = pair.split("=") 214 res[kv[0]] = kv[1] 215 return res