1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//! Arrow Flight SQL gRPC server for the Rhei HTAP engine.
//!
//! This crate exposes the OLAP backend (DataFusion or DuckDB) over the
//! [Arrow Flight SQL](https://arrow.apache.org/docs/format/FlightSql.html)
//! protocol, letting clients such as `adbc_driver_flightsql` (Python), DBeaver,
//! or any standard Arrow Flight SQL driver run analytical queries via gRPC.
//!
//! # Architecture
//!
//! The crate is built on `arrow-flight 58` and `tonic 0.14`. The core service
//! is [`RheiFlightSqlService`], which implements `FlightSqlService` and
//! delegates all query execution to [`rhei_olap::OlapBackend`].
//!
//! ## Deferred-execution pattern
//!
//! `get_flight_info_*` encodes the SQL string into an opaque
//! ticket and returns a `FlightInfo` immediately — no query planning occurs
//! yet. When the client calls `do_get_*` with that ticket, the service
//! decodes the SQL, calls [`rhei_core::OlapEngine::query_stream`], and streams
//! Arrow IPC record batches back over the gRPC connection.
//!
//! Tickets are cheap opaque byte handles; deferring query planning to
//! `do_get` keeps `get_flight_info` latency negligible and avoids holding
//! engine resources while the client is not yet ready to consume data.
//!
//! ## Compression
//!
//! Arrow IPC record batches are compressed before transmission.
//! [`CompressionType::Zstd`] is the default — it offers the best
//! size/CPU tradeoff for typical columnar workloads.
//! [`CompressionType::Lz4`] is available for CPU-constrained clients that
//! need faster decompression. [`CompressionType::None`] disables compression
//! entirely, which is useful on loopback or high-bandwidth LAN links.
//!
//! ## Read-only constraint
//!
//! All write operations (`do_put_*`) return `tonic::Status::unimplemented`.
//! Rhei's OLAP layer carries no DML semantics — INSERT / UPDATE / DELETE go
//! through the OLTP engine (Rusqlite) on a separate path.
//!
//! # Quick start
//!
//! ```rust,no_run
//! use std::net::SocketAddr;
//! use rhei_flight::serve_flight_sql;
//! # async fn example(olap: rhei_olap::OlapBackend) -> Result<(), Box<dyn std::error::Error>> {
//! let addr: SocketAddr = "0.0.0.0:50051".parse()?;
//! serve_flight_sql(olap, addr).await?;
//! # Ok(()) }
//! ```
pub use ;
use SocketAddr;
use Server;
use info;
/// Start the Arrow Flight SQL gRPC server with [`CompressionType::Zstd`] (the default).
///
/// Binds a tonic gRPC server on `addr` and serves Arrow Flight SQL queries
/// against the provided [`rhei_olap::OlapBackend`]. This is a convenience
/// wrapper around [`serve_flight_sql_with_compression`] that pre-selects Zstd.
///
/// The call blocks until the server shuts down or returns an error.
pub async
/// Start the Arrow Flight SQL gRPC server with the specified [`CompressionType`].
///
/// Binds a tonic gRPC server on `addr` and serves Arrow Flight SQL queries
/// against the provided [`rhei_olap::OlapBackend`]. Use this variant when
/// you need to override the default Zstd compression — for example, to select
/// [`CompressionType::Lz4`] on CPU-constrained clients or
/// [`CompressionType::None`] on loopback deployments.
///
/// The call blocks until the server shuts down or returns an error.
pub async
/// Start the Arrow Flight SQL gRPC server with bearer-token authentication.
///
/// Identical to [`serve_flight_sql`] but requires every client RPC to carry
/// `authorization: Bearer {token}` in the gRPC metadata. Requests that omit
/// or present a wrong token are rejected with `tonic::Status::unauthenticated`.
///
/// Uses [`CompressionType::Zstd`] by default. To combine custom compression
/// with authentication, construct a [`RheiFlightSqlService`] manually using
/// [`RheiFlightSqlService::with_compression`] and
/// [`RheiFlightSqlService::with_auth_token`].
///
/// The call blocks until the server shuts down or returns an error.
pub async