Skip to content

Commit 6abaaee

Browse files
authored
add integration tests (#784)
1 parent 2445bb1 commit 6abaaee

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

integration_tests/cases/env/local/influxql/basic.result

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ SELECT * FROM "h2o_feet";
2929

3030
{"results":[{"statement_id":0,"series":[{"name":"h2o_feet","columns":["time","level_description","location","water_level"],"values":[[1439827200000,"below 3 feet","santa_monica",2.064],[1439827200000,"between 6 and 9 feet","coyote_creek",8.12],[1439827560000,"below 3 feet","santa_monica",2.116],[1439827560000,"between 6 and 9 feet","coyote_creek",8.005],[1439827620000,"below 3 feet","santa_monica",2.028],[1439827620000,"between 6 and 9 feet","coyote_creek",7.887]]}]}]}
3131

32+
-- SQLNESS ARG protocol=influxql method=get
33+
SELECT * FROM "h2o_feet";
34+
35+
{"results":[{"statement_id":0,"series":[{"name":"h2o_feet","columns":["time","level_description","location","water_level"],"values":[[1439827200000,"below 3 feet","santa_monica",2.064],[1439827200000,"between 6 and 9 feet","coyote_creek",8.12],[1439827560000,"below 3 feet","santa_monica",2.116],[1439827560000,"between 6 and 9 feet","coyote_creek",8.005],[1439827620000,"below 3 feet","santa_monica",2.028],[1439827620000,"between 6 and 9 feet","coyote_creek",7.887]]}]}]}
36+
3237
-- SQLNESS ARG protocol=influxql
3338
SELECT "level_description", location, water_level FROM "h2o_feet" where location = 'santa_monica';
3439

integration_tests/cases/env/local/influxql/basic.sql

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ INSERT INTO h2o_feet(time, level_description, location, water_level)
2929
-- SQLNESS ARG protocol=influxql
3030
SELECT * FROM "h2o_feet";
3131

32+
-- SQLNESS ARG protocol=influxql method=get
33+
SELECT * FROM "h2o_feet";
34+
3235
-- SQLNESS ARG protocol=influxql
3336
SELECT "level_description", location, water_level FROM "h2o_feet" where location = 'santa_monica';
3437

integration_tests/src/database.rs

+20-11
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use ceresdb_client::{
1616
model::sql_query::{display::CsvFormatter, Request},
1717
RpcContext,
1818
};
19-
use reqwest::ClientBuilder;
19+
use reqwest::{ClientBuilder, Url};
2020
use sql::{
2121
ast::{Statement, TableName},
2222
parser::Parser,
@@ -212,7 +212,7 @@ impl<T: Send + Sync> Database for CeresDB<T> {
212212
Protocol::Sql => Self::execute_sql(query, self.db_client.clone()).await,
213213
Protocol::InfluxQL => {
214214
let http_client = self.http_client.clone();
215-
Self::execute_influxql(query, http_client).await
215+
Self::execute_influxql(query, http_client, context.context).await
216216
}
217217
}
218218
}
@@ -244,16 +244,25 @@ impl<T: Backend> CeresDB<T> {
244244
}
245245

246246
impl<T> CeresDB<T> {
247-
async fn execute_influxql(query: String, http_client: HttpClient) -> Box<dyn Display> {
248-
let query = format!("q={query}");
247+
async fn execute_influxql(
248+
query: String,
249+
http_client: HttpClient,
250+
params: HashMap<String, String>,
251+
) -> Box<dyn Display> {
249252
let url = format!("http://{}/influxdb/v1/query", http_client.endpoint);
250-
let resp = http_client
251-
.client
252-
.post(url)
253-
.body(query)
254-
.send()
255-
.await
256-
.unwrap();
253+
let resp = match params.get("method") {
254+
Some(v) if v == "get" => {
255+
let url = Url::parse_with_params(&url, &[("q", query)]).unwrap();
256+
http_client.client.get(url).send().await.unwrap()
257+
}
258+
_ => http_client
259+
.client
260+
.post(url)
261+
.form(&[("q", query)])
262+
.send()
263+
.await
264+
.unwrap(),
265+
};
257266
let query_res = match resp.text().await {
258267
Ok(text) => text,
259268
Err(e) => format!("Failed to do influxql query, err:{e:?}"),

0 commit comments

Comments
 (0)