Skip to content

Commit

Permalink
chore: change error messages (GreptimeTeam#2379)
Browse files Browse the repository at this point in the history
* chore: change error messages

* chore: remove locaton in table not found error msg
  • Loading branch information
killme2008 authored and paomian committed Oct 19, 2023
1 parent 28df971 commit 9b9193f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 29 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(())
}
7 changes: 2 additions & 5 deletions src/frontend/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,8 @@ pub enum Error {
#[snafu(display("Invalid system table definition: {err_msg}, at {location}"))]
InvalidSystemTableDef { err_msg: String, location: Location },

#[snafu(display("Table not found: '{}', at {location}", table_name))]
TableNotFound {
table_name: String,
location: Location,
},
#[snafu(display("Table not found: {}", table_name))]
TableNotFound { table_name: String },

#[snafu(display("Failed to join task, source: {}", source))]
JoinTask {
Expand Down
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 9b9193f

Please sign in to comment.