Skip to content

Commit 7824198

Browse files
Meta endpoints (#351)
1 parent 18f9372 commit 7824198

File tree

9 files changed

+841
-16
lines changed

9 files changed

+841
-16
lines changed

.claude/settings.local.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
"Bash(RUST_LOG=debug cargo run:*)",
2121
"Bash(cat:*)",
2222
"Bash(cargo clippy:*)",
23-
"Bash(test:*)"
23+
"Bash(find:*)",
24+
"WebFetch(domain:arrow.apache.org)",
25+
"Bash(timeout 90 cargo test:*)",
26+
"Bash(test:*)",
2427
"WebFetch(domain:github.com)",
2528
"Bash(ls:*)",
2629
"Bash(grep:*)"

.github/actions/setup-rust/action.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ runs:
4242
- name: Install Cargo tools
4343
shell: bash
4444
run: |
45-
cargo install taplo-cli --locked
46-
cargo install just
47-
cargo install --version 0.8.0 cargo-machete --locked
45+
command -v taplo &> /dev/null || cargo install taplo-cli --locked
46+
command -v just &> /dev/null || cargo install just
47+
command -v cargo-machete &> /dev/null || cargo install --version 0.8.0 cargo-machete --locked

crates/datafusion-app/src/flightsql.rs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ use std::sync::Arc;
1919

2020
use arrow_flight::{
2121
decode::FlightRecordBatchStream,
22-
sql::{client::FlightSqlServiceClient, CommandGetDbSchemas, CommandGetTables},
22+
sql::{
23+
client::FlightSqlServiceClient, CommandGetDbSchemas, CommandGetTables,
24+
CommandGetXdbcTypeInfo,
25+
},
2326
FlightInfo,
2427
};
2528
#[cfg(feature = "flightsql")]
@@ -287,6 +290,62 @@ impl FlightSQLContext {
287290
}
288291
}
289292

293+
pub async fn get_table_types_flight_info(&self) -> DFResult<FlightInfo> {
294+
let client = Arc::clone(&self.client);
295+
let mut guard = client.lock().await;
296+
if let Some(client) = guard.as_mut() {
297+
client
298+
.get_table_types()
299+
.await
300+
.map_err(|e| DataFusionError::ArrowError(Box::new(e), None))
301+
} else {
302+
Err(DataFusionError::External(
303+
"No FlightSQL client configured. Add one in `~/.config/dft/config.toml`".into(),
304+
))
305+
}
306+
}
307+
308+
pub async fn get_sql_info_flight_info(&self, info: Option<Vec<u32>>) -> DFResult<FlightInfo> {
309+
let client = Arc::clone(&self.client);
310+
let mut guard = client.lock().await;
311+
if let Some(client) = guard.as_mut() {
312+
use arrow_flight::sql::SqlInfo;
313+
// Convert u32 IDs to SqlInfo enum variants if needed
314+
let sql_info_list: Vec<SqlInfo> = info
315+
.unwrap_or_default()
316+
.into_iter()
317+
.filter_map(|id| SqlInfo::try_from(id as i32).ok())
318+
.collect();
319+
client
320+
.get_sql_info(sql_info_list)
321+
.await
322+
.map_err(|e| DataFusionError::ArrowError(Box::new(e), None))
323+
} else {
324+
Err(DataFusionError::External(
325+
"No FlightSQL client configured. Add one in `~/.config/dft/config.toml`".into(),
326+
))
327+
}
328+
}
329+
330+
pub async fn get_xdbc_type_info_flight_info(
331+
&self,
332+
data_type: Option<i32>,
333+
) -> DFResult<FlightInfo> {
334+
let client = Arc::clone(&self.client);
335+
let mut guard = client.lock().await;
336+
if let Some(client) = guard.as_mut() {
337+
let cmd = CommandGetXdbcTypeInfo { data_type };
338+
client
339+
.get_xdbc_type_info(cmd)
340+
.await
341+
.map_err(|e| DataFusionError::ArrowError(Box::new(e), None))
342+
} else {
343+
Err(DataFusionError::External(
344+
"No FlightSQL client configured. Add one in `~/.config/dft/config.toml`".into(),
345+
))
346+
}
347+
}
348+
290349
pub async fn do_get(&self, flight_info: FlightInfo) -> DFResult<Vec<FlightRecordBatchStream>> {
291350
let client = Arc::clone(&self.client);
292351
let mut guard = client.lock().await;

docs/cli.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ dft flightsql get-db-schemas --db-schema-filter-pattern "my%"
3838
# List tables in a schema
3939
dft flightsql get-tables --catalog mycatalog --db-schema-filter-pattern myschema
4040
dft flightsql get-tables --table-name-filter-pattern "table" --table-types VIEW
41+
42+
# Get supported table types
43+
dft flightsql get-table-types
44+
45+
# Get SQL capabilities and server information
46+
dft flightsql get-sql-info
47+
dft flightsql get-sql-info --info 1 --info 2 # Query specific info IDs
48+
49+
# Get data type information (XDBC/ODBC type metadata)
50+
dft flightsql get-xdbc-type-info
51+
dft flightsql get-xdbc-type-info --data-type 4 # Filter by specific SQL data type
4152
```
4253

4354
## Auth

docs/flightsql_server.md

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,23 @@ dft serve-flightsql --run-ddl
1616

1717
The server implements the FlightSQL protocol, providing:
1818

19-
- SQL query execution
20-
- Schema fetching (TODO)
21-
- Prepared statements (TODO)
22-
- Catalog browsing (TODO)
19+
### Core Query Execution
20+
- **SQL query execution** - Execute SQL statements via `CommandStatementQuery`
21+
- **Prepared statements** - Create, execute, and close prepared statements for improved performance
22+
- `ActionCreatePreparedStatement` - Parse and prepare SQL statements
23+
- `ActionClosePreparedStatement` - Release prepared statement resources
24+
- `CommandPreparedStatementQuery` - Execute prepared statements
25+
26+
### Metadata Discovery
27+
- **Catalog browsing** - Discover database structure and metadata
28+
- `CommandGetCatalogs` - List available catalogs
29+
- `CommandGetDbSchemas` - List schemas with optional filtering
30+
- `CommandGetTables` - List tables with filtering by catalog, schema, name pattern, and type
31+
- `CommandGetTableTypes` - Get supported table types (TABLE, VIEW, etc.)
32+
33+
### Server Capabilities
34+
- **SQL information** - Query server capabilities and version information via `CommandGetSqlInfo`
35+
- **Type metadata** - Get XDBC/ODBC type information via `CommandGetXdbcTypeInfo` for understanding supported data types
2336

2437
## Client Connections (TODO - Test this)
2538

@@ -54,10 +67,19 @@ server_metrics_addr = "0.0.0.0:9000"
5467
```
5568

5669
Available metrics include:
57-
- Query execution time
58-
- Active connections
59-
- Errors by type
60-
- Memory usage
70+
- Query execution time (by endpoint)
71+
- `get_flight_info_latency_ms` - Flight info request latency
72+
- `do_get_fallback_latency_ms` - Data fetch latency
73+
- `get_flight_info_table_types_latency_ms` - Table types metadata latency
74+
- `get_flight_info_sql_info_latency_ms` - SQL info metadata latency
75+
- `get_flight_info_xdbc_type_info_latency_ms` - Type info metadata latency
76+
- `do_action_create_prepared_statement_latency_ms` - Prepared statement creation latency
77+
- `do_action_close_prepared_statement_latency_ms` - Prepared statement cleanup latency
78+
- `get_flight_info_prepared_statement_latency_ms` - Prepared statement flight info latency
79+
- `do_get_prepared_statement_latency_ms` - Prepared statement execution latency
80+
- Active prepared statements (`prepared_statements_active` gauge)
81+
- Request counts by endpoint
82+
- Observability request details (when enabled) stored in `dft.observability_requests` table
6183

6284
## Configuration
6385

src/args.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,20 @@ pub enum FlightSqlCommand {
171171
#[clap(long)]
172172
table_types: Option<Vec<String>>,
173173
},
174+
/// Executes `CommandGetTableTypes` and `DoGet` to return supported table types
175+
GetTableTypes,
176+
/// Executes `CommandGetSqlInfo` and `DoGet` to return server SQL capabilities
177+
GetSqlInfo {
178+
/// Specific SQL info IDs to retrieve (if not provided, returns all)
179+
#[clap(long)]
180+
info: Option<Vec<u32>>,
181+
},
182+
/// Executes `CommandGetXdbcTypeInfo` and `DoGet` to return type information
183+
GetXdbcTypeInfo {
184+
/// Optional data type to filter by
185+
#[clap(long)]
186+
data_type: Option<i32>,
187+
},
174188
}
175189

176190
#[derive(Clone, Debug, Subcommand)]

src/cli/mod.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,51 @@ impl CliApp {
155155
self.print_any_stream(flight_batch_stream).await;
156156
Ok(())
157157
}
158+
FlightSqlCommand::GetTableTypes => {
159+
let flight_info = self
160+
.app_execution
161+
.flightsql_ctx()
162+
.get_table_types_flight_info()
163+
.await?;
164+
let streams = self
165+
.app_execution
166+
.flightsql_ctx()
167+
.do_get(flight_info)
168+
.await?;
169+
let flight_batch_stream = stream::select_all(streams);
170+
self.print_any_stream(flight_batch_stream).await;
171+
Ok(())
172+
}
173+
FlightSqlCommand::GetSqlInfo { info } => {
174+
let flight_info = self
175+
.app_execution
176+
.flightsql_ctx()
177+
.get_sql_info_flight_info(info)
178+
.await?;
179+
let streams = self
180+
.app_execution
181+
.flightsql_ctx()
182+
.do_get(flight_info)
183+
.await?;
184+
let flight_batch_stream = stream::select_all(streams);
185+
self.print_any_stream(flight_batch_stream).await;
186+
Ok(())
187+
}
188+
FlightSqlCommand::GetXdbcTypeInfo { data_type } => {
189+
let flight_info = self
190+
.app_execution
191+
.flightsql_ctx()
192+
.get_xdbc_type_info_flight_info(data_type)
193+
.await?;
194+
let streams = self
195+
.app_execution
196+
.flightsql_ctx()
197+
.do_get(flight_info)
198+
.await?;
199+
let flight_batch_stream = stream::select_all(streams);
200+
self.print_any_stream(flight_batch_stream).await;
201+
Ok(())
202+
}
158203
}
159204
}
160205

0 commit comments

Comments
 (0)