Skip to content

Commit

Permalink
feat: rename json_lines to jsonl for cli (#25888)
Browse files Browse the repository at this point in the history
closes: #25873
  • Loading branch information
praveen-influx authored Jan 21, 2025
1 parent d1fd155 commit d39a4a2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 52 deletions.
31 changes: 30 additions & 1 deletion influxdb3/src/commands/common.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::Parser;
use clap::{Parser, ValueEnum};
use secrecy::Secret;
use std::error::Error;
use std::fmt::Display;
Expand All @@ -25,6 +25,35 @@ pub struct InfluxDb3Config {
pub auth_token: Option<Secret<String>>,
}

#[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<Format> 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<K, V, const SEPARATOR: char = '='>(pub (K, V));
Expand Down
30 changes: 2 additions & 28 deletions influxdb3/src/commands/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use tokio::{
io::{self, AsyncWriteExt},
};

use crate::commands::common::Format;

use super::common::InfluxDb3Config;

#[derive(Debug, thiserror::Error)]
Expand Down Expand Up @@ -63,34 +65,6 @@ pub struct Config {
query: Vec<String>,
}

#[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<Format> 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,
Expand Down
24 changes: 3 additions & 21 deletions influxdb3/src/commands/show.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -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<Format> 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<dyn Error>> {
match config.cmd {
SubCommand::Databases(DatabaseConfig {
Expand Down
2 changes: 1 addition & 1 deletion influxdb3/tests/server/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ async fn test_show_databases() {
"--host",
&server_addr,
"--format",
"json_lines",
"jsonl",
]);
assert_eq!(
"\
Expand Down
2 changes: 1 addition & 1 deletion influxdb3/tests/server/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down

0 comments on commit d39a4a2

Please sign in to comment.