Open renardeinside opened 1 month ago
Note: I'm quite sure that returned payload is arrow-compatible. It's generated like this:
@api_app.get("/satellites/positions")
def get_satellite_in_time_window(
from_dttm_iso: Annotated[str, Query(alias="from")],
to_dttm_iso: Annotated[str, Query(alias="to")],
satellite_ids: Annotated[list[int] | None, Query()] = None,
db: duckdb.DuckDBPyConnection = Depends(db),
):
from_dttm = dt.datetime.fromisoformat(from_dttm_iso)
to_dttm = dt.datetime.fromisoformat(to_dttm_iso)
satellite_ids = (
satellite_ids
or db.execute("EXECUTE query_satellite_ids").fetchdf()["satnum"].to_list()
)
# get satellite positions in the time window
satellite_positions: pa.Table = db.sql(
"""select * from satellite_positions
where ts between '{start}' and '{end}'
and satnum in ({satellite_ids})
""".format(
start=from_dttm.isoformat(),
end=to_dttm.isoformat(),
satellite_ids=",".join(map(str, satellite_ids)),
)
).fetch_arrow_table()
def stream_arrow_data():
sink = io.BytesIO()
writer = pa.ipc.new_stream(sink, satellite_positions.schema)
writer.write_table(satellite_positions)
sink.seek(0)
while chunk := sink.read(64 * 1024):
yield chunk
return StreamingResponse(stream_arrow_data(), media_type="application/octet-stream")
Where the data is coming from a DuckDB (which means that it's in correct byte format).
Moreover, if I read this data from arquero
library in browser, it works as expected:
import * as aq from "arquero";
const rawData = await apiClient.get("/satellites/positions", {
params: params,
responseType: "arraybuffer",
});
const buffer = rawData.data as ArrayBuffer;
const typed = new Uint8Array(buffer);
console.log(`Array size: ${typed.length}`);
console.log(`First 10 bytes: ${typed.slice(0, 10)}`);
const table = aq.fromArrow(typed);
Meaning that it's also shouldn't be the issue of the serialization or something like that.
Upd: removing a string column name
from the response table on the server side fixed the problem. Clearly, it's something about utf8 string conversion.
Checks
Reproducible example
Quick testing example in Rust:
With the following
Cargo.toml
:Running the test:
Log output
Issue description
I'm quite unsure what's missing here. Maybe some tests misconfiguration?
Expected behavior
Works as expected.
Installed versions