mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-18 08:44:07 +00:00
fix(servers): report the dryrun row limit instead of "data is required" (#10491)
* test(servers): expect the dryrun row limit in the error message Signed-off-by: dayan02dev <pawarudayan92@gmail.com> * fix(servers): report the dryrun row limit instead of "data is required" Signed-off-by: dayan02dev <pawarudayan92@gmail.com> --------- Signed-off-by: dayan02dev <pawarudayan92@gmail.com>
This commit is contained in:
@@ -571,12 +571,15 @@ fn check_pipeline_name_exists(pipeline_name: Option<String>) -> Result<String> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Check if the data length less than 10
|
||||
/// The maximum number of rows the pipeline dryrun API accepts.
|
||||
const MAX_DRYRUN_ROWS: usize = 10;
|
||||
|
||||
/// Check that the dryrun data has at most [`MAX_DRYRUN_ROWS`] rows.
|
||||
fn check_data_valid(data_len: usize) -> Result<()> {
|
||||
ensure!(
|
||||
data_len <= 10,
|
||||
data_len <= MAX_DRYRUN_ROWS,
|
||||
InvalidParameterSnafu {
|
||||
reason: "data is required",
|
||||
reason: format!("dryrun data must not exceed {MAX_DRYRUN_ROWS} rows, got {data_len}"),
|
||||
}
|
||||
);
|
||||
Ok(())
|
||||
@@ -1124,6 +1127,17 @@ mod tests {
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_check_data_valid() {
|
||||
assert!(check_data_valid(0).is_ok());
|
||||
assert!(check_data_valid(10).is_ok());
|
||||
let err = check_data_valid(11).unwrap_err();
|
||||
assert_eq!(
|
||||
err.output_msg(),
|
||||
"Invalid request parameter: dryrun data must not exceed 10 rows, got 11"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_transform_ndjson() {
|
||||
let s = "{\"a\": 1}\n{\"b\": 2}";
|
||||
|
||||
@@ -8446,6 +8446,45 @@ transform:
|
||||
.await;
|
||||
assert_eq!(res.status(), StatusCode::BAD_REQUEST);
|
||||
}
|
||||
{
|
||||
// the dryrun API accepts at most 10 rows
|
||||
let rows = (0..11)
|
||||
.map(|i| {
|
||||
json!({
|
||||
"id1": "2436",
|
||||
"id2": "2528",
|
||||
"logger": "INTERACT.MANAGER",
|
||||
"type": "I",
|
||||
"time": "2024-05-25 20:16:37.217",
|
||||
"log": format!("row {i}")
|
||||
})
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let data = Value::Array(rows).to_string();
|
||||
let expected =
|
||||
json!("Invalid request parameter: dryrun data must not exceed 10 rows, got 11");
|
||||
|
||||
let body = json!({"pipeline_name": "test", "data": data});
|
||||
let res = client
|
||||
.post("/v1/pipelines/_dryrun")
|
||||
.header("Content-Type", "application/json")
|
||||
.body(body.to_string())
|
||||
.send()
|
||||
.await;
|
||||
assert_eq!(res.status(), StatusCode::BAD_REQUEST);
|
||||
let body: Value = res.json().await;
|
||||
assert_eq!(body["error"], expected);
|
||||
|
||||
let res = client
|
||||
.post("/v1/pipelines/_dryrun?pipeline_name=test")
|
||||
.header("Content-Type", "application/json")
|
||||
.body(data)
|
||||
.send()
|
||||
.await;
|
||||
assert_eq!(res.status(), StatusCode::BAD_REQUEST);
|
||||
let body: Value = res.json().await;
|
||||
assert_eq!(body["error"], expected);
|
||||
}
|
||||
guard.remove_all().await;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user