query-farm-duckdb-json-serialization
This Python module provides a Pydantic parser for DuckDB expressions that have been serialized to JSON by the Airport DuckDB extension.
These expressions are used by Apache Arrow Flight servers to perform predicate pushdown — enabling the server to filter rows efficiently before sending data to the client.
Purpose
The module's primary function is to:
- Parse DuckDB expressions serialized as JSON.
- Optionally convert the parsed expressions back into SQL.
- Allow server-side row filtering using DuckDB, before returning data via Arrow Flight.
Note: The JSON format used by Airport differs from the built-in DuckDB JSON serialization. Specifically, binary values are encoded using Base64 in Airport for UTF-8 compatibility.
Installation
pip install query-farm-duckdb-json-serialization
API Usage
from query_farm_duckdb_json_serialization.expression import Expression
column_names_by_index = ['first_name', 'last_name']
# If there are multiple expressions passed, these will all
# be logically joined with an AND operator.
#
# The DuckDB data typestypes of the columns bound by the expressions
# will be returned.
sql, bound_types = Expression.convert_to_sql(
source=expressions,
bound_column_names=column_names_by_index
)
expressions: JSON-serialized list of DuckDB expression trees.bound_column_names: Column names indexed as expected by DuckDB.sql: ReconstructedSQL WHEREclause.bound_types: List of DuckDB data types for the bound columns.
Input
The structure of DuckDB's serialized expressions may change between versions. Below is a working example.
CREATE TABLE test_type_int64 (v int64);
INSERT INTO test_type_int64 values (1234567890123456789);
-- This statement will generate the following JSON serialization.
SELECT v FROM test_type_int64 WHERE v = 1234567890123456789;
[
{
"expression_class": "BOUND_COMPARISON",
"type": "COMPARE_EQUAL",
"alias": "",
"query_location": 18446744073709551615,
"left": {
"expression_class": "BOUND_COLUMN_REF",
"type": "BOUND_COLUMN_REF",
"alias": "v",
"query_location": 18446744073709551615,
"return_type": {
"id": "BIGINT",
"type_info": null
},
"binding": {
"table_index": 0,
"column_index": 0
},
"depth": 0
},
"right": {
"expression_class": "BOUND_CONSTANT",
"type": "VALUE_CONSTANT",
"alias": "",
"query_location": 18446744073709551615,
"value": {
"type": {
"id": "BIGINT",
"type_info": null
},
"is_null": false,
"value": 1234567890123456789
}
}
}
]
Author
This Python module was created by Query.Farm.
License
MIT License. See LICENSE for details.
Metadata
Release files for query-farm-duckdb-json-serialization 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| query_farm_duckdb_json_serialization-0.1.4.tar.gz | 14.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| query_farm_duckdb_json_serialization-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 29.4 kB
Release files / query_farm_duckdb_json_serialization-0.1.4.tar.gz
| Download URL | query_farm_duckdb_json_serialization-0.1.4.tar.gz |
|---|---|
| Size | 14.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fb7750764ee8cd2d29d380130a1264bd6b3e7729e6a516b395e88ffc2bcca3ea
|
|
BLAKE2b-256 checksum How to use checksums |
93352b84db561313b2e29468753488a3bd792afc311e3210dbecd2571266bd46
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / query_farm_duckdb_json_serialization-0.1.4-py3-none-any.whl
| Download URL | query_farm_duckdb_json_serialization-0.1.4-py3-none-any.whl |
|---|---|
| Size | 14.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7d9e27e8000ab5a437b52819fa2e8628a9a578537bcb295af7ab77d32234b244
|
|
BLAKE2b-256 checksum How to use checksums |
d99ff8386f8f155cc15cc24f573e307710e620872e29c4bd446aaec76db19bb8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|