Tabular¶
deep_db_agents.tabular ¶
Conversion of heterogeneous documents/records into tabular (columns, rows) form.
Helper shared by non-relational dialects (MongoDB, Neo4j, Elasticsearch/OpenSearch) for materializing results to file: columns are the ordered union of top-level keys, nested values are serialized to a string.
docs_to_table ¶
docs_to_table(docs: list[dict], *, scalar: Callable[[Any], Any] = scalar_json) -> tuple[list[str], list[list[Any]]]
Convert heterogeneous documents into (columns, rows).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docs
|
list[dict]
|
List of documents (dicts) to convert. |
required |
scalar
|
Callable[[Any], Any]
|
Callable used to serialize nested values; the default uses JSON,
dialects can pass a specific serializer (e.g. |
scalar_json
|
Returns:
| Type | Description |
|---|---|
list[str]
|
tuple[list[str], list[list[Any]]]: The ordered column names and the list of |
list[list[Any]]
|
rows, each row aligned with |
Source code in src/deep_db_agents/tabular.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
scalar_json ¶
scalar_json(value: Any) -> Any
Keep scalars as-is; serialize nested values (dict/list) to a JSON string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
The value to normalize. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
|
Any
|
serialization. |
Source code in src/deep_db_agents/tabular.py
15 16 17 18 19 20 21 22 23 24 25 26 27 | |
union_columns ¶
union_columns(docs: list[dict]) -> list[str]
Compute the ordered (first-occurrence) union of documents' top-level keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docs
|
list[dict]
|
List of documents (dicts) to inspect. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: The keys found across all documents, in first-occurrence order. |
Source code in src/deep_db_agents/tabular.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |