mirror of
https://github.com/lancedb/lancedb.git
synced 2026-04-13 11:20:39 +00:00
refactor: rename serialize_to_json/from_serialized_json to serialize/deserialize
Simpler names, docs no longer reference JSON as the serialization format. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -237,20 +237,20 @@ def _apply_worker_overrides(props: dict[str, str]) -> dict[str, str]:
|
||||
return result
|
||||
|
||||
|
||||
def from_serialized_json(
|
||||
json_str: str,
|
||||
def deserialize(
|
||||
data: str,
|
||||
*,
|
||||
for_worker: bool = False,
|
||||
) -> DBConnection:
|
||||
"""Reconstruct a DBConnection from a JSON string.
|
||||
"""Reconstruct a DBConnection from a serialized string.
|
||||
|
||||
The JSON string must have been produced by
|
||||
:meth:`DBConnection.serialize_to_json`.
|
||||
The string must have been produced by
|
||||
:meth:`DBConnection.serialize`.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
json_str : str
|
||||
JSON string produced by ``serialize_to_json()``.
|
||||
data : str
|
||||
String produced by ``serialize()``.
|
||||
for_worker : bool, default False
|
||||
When ``True``, any namespace client property whose key starts
|
||||
with ``_lancedb_worker_`` has that prefix stripped and the
|
||||
@@ -264,27 +264,27 @@ def from_serialized_json(
|
||||
"""
|
||||
import json
|
||||
|
||||
data = json.loads(json_str)
|
||||
connection_type = data.get("connection_type")
|
||||
parsed = json.loads(data)
|
||||
connection_type = parsed.get("connection_type")
|
||||
|
||||
rci_secs = data.get("read_consistency_interval_seconds")
|
||||
rci_secs = parsed.get("read_consistency_interval_seconds")
|
||||
rci = timedelta(seconds=rci_secs) if rci_secs is not None else None
|
||||
storage_options = data.get("storage_options")
|
||||
storage_options = parsed.get("storage_options")
|
||||
|
||||
if connection_type == "namespace":
|
||||
props = dict(data.get("namespace_client_properties") or {})
|
||||
props = dict(parsed.get("namespace_client_properties") or {})
|
||||
if for_worker:
|
||||
props = _apply_worker_overrides(props)
|
||||
return connect_namespace(
|
||||
namespace_client_impl=data["namespace_client_impl"],
|
||||
namespace_client_impl=parsed["namespace_client_impl"],
|
||||
namespace_client_properties=props,
|
||||
read_consistency_interval=rci,
|
||||
storage_options=storage_options,
|
||||
namespace_client_pushdown_operations=data.get("pushdown_operations"),
|
||||
namespace_client_pushdown_operations=parsed.get("pushdown_operations"),
|
||||
)
|
||||
elif connection_type == "local":
|
||||
return LanceDBConnection(
|
||||
data["uri"],
|
||||
parsed["uri"],
|
||||
read_consistency_interval=rci,
|
||||
storage_options=storage_options,
|
||||
)
|
||||
|
||||
@@ -529,19 +529,19 @@ class DBConnection(EnforceOverrides):
|
||||
"namespace_client is not supported for this connection type"
|
||||
)
|
||||
|
||||
def serialize_to_json(self) -> str:
|
||||
"""Serialize this connection to a JSON string for reconstruction.
|
||||
def serialize(self) -> str:
|
||||
"""Serialize this connection for reconstruction.
|
||||
|
||||
The returned JSON can be passed to :func:`from_serialized_json`
|
||||
The returned string can be passed to :func:`lancedb.deserialize`
|
||||
to recreate an equivalent connection, e.g. in a remote worker.
|
||||
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
JSON string representation of this connection.
|
||||
Serialized representation of this connection.
|
||||
"""
|
||||
raise NotImplementedError(
|
||||
"serialize_to_json is not supported for this connection type"
|
||||
"serialize is not supported for this connection type"
|
||||
)
|
||||
|
||||
|
||||
@@ -670,7 +670,7 @@ class LanceDBConnection(DBConnection):
|
||||
return val
|
||||
|
||||
@override
|
||||
def serialize_to_json(self) -> str:
|
||||
def serialize(self) -> str:
|
||||
import json
|
||||
|
||||
rci = self.read_consistency_interval
|
||||
|
||||
@@ -424,7 +424,7 @@ class LanceNamespaceDBConnection(DBConnection):
|
||||
self._namespace_client_properties = namespace_client_properties
|
||||
|
||||
@override
|
||||
def serialize_to_json(self) -> str:
|
||||
def serialize(self) -> str:
|
||||
import json
|
||||
|
||||
return json.dumps({
|
||||
|
||||
Reference in New Issue
Block a user