Skip to content

Commit f897723

Browse files
Test for query command
1 parent 3048dc9 commit f897723

4 files changed

Lines changed: 46 additions & 7 deletions

File tree

src/cli/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ impl CliApp {
8585
}
8686

8787
#[cfg(feature = "flightsql")]
88-
fn handle_flightsql_command(&self, command: FlightSqlCommand) {}
88+
async fn handle_flightsql_command(&self, command: FlightSqlCommand) -> color_eyre::Result<()> {
89+
match command {
90+
FlightSqlCommand::Query { sql } => self.exec_from_flightsql(sql, 0).await,
91+
}
92+
}
8993

9094
/// Execute the provided sql, which was passed as an argument from CLI.
9195
///
@@ -98,9 +102,9 @@ impl CliApp {
98102
self.validate_args()?;
99103

100104
#[cfg(feature = "flightsql")]
101-
if let Some(Command::FlightSql { command }) = self.args.command {
102-
self.handle_flightsql_command(command)
103-
}
105+
if let Some(Command::FlightSql { command }) = &self.args.command {
106+
return self.handle_flightsql_command(command.clone()).await;
107+
};
104108

105109
#[cfg(not(feature = "flightsql"))]
106110
match (
@@ -613,7 +617,7 @@ pub async fn try_run(cli: DftArgs, config: AppConfig) -> Result<()> {
613617
let mut app_execution = AppExecution::new(execution_ctx);
614618
#[cfg(feature = "flightsql")]
615619
{
616-
if cli.flightsql {
620+
if cli.flightsql || matches!(cli.command, Some(Command::FlightSql { .. })) {
617621
let auth = AuthConfig {
618622
basic_auth: config.flightsql_client.auth.basic_auth,
619623
bearer_token: config.flightsql_client.auth.bearer_token,

src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ async fn app_entry_point(cli: DftArgs) -> Result<()> {
9191
}
9292
}
9393

94-
if !cli.files.is_empty() || !cli.commands.is_empty() {
94+
if !cli.files.is_empty()
95+
|| !cli.commands.is_empty()
96+
|| matches!(cli.command, Some(Command::FlightSql { .. }))
97+
{
9598
cli::try_run(cli, cfg).await?;
9699
} else {
97100
tui::try_run(cli, cfg).await?;

tests/cli_cases/tpch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async fn test_custom_config_with_s3() {
7373
);
7474
let config = config_builder.build("my_config.toml");
7575

76-
let a = Command::cargo_bin("dft")
76+
Command::cargo_bin("dft")
7777
.unwrap()
7878
.arg("--config")
7979
.arg(config.path)

tests/extension_cases/flightsql.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ async fn test_output_parquet() {
608608
.unwrap()
609609
.arg("-c")
610610
.arg(sql.clone())
611+
.arg("--flightsql")
611612
.arg("-o")
612613
.arg(cloned_path)
613614
.assert()
@@ -633,3 +634,34 @@ async fn test_output_parquet() {
633634

634635
fixture.shutdown_and_wait().await;
635636
}
637+
638+
#[tokio::test]
639+
async fn test_flightsql_query_command() {
640+
let test_server = TestFlightSqlServiceImpl::new();
641+
let fixture = TestFixture::new(test_server.service(), "127.0.0.1:50051").await;
642+
643+
let assert = tokio::task::spawn_blocking(|| {
644+
let sql = "SELECT 1".to_string();
645+
Command::cargo_bin("dft")
646+
.unwrap()
647+
.arg("flightsql")
648+
.arg("query")
649+
.arg(sql.clone())
650+
.timeout(Duration::from_secs(5))
651+
.assert()
652+
.success()
653+
})
654+
.await
655+
.unwrap();
656+
657+
let expected = r#"
658+
+----------+
659+
| Int64(1) |
660+
+----------+
661+
| 1 |
662+
+----------+"#;
663+
664+
assert.stdout(contains_str(expected));
665+
666+
fixture.shutdown_and_wait().await;
667+
}

0 commit comments

Comments
 (0)