Skip to content

Commit

Permalink
chore: change error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
killme2008 committed Sep 13, 2023
1 parent 60bdf96 commit f94337a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 24 deletions.
19 changes: 13 additions & 6 deletions src/frontend/src/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,19 @@ fn validate_column_count_match(requests: &RowDeleteRequests) -> Result<()> {
for request in &requests.deletes {
let rows = request.rows.as_ref().unwrap();
let column_count = rows.schema.len();
ensure!(
rows.rows.iter().all(|r| r.values.len() == column_count),
InvalidDeleteRequestSnafu {
reason: "column count mismatch"
}
)
rows.rows.iter().try_for_each(|r| {
ensure!(
r.values.len() == column_count,
InvalidDeleteRequestSnafu {
reason: format!(
"column count mismatch, columns: {}, values: {}",
column_count,
r.values.len()
)
}
);
Ok(())
})?;
}
Ok(())
}
19 changes: 13 additions & 6 deletions src/frontend/src/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,19 @@ fn validate_column_count_match(requests: &RowInsertRequests) -> Result<()> {
for request in &requests.inserts {
let rows = request.rows.as_ref().unwrap();
let column_count = rows.schema.len();
ensure!(
rows.rows.iter().all(|r| r.values.len() == column_count),
InvalidInsertRequestSnafu {
reason: "column count mismatch"
}
)
rows.rows.iter().try_for_each(|r| {
ensure!(
r.values.len() == column_count,
InvalidInsertRequestSnafu {
reason: format!(
"column count mismatch, columns: {}, values: {}",
column_count,
r.values.len()
)
}
);
Ok(())
})?;
}
Ok(())
}
Expand Down
19 changes: 13 additions & 6 deletions src/frontend/src/req_convert/insert/stmt_to_region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,19 @@ impl<'a> StatementToRegion<'a> {
let sql_rows = stmt.values_body().context(MissingInsertBodySnafu)?;
let row_count = sql_rows.len();

ensure!(
sql_rows.iter().all(|row| row.len() == column_count),
InvalidSqlSnafu {
err_msg: "column count mismatch"
}
);
sql_rows.iter().try_for_each(|r| {
ensure!(
r.len() == column_count,
InvalidSqlSnafu {
err_msg: format!(
"column count mismatch, columns: {}, values: {}",
column_count,
r.len()
)
}
);
Ok(())
})?;

let mut schema = Vec::with_capacity(column_count);
let mut rows = vec![
Expand Down
4 changes: 2 additions & 2 deletions tests/cases/standalone/common/insert/insert_default.result
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ Affected Rows: 0

INSERT INTO test1 VALUES (DEFAULT);

Error: 1004(InvalidArguments), Columns and values number mismatch, columns: 3, values: 1
Error: 1004(InvalidArguments), Invalid SQL, error: column count mismatch, columns: 3, values: 1

INSERT INTO test1 VALUES (DEFAULT, DEFAULT, DEFAULT);

Error: 1004(InvalidArguments), No valid default value can be built automatically, column: j

INSERT INTO test1 VALUES (DEFAULT, DEFAULT, DEFAULT, DEFAULT);

Error: 1004(InvalidArguments), Columns and values number mismatch, columns: 3, values: 4
Error: 1004(InvalidArguments), Invalid SQL, error: column count mismatch, columns: 3, values: 4

INSERT INTO test1 VALUES (DEFAULT, 1, DEFAULT), (default, 2, default), (DeFaUlT, 3, DeFaUlT), (dEfAuLt, 4, dEfAuLt);

Expand Down
8 changes: 4 additions & 4 deletions tests/cases/standalone/common/insert/insert_invalid.result
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ Affected Rows: 1

INSERT INTO a VALUES (1);

Error: 1004(InvalidArguments), Columns and values number mismatch, columns: 2, values: 1
Error: 1004(InvalidArguments), Invalid SQL, error: column count mismatch, columns: 2, values: 1

INSERT INTO a VALUES (1,2,3);

Error: 1004(InvalidArguments), Columns and values number mismatch, columns: 2, values: 3
Error: 1004(InvalidArguments), Invalid SQL, error: column count mismatch, columns: 2, values: 3

INSERT INTO a VALUES (1,2),(3);

Error: 1004(InvalidArguments), Columns and values number mismatch, columns: 2, values: 1
Error: 1004(InvalidArguments), Invalid SQL, error: column count mismatch, columns: 2, values: 1

INSERT INTO a VALUES (1,2),(3,4,5);

Error: 1004(InvalidArguments), Columns and values number mismatch, columns: 2, values: 3
Error: 1004(InvalidArguments), Invalid SQL, error: column count mismatch, columns: 2, values: 3

DROP TABLE strings;

Expand Down

0 comments on commit f94337a

Please sign in to comment.