Skip to content

Commit cb10b17

Browse files
committed
feat: support SHOW queries for /query API
* SHOW DATABASES * SHOW RETENTION POLICIES Includes tests for the lower level implementation of these interfaces from iox_query
1 parent 4e01bb7 commit cb10b17

16 files changed

+718
-920
lines changed

Cargo.lock

Lines changed: 264 additions & 886 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ criterion = { version = "0.5", features = ["html_reports"] }
8484
crossbeam-channel = "0.5.11"
8585
csv = "1.3.0"
8686
# See https://github.com/influxdata/arrow-datafusion/pull/73 for contents
87-
datafusion = { git = "https://github.com/influxdata/arrow-datafusion.git", rev = "a9cf9aca9ebf0d6c04e0861d2baebffa0ba77dbc" }
88-
datafusion-proto = { git = "https://github.com/influxdata/arrow-datafusion.git", rev = "a9cf9aca9ebf0d6c04e0861d2baebffa0ba77dbc" }
87+
datafusion = { git = "https://github.com/influxdata/arrow-datafusion.git", rev = "ee81b1cc652bde6c131973d091b178836692112d" }
88+
datafusion-proto = { git = "https://github.com/influxdata/arrow-datafusion.git", rev = "ee81b1cc652bde6c131973d091b178836692112d" }
8989
dashmap = "6.1.0"
9090
dotenvy = "0.15.7"
9191
flate2 = "1.0.27"
@@ -112,25 +112,25 @@ mockito = { version = "1.4.0", default-features = false }
112112
mockall = { version = "0.13.0" }
113113
non-empty-string = "0.2.5"
114114
num_cpus = "1.16.0"
115-
object_store = { version = "0.12.3", features = ["aws", "azure", "gcp"] }
115+
object_store = { version = "0.12.4", features = ["aws", "azure", "gcp"] }
116116
parking_lot = { version = "0.12.1", features = ["serde"] }
117117
paste = "1.0.15"
118118
parquet = {version = "55", features = ["object_store"]}
119-
pbjson = "0.6.0"
120-
pbjson-build = "0.6.2"
121-
pbjson-types = "0.6.0"
119+
pbjson = "0.8"
120+
pbjson-build = "0.8"
121+
pbjson-types = "0.7"
122122
pin-project-lite = "0.2"
123123
pretty_assertions = { version = "1.4.0", features = ["unstable"] }
124-
prost = "0.12.6"
125-
prost-build = "0.12.6"
126-
prost-types = "0.12.6"
124+
prost = "0.13"
125+
prost-build = "0.13"
126+
prost-types = "0.13"
127127
proptest = { version = "1", default-features = false, features = ["std"] }
128128
pyo3 = { version = "0.24.1", features = ["experimental-async"]}
129129
rand = "0.8.5"
130130
rcgen = "0.13.2"
131131
regex = "1.11.1"
132-
reqwest = { version = "0.11.27", default-features = false, features = ["rustls-tls", "stream", "json"] }
133-
rstest = "0.18"
132+
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls", "stream", "json"] }
133+
rstest = "0.26"
134134
rustls = { version = "0.23", default-features = false, features = ["logging", "ring", "std", "tls12"] }
135135
rustls-webpki = { version = "0.103", default-features = false, features = ["ring", "std"] }
136136
rustls-pemfile = "2.2.0"
@@ -157,7 +157,7 @@ tonic = { version = "0.12.3", features = ["tls", "tls-roots"] }
157157
tonic-build = "0.12.3"
158158
tonic-health = "0.12.3"
159159
tonic-reflection = "0.12.3"
160-
tower = "0.4.13"
160+
tower = "0.5"
161161
twox-hash = "2.1.0"
162162
unicode-segmentation = "1.11.0"
163163
url = "2.5.0"

influxdb3/src/commands/serve.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,7 @@ pub async fn command(config: Config, user_params: HashMap<String, String>) -> Re
10401040
let write_buffer: Arc<dyn WriteBuffer> = write_buffer_impl;
10411041

10421042
let common_state = CommonServerState::new(
1043+
Arc::clone(&catalog),
10431044
Arc::clone(&metrics),
10441045
trace_exporter,
10451046
trace_header_parser,

influxdb3/tests/server/mod.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -761,13 +761,7 @@ impl Drop for TestServer {
761761
}
762762

763763
impl TestServer {
764-
/// Write some line protocol to the server
765-
pub async fn write_lp_to_db(
766-
&self,
767-
database: &str,
768-
lp: impl ToString,
769-
precision: Precision,
770-
) -> Result<(), influxdb3_client::Error> {
764+
fn maybe_authorized_client(&self) -> influxdb3_client::Client {
771765
let mut client = influxdb3_client::Client::new(
772766
self.client_addr(),
773767
Some("../testing-certs/rootCA.pem".into()),
@@ -776,6 +770,17 @@ impl TestServer {
776770
if let Some(token) = &self.auth_token {
777771
client = client.with_auth_token(token);
778772
}
773+
client
774+
}
775+
776+
/// Write some line protocol to the server
777+
pub async fn write_lp_to_db(
778+
&self,
779+
database: &str,
780+
lp: impl ToString,
781+
precision: Precision,
782+
) -> Result<(), influxdb3_client::Error> {
783+
let client = self.maybe_authorized_client();
779784
client
780785
.api_v3_write_lp(database)
781786
.body(lp.to_string())
@@ -784,21 +789,25 @@ impl TestServer {
784789
.await
785790
}
786791

792+
pub async fn api_v3_create_database(
793+
&self,
794+
database: &str,
795+
retention_period: Option<Duration>,
796+
) -> Result<(), influxdb3_client::Error> {
797+
let client = self.maybe_authorized_client();
798+
client
799+
.api_v3_configure_db_create(database, retention_period)
800+
.await
801+
}
802+
787803
pub async fn api_v3_create_table(
788804
&self,
789805
database: &str,
790806
table: &str,
791807
tags: Vec<String>,
792808
fields: Vec<(String, FieldType)>,
793809
) -> Result<(), influxdb3_client::Error> {
794-
let mut client = influxdb3_client::Client::new(
795-
self.client_addr(),
796-
Some("../testing-certs/rootCA.pem".into()),
797-
)
798-
.unwrap();
799-
if let Some(token) = &self.auth_token {
800-
client = client.with_auth_token(token);
801-
}
810+
let client = self.maybe_authorized_client();
802811

803812
client
804813
.api_v3_configure_table_create(database, table, tags, fields)

influxdb3/tests/server/query.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use core::str;
2+
use std::time::Duration;
23

34
use crate::server::TestServer;
45
use futures::StreamExt;
@@ -1799,6 +1800,69 @@ async fn api_v1_query_group_by_with_nulls() {
17991800
}
18001801
}
18011802

1803+
#[tokio::test]
1804+
async fn api_v1_query_api_show_databases_and_retention_policies() {
1805+
let server = TestServer::spawn().await;
1806+
1807+
server.api_v3_create_database("foo", None).await.unwrap();
1808+
server
1809+
.api_v3_create_database("bar", Some(Duration::from_secs(30 * 24 * 60 * 60)))
1810+
.await
1811+
.unwrap();
1812+
1813+
let response = server
1814+
.api_v1_query(&[("q", "SHOW DATABASES")], None)
1815+
.await
1816+
.text()
1817+
.await
1818+
.unwrap();
1819+
1820+
insta::with_settings!({
1821+
description => "SHOW DATABASES",
1822+
}, {
1823+
insta::assert_snapshot!(response);
1824+
});
1825+
1826+
let response = server
1827+
.api_v1_query(&[("q", "SHOW RETENTION POLICIES"), ("db", "foo")], None)
1828+
.await
1829+
.text()
1830+
.await
1831+
.unwrap();
1832+
1833+
insta::with_settings!({
1834+
description => "SHOW RETENTION POLICIES on foo db",
1835+
}, {
1836+
insta::assert_snapshot!(response);
1837+
});
1838+
1839+
let response = server
1840+
.api_v1_query(&[("q", "SHOW RETENTION POLICIES"), ("db", "bar")], None)
1841+
.await
1842+
.text()
1843+
.await
1844+
.unwrap();
1845+
1846+
insta::with_settings!({
1847+
description => "SHOW RETENTION POLICIES on bar db",
1848+
}, {
1849+
insta::assert_snapshot!(response);
1850+
});
1851+
1852+
let response = server
1853+
.api_v1_query(&[("q", "SHOW RETENTION POLICIES"), ("db", "frodo")], None)
1854+
.await
1855+
.text()
1856+
.await
1857+
.unwrap();
1858+
1859+
insta::with_settings!({
1860+
description => "SHOW RETENTION POLICIES on non-existent db",
1861+
}, {
1862+
insta::assert_snapshot!(response);
1863+
});
1864+
}
1865+
18021866
#[tokio::test]
18031867
async fn api_v3_query_sql_distinct_cache() {
18041868
let server = TestServer::spawn().await;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
source: influxdb3/tests/server/query.rs
3+
description: SHOW DATABASES
4+
expression: response
5+
---
6+
{"results":[{"statement_id":0,"series":[{"name":"databases","columns":["name"],"values":[["_internal"],["foo"],["bar"]]}]}]}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
source: influxdb3/tests/server/query.rs
3+
description: SHOW RETENTION POLICIES on foo db
4+
expression: response
5+
---
6+
{"results":[{"statement_id":0,"series":[{"name":"retention_policies","columns":["name","duration","default"],"values":[["foo",null,true]]}]}]}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
source: influxdb3/tests/server/query.rs
3+
description: SHOW RETENTION POLICIES on bar db
4+
expression: response
5+
---
6+
{"results":[{"statement_id":0,"series":[{"name":"retention_policies","columns":["name","duration","default"],"values":[["bar","30days",true]]}]}]}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
source: influxdb3/tests/server/query.rs
3+
description: SHOW RETENTION POLICIES on non-existent db
4+
expression: response
5+
---
6+
{"results":[{"statement_id":0,"error":"datafusion error: Error during planning: database not found: frodo"}]}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
source: influxdb3/tests/server/query.rs
3+
description: SHOW DATABASES
4+
expression: response
5+
---
6+
{"results":[{"statement_id":0,"series":[{"name":"databases","columns":["name"],"values":[["_internal"],["foo"],["bar"]]}]}]}

0 commit comments

Comments
 (0)