diff --git a/influxdb3/tests/cli/api.rs b/influxdb3/tests/cli/api.rs index f907f5524c8..6e580a70ce7 100644 --- a/influxdb3/tests/cli/api.rs +++ b/influxdb3/tests/cli/api.rs @@ -1,6 +1,7 @@ use crate::server::TestServer; use anyhow::{Result, bail}; use assert_cmd::cargo::CommandCargoExt; +use influxdb3_types::http::FieldType; use serde_json::Value; use std::io::Write; use std::process::{Command, Stdio}; @@ -136,6 +137,35 @@ impl CreateTableQuery<'_> { self } + pub async fn run_api(self) -> Result<(), influxdb3_client::Error> { + let fields = self + .fields + .into_iter() + .map(|(name, dt)| { + ( + name, + match dt.as_ref() { + "utf8" => FieldType::Utf8, + "bool" => FieldType::Bool, + "int64" => FieldType::Int64, + "float64" => FieldType::Float64, + "uint64" => FieldType::UInt64, + _ => panic!("invalid field type"), + }, + ) + }) + .collect(); + + self.server + .api_v3_create_table( + self.db_name.as_str(), + self.table_name.as_str(), + self.tags, + fields, + ) + .await + } + pub fn run(self) -> Result { // Convert tags to comma-separated string for --tags argument let tags_arg = self.tags.join(","); diff --git a/influxdb3/tests/server/mod.rs b/influxdb3/tests/server/mod.rs index ea198034692..f6a274fe439 100644 --- a/influxdb3/tests/server/mod.rs +++ b/influxdb3/tests/server/mod.rs @@ -11,6 +11,7 @@ use assert_cmd::cargo::CommandCargoExt; use futures::TryStreamExt; use influxdb_iox_client::flightsql::FlightSqlClient; use influxdb3_client::Precision; +use influxdb3_types::http::FieldType; use reqwest::header::{HeaderMap, HeaderName, HeaderValue}; use reqwest::{Certificate, Response, tls::Version}; use tonic::transport::ClientTlsConfig; @@ -417,6 +418,27 @@ impl TestServer { .await } + pub async fn api_v3_create_table( + &self, + database: &str, + table: &str, + tags: Vec, + fields: Vec<(String, FieldType)>, + ) -> Result<(), influxdb3_client::Error> { + let mut client = influxdb3_client::Client::new( + self.client_addr(), + Some("../testing-certs/rootCA.pem".into()), + ) + .unwrap(); + if let Some(token) = &self.auth_token { + client = client.with_auth_token(token); + } + + client + .api_v3_configure_table_create(database, table, tags, fields) + .await + } + pub async fn api_v3_query_sql_with_header( &self, params: &[(&str, &str)], diff --git a/influxdb3/tests/server/query.rs b/influxdb3/tests/server/query.rs index cf194cba575..0ad63983757 100644 --- a/influxdb3/tests/server/query.rs +++ b/influxdb3/tests/server/query.rs @@ -1916,3 +1916,31 @@ async fn api_query_with_default_browser_header() { resp ); } + +#[tokio::test] +async fn api_v3_query_show_tables_ordering() { + let server = TestServer::spawn().await; + + let tables = [ + "xxx", + "table_002", + "table_009", + "table_001", + "table_003", + "table_006", + "aaa", + ]; + + for table in tables { + server.create_table("foo", table).run_api().await.unwrap(); + } + + let output = server + .api_v3_query_sql(&[("db", "foo"), ("format", "pretty"), ("q", "SHOW TABLES")]) + .await + .text() + .await + .unwrap(); + + insta::assert_snapshot!(output); +} diff --git a/influxdb3/tests/server/snapshots/lib__server__query__api_v3_query_show_tables_ordering.snap b/influxdb3/tests/server/snapshots/lib__server__query__api_v3_query_show_tables_ordering.snap new file mode 100644 index 00000000000..0c834eea952 --- /dev/null +++ b/influxdb3/tests/server/snapshots/lib__server__query__api_v3_query_show_tables_ordering.snap @@ -0,0 +1,26 @@ +--- +source: influxdb3/tests/server/query.rs +expression: output +--- ++---------------+--------------------+----------------------------+------------+ +| table_catalog | table_schema | table_name | table_type | ++---------------+--------------------+----------------------------+------------+ +| public | iox | aaa | BASE TABLE | +| public | iox | table_001 | BASE TABLE | +| public | iox | table_002 | BASE TABLE | +| public | iox | table_003 | BASE TABLE | +| public | iox | table_006 | BASE TABLE | +| public | iox | table_009 | BASE TABLE | +| public | iox | xxx | BASE TABLE | +| public | system | distinct_caches | BASE TABLE | +| public | system | last_caches | BASE TABLE | +| public | system | parquet_files | BASE TABLE | +| public | system | processing_engine_logs | BASE TABLE | +| public | system | processing_engine_triggers | BASE TABLE | +| public | system | queries | BASE TABLE | +| public | information_schema | tables | VIEW | +| public | information_schema | views | VIEW | +| public | information_schema | columns | VIEW | +| public | information_schema | df_settings | VIEW | +| public | information_schema | schemata | VIEW | ++---------------+--------------------+----------------------------+------------+ diff --git a/influxdb3_server/src/query_executor/mod.rs b/influxdb3_server/src/query_executor/mod.rs index f33318d9134..d9e65589087 100644 --- a/influxdb3_server/src/query_executor/mod.rs +++ b/influxdb3_server/src/query_executor/mod.rs @@ -639,11 +639,14 @@ impl SchemaProvider for Database { } fn table_names(&self) -> Vec { - self.db_schema + let mut names = self + .db_schema .table_names() .iter() .map(|t| t.to_string()) - .collect() + .collect::>(); + names.sort(); + names } async fn table(