Skip to content

Commit

Permalink
[BugFix] Fix ip string as double type in csv files()
Browse files Browse the repository at this point in the history
Signed-off-by: wyb <[email protected]>
  • Loading branch information
wyb committed Jan 16, 2025
1 parent e9f711c commit 3aab5a2
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
8 changes: 8 additions & 0 deletions be/src/util/string_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,14 @@ inline T StringParser::string_to_float_internal(const char* s, int len, ParseRes
auto res = fast_float::from_chars(s + i, s + j + 1, val);

if (LIKELY(res.ec == std::errc())) {
// 'res.ptr' is set to point right after the parsed number.
// if there are some chars left, treate it failure.
// for example,
// '10.11.12.13' is parsed as 10.11, res.ptr is '.12.13', and it is invalid.
if (res.ptr != s + j + 1) {
*result = PARSE_FAILURE;
return 0;
}
if (UNLIKELY(val == std::numeric_limits<T>::infinity())) {
*result = PARSE_OVERFLOW;
} else {
Expand Down
2 changes: 2 additions & 0 deletions be/test/util/string_parser_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,8 @@ TEST(StringToFloat, Basic) {
test_all_float_variants("in finity", StringParser::PARSE_FAILURE);
test_all_float_variants("na", StringParser::PARSE_FAILURE);
test_all_float_variants("ThisIsANaN", StringParser::PARSE_FAILURE);
test_all_float_variants("10.1.2.3", StringParser::PARSE_FAILURE);
test_all_float_variants("10.1 max", StringParser::PARSE_FAILURE);
}

TEST(StringToFloat, InvalidLeadingTrailing) {
Expand Down
28 changes: 28 additions & 0 deletions test/sql/test_files/R/test_csv_ip
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- name: test_csv_ip

create database db_${uuid0};
use db_${uuid0};

shell: ossutil64 mkdir oss://${oss_bucket}/test_files/csv_format/${uuid0} >/dev/null || echo "exit 0" >/dev/null

shell: ossutil64 cp --force ./sql/test_files/csv_format/ip.csv oss://${oss_bucket}/test_files/csv_format/${uuid0}/ | grep -Pv "(average|elapsed)"
-- result:
0

Succeed: Total num: 1, size: 14. OK num: 1(upload 1 files).
-- !result


select * from files("path" = "oss://${oss_bucket}/test_files/csv_format/${uuid0}/*", "format" = "csv", "csv.column_separator" = "|", "csv.row_delimiter" = "\n");
-- result:
1 10.11.12.13
-- !result

desc files("path" = "oss://${oss_bucket}/test_files/csv_format/${uuid0}/*", "format" = "csv", "csv.column_separator" = "|", "csv.row_delimiter" = "\n");
-- result:
$1 bigint YES
$2 varchar(1048576) YES
-- !result


shell: ossutil64 rm -rf oss://${oss_bucket}/test_files/csv_format/${uuid0}/ > /dev/null
12 changes: 12 additions & 0 deletions test/sql/test_files/T/test_csv_ip
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- name: test_csv_ip

create database db_${uuid0};
use db_${uuid0};

shell: ossutil64 mkdir oss://${oss_bucket}/test_files/csv_format/${uuid0} >/dev/null || echo "exit 0" >/dev/null
shell: ossutil64 cp --force ./sql/test_files/csv_format/ip.csv oss://${oss_bucket}/test_files/csv_format/${uuid0}/ | grep -Pv "(average|elapsed)"

select * from files("path" = "oss://${oss_bucket}/test_files/csv_format/${uuid0}/*", "format" = "csv", "csv.column_separator" = "|", "csv.row_delimiter" = "\n");
desc files("path" = "oss://${oss_bucket}/test_files/csv_format/${uuid0}/*", "format" = "csv", "csv.column_separator" = "|", "csv.row_delimiter" = "\n");

shell: ossutil64 rm -rf oss://${oss_bucket}/test_files/csv_format/${uuid0}/ > /dev/null
1 change: 1 addition & 0 deletions test/sql/test_files/csv_format/ip.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1|10.11.12.13

0 comments on commit 3aab5a2

Please sign in to comment.