Skip to content

Commit ae99dd5

Browse files
More endpoints
1 parent 6303459 commit ae99dd5

6 files changed

Lines changed: 621 additions & 7 deletions

File tree

.claude/settings.local.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"Bash(cat:*)",
2222
"Bash(cargo clippy:*)",
2323
"Bash(find:*)",
24-
"WebFetch(domain:arrow.apache.org)"
24+
"WebFetch(domain:arrow.apache.org)",
25+
"Bash(timeout 90 cargo test:*)"
2526
],
2627
"deny": [],
2728
"ask": []

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, CommandGetSqlInfo,
24+
CommandGetTableTypes, CommandGetTables, 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;

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)