Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rename json_lines to jsonl for cli #25888

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading