Skip to content

Commit

Permalink
chore: polish error message. (#14737)
Browse files Browse the repository at this point in the history
  • Loading branch information
youngsofun authored Feb 26, 2024
1 parent 16b105e commit 451d463
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/common/storage/src/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,14 @@ pub enum FileParseError {
column_type: String,
},
#[error(
"Empty value for column {column_index} ({column_name} {column_type}), when option empty_field_as = {empty_field_as}"
"Encountered an empty value for column {column_index} (`{column_name}` of type {column_type}), with the FILE_FORMAT option `EMPTY_FIELD_AS={empty_field_as}`. To resolve this, please consider {remedy}"
)]
ColumnEmptyError {
column_index: usize,
column_name: String,
column_type: String,
empty_field_as: String,
remedy: String,
},
#[error(
"Invalid value '{column_data}' for column {column_index} ({column_name} {column_type}): {size_remained} bytes remained, next_char at {error_pos} is {next_char}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ impl InputFormatCSV {
column_name: field.name().to_owned(),
column_type: field.data_type.to_string(),
empty_field_as: empty_filed_as.to_string(),
remedy: format!(
"one of the following options: 1. Modify the `{}` column to allow NULL values. 2. Set `EMPTY_FIELD_AS = FIELD_DEFAULT`.",
field.name()
),
});
}
builder.push_default();
Expand All @@ -93,6 +97,8 @@ impl InputFormatCSV {
column_name: field.name().to_owned(),
column_type: field.data_type.to_string(),
empty_field_as: empty_filed_as.to_string(),
remedy: "Set EMPTY_FIELD_AS to FIELD_DEFAULT or NULL."
.to_string(),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ impl CsvDecoder {
column_name: field.name().to_owned(),
column_type: field.data_type.to_string(),
empty_field_as: empty_filed_as.to_string(),
remedy: format!(
"one of the following options: 1. Modify the `{}` column to allow NULL values. 2. Set EMPTY_FIELD_AS to FIELD_DEFAULT.",
field.name()
),
});
}
builder.push_default();
Expand All @@ -87,6 +91,8 @@ impl CsvDecoder {
column_name: field.name().to_owned(),
column_type: field.data_type.to_string(),
empty_field_as: empty_filed_as.to_string(),
remedy: "Set EMPTY_FIELD_AS to FIELD_DEFAULT or NULL."
.to_string(),
});
}

Expand Down
20 changes: 10 additions & 10 deletions tests/sqllogictests/suites/stage/formats/csv/csv_empty.test
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ truncate table ints
query TIITI
copy into ints from @data/csv/empty/ file_format = (type = CSV) force=true on_error=continue
----
csv/empty/empty1.csv 0 1 Empty value for column 3 (c3 Int32), when option empty_field_as = NULL 1
csv/empty/empty2.csv 0 1 Empty value for column 3 (c3 Int32), when option empty_field_as = NULL 1
csv/empty/empty1.csv 0 1 Encountered an empty value for column 3 (`c3` of type Int32), with the FILE_FORMAT option `EMPTY_FIELD_AS=NULL`. To resolve this, please consider one of the following options: 1. Modify the `c3` column to allow NULL values. 2. Set EMPTY_FIELD_AS to FIELD_DEFAULT. 1
csv/empty/empty2.csv 0 1 Encountered an empty value for column 3 (`c3` of type Int32), with the FILE_FORMAT option `EMPTY_FIELD_AS=NULL`. To resolve this, please consider one of the following options: 1. Modify the `c3` column to allow NULL values. 2. Set EMPTY_FIELD_AS to FIELD_DEFAULT. 1
csv/empty/empty3.csv 1 0 NULL NULL
csv/empty/empty4.csv 0 1 Empty value for column 3 (c3 Int32), when option empty_field_as = NULL 1
csv/empty/empty4.csv 0 1 Encountered an empty value for column 3 (`c3` of type Int32), with the FILE_FORMAT option `EMPTY_FIELD_AS=NULL`. To resolve this, please consider one of the following options: 1. Modify the `c3` column to allow NULL values. 2. Set EMPTY_FIELD_AS to FIELD_DEFAULT. 1

query
select * from ints order by c0,c1,c2,c3,c4;
Expand All @@ -57,10 +57,10 @@ truncate table ints
query TIITI
copy into ints from @data/csv/empty/ file_format = (type = CSV empty_field_as = STRING) force=true on_error=continue
----
csv/empty/empty1.csv 0 1 Empty value for column 1 (c1 Int32 NULL), when option empty_field_as = STRING 1
csv/empty/empty2.csv 0 1 Empty value for column 3 (c3 Int32), when option empty_field_as = STRING 1
csv/empty/empty1.csv 0 1 Encountered an empty value for column 1 (`c1` of type Int32 NULL), with the FILE_FORMAT option `EMPTY_FIELD_AS=STRING`. To resolve this, please consider Set EMPTY_FIELD_AS to FIELD_DEFAULT or NULL. 1
csv/empty/empty2.csv 0 1 Encountered an empty value for column 3 (`c3` of type Int32), with the FILE_FORMAT option `EMPTY_FIELD_AS=STRING`. To resolve this, please consider Set EMPTY_FIELD_AS to FIELD_DEFAULT or NULL. 1
csv/empty/empty3.csv 1 0 NULL NULL
csv/empty/empty4.csv 0 1 Empty value for column 0 (c0 Int32 NULL), when option empty_field_as = STRING 1
csv/empty/empty4.csv 0 1 Encountered an empty value for column 0 (`c0` of type Int32 NULL), with the FILE_FORMAT option `EMPTY_FIELD_AS=STRING`. To resolve this, please consider Set EMPTY_FIELD_AS to FIELD_DEFAULT or NULL. 1

query
select * from ints order by c0,c1,c2,c3,c4;
Expand Down Expand Up @@ -96,10 +96,10 @@ truncate table strings
query TIITI
copy into strings from @data/csv/empty/ file_format = (type = CSV) force=true on_error=continue
----
csv/empty/empty1.csv 0 1 Empty value for column 3 (c3 String), when option empty_field_as = NULL 1
csv/empty/empty2.csv 0 1 Empty value for column 3 (c3 String), when option empty_field_as = NULL 1
csv/empty/empty1.csv 0 1 Encountered an empty value for column 3 (`c3` of type String), with the FILE_FORMAT option `EMPTY_FIELD_AS=NULL`. To resolve this, please consider one of the following options: 1. Modify the `c3` column to allow NULL values. 2. Set EMPTY_FIELD_AS to FIELD_DEFAULT. 1
csv/empty/empty2.csv 0 1 Encountered an empty value for column 3 (`c3` of type String), with the FILE_FORMAT option `EMPTY_FIELD_AS=NULL`. To resolve this, please consider one of the following options: 1. Modify the `c3` column to allow NULL values. 2. Set EMPTY_FIELD_AS to FIELD_DEFAULT. 1
csv/empty/empty3.csv 1 0 NULL NULL
csv/empty/empty4.csv 0 1 Empty value for column 3 (c3 String), when option empty_field_as = NULL 1
csv/empty/empty4.csv 0 1 Encountered an empty value for column 3 (`c3` of type String), with the FILE_FORMAT option `EMPTY_FIELD_AS=NULL`. To resolve this, please consider one of the following options: 1. Modify the `c3` column to allow NULL values. 2. Set EMPTY_FIELD_AS to FIELD_DEFAULT. 1

query
select * from strings order by c0,c1,c2,c3,c4;
Expand All @@ -115,7 +115,7 @@ copy into strings from @data/csv/empty/ file_format = (type = CSV empty_field_as
csv/empty/empty1.csv 1 0 NULL NULL
csv/empty/empty2.csv 1 0 NULL NULL
csv/empty/empty3.csv 1 0 NULL NULL
csv/empty/empty4.csv 0 1 Empty value for column 0 (c0 Int32 NULL), when option empty_field_as = STRING 1
csv/empty/empty4.csv 0 1 Encountered an empty value for column 0 (`c0` of type Int32 NULL), with the FILE_FORMAT option `EMPTY_FIELD_AS=STRING`. To resolve this, please consider Set EMPTY_FIELD_AS to FIELD_DEFAULT or NULL. 1

query
select * from strings order by c0,c1,c2,c3,c4;
Expand Down

0 comments on commit 451d463

Please sign in to comment.