diff --git a/influxdb3/src/commands/common.rs b/influxdb3/src/commands/common.rs index 029190ce3d0..19378140803 100644 --- a/influxdb3/src/commands/common.rs +++ b/influxdb3/src/commands/common.rs @@ -1,4 +1,4 @@ -use clap::Parser; +use clap::{Parser, ValueEnum}; use secrecy::Secret; use std::error::Error; use std::fmt::Display; @@ -25,6 +25,35 @@ pub struct InfluxDb3Config { pub auth_token: Option>, } +#[derive(Debug, ValueEnum, Clone)] +#[clap(rename_all = "snake_case")] +pub enum Format { + Pretty, + Json, + #[clap(name = "jsonl")] + JsonLines, + Csv, + Parquet, +} + +impl Format { + pub fn is_parquet(&self) -> bool { + matches!(self, Self::Parquet) + } +} + +impl From for influxdb3_client::Format { + fn from(this: Format) -> Self { + match this { + Format::Pretty => Self::Pretty, + Format::Json => Self::Json, + Format::JsonLines => Self::JsonLines, + Format::Csv => Self::Csv, + Format::Parquet => Self::Parquet, + } + } +} + // A clap argument provided as a key/value pair separated by `SEPARATOR`, which by default is a '=' #[derive(Debug, Clone)] pub struct SeparatedKeyValue(pub (K, V)); diff --git a/influxdb3/src/commands/query.rs b/influxdb3/src/commands/query.rs index baa71d1dc35..2a70caf7051 100644 --- a/influxdb3/src/commands/query.rs +++ b/influxdb3/src/commands/query.rs @@ -7,6 +7,8 @@ use tokio::{ io::{self, AsyncWriteExt}, }; +use crate::commands::common::Format; + use super::common::InfluxDb3Config; #[derive(Debug, thiserror::Error)] @@ -63,34 +65,6 @@ pub struct Config { query: Vec, } -#[derive(Debug, ValueEnum, Clone)] -#[clap(rename_all = "snake_case")] -enum Format { - Pretty, - Json, - JsonLines, - Csv, - Parquet, -} - -impl Format { - fn is_parquet(&self) -> bool { - matches!(self, Self::Parquet) - } -} - -impl From for influxdb3_client::Format { - fn from(this: Format) -> Self { - match this { - Format::Pretty => Self::Pretty, - Format::Json => Self::Json, - Format::JsonLines => Self::JsonLines, - Format::Csv => Self::Csv, - Format::Parquet => Self::Parquet, - } - } -} - #[derive(Debug, ValueEnum, Clone)] enum QueryLanguage { Sql, diff --git a/influxdb3/src/commands/show.rs b/influxdb3/src/commands/show.rs index 25b1c66153b..1f4b5f0d0c6 100644 --- a/influxdb3/src/commands/show.rs +++ b/influxdb3/src/commands/show.rs @@ -1,8 +1,10 @@ -use clap::{Parser, ValueEnum}; +use clap::Parser; use secrecy::{ExposeSecret, Secret}; use std::error::Error; use url::Url; +use crate::commands::common::Format; + #[derive(Debug, Parser)] pub struct Config { #[clap(subcommand)] @@ -39,26 +41,6 @@ pub struct DatabaseConfig { output_format: Format, } -#[derive(Debug, ValueEnum, Clone)] -#[clap(rename_all = "snake_case")] -enum Format { - Pretty, - Json, - JsonLines, - Csv, -} - -impl From for influxdb3_client::Format { - fn from(this: Format) -> Self { - match this { - Format::Pretty => Self::Pretty, - Format::Json => Self::Json, - Format::JsonLines => Self::JsonLines, - Format::Csv => Self::Csv, - } - } -} - pub(crate) async fn command(config: Config) -> Result<(), Box> { match config.cmd { SubCommand::Databases(DatabaseConfig { diff --git a/influxdb3/tests/server/cli.rs b/influxdb3/tests/server/cli.rs index 05327212d0a..eb632dae250 100644 --- a/influxdb3/tests/server/cli.rs +++ b/influxdb3/tests/server/cli.rs @@ -278,7 +278,7 @@ async fn test_show_databases() { "--host", &server_addr, "--format", - "json_lines", + "jsonl", ]); assert_eq!( "\ diff --git a/influxdb3/tests/server/query.rs b/influxdb3/tests/server/query.rs index a5a759d7f3b..283b89e9e9a 100644 --- a/influxdb3/tests/server/query.rs +++ b/influxdb3/tests/server/query.rs @@ -780,7 +780,7 @@ async fn api_v3_query_jsonl_format() { }, ]; for t in test_cases { - let mut params = vec![("q", t.query), ("format", "json_lines")]; + let mut params = vec![("q", t.query), ("format", "jsonl")]; if let Some(db) = t.database { params.push(("db", db)) }