Skip to content
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
30 changes: 30 additions & 0 deletions influxdb3/tests/cli/api.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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<String> {
// Convert tags to comma-separated string for --tags argument
let tags_arg = self.tags.join(",");
Expand Down
22 changes: 22 additions & 0 deletions influxdb3/tests/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -417,6 +418,27 @@ impl TestServer {
.await
}

pub async fn api_v3_create_table(
&self,
database: &str,
table: &str,
tags: Vec<String>,
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)],
Expand Down
28 changes: 28 additions & 0 deletions influxdb3/tests/server/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
@@ -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 |
+---------------+--------------------+----------------------------+------------+
7 changes: 5 additions & 2 deletions influxdb3_server/src/query_executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,11 +639,14 @@ impl SchemaProvider for Database {
}

fn table_names(&self) -> Vec<String> {
self.db_schema
let mut names = self
.db_schema
.table_names()
.iter()
.map(|t| t.to_string())
.collect()
.collect::<Vec<_>>();
names.sort();
names
}

async fn table(
Expand Down