Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BugFix] Fix promote ip string as double type in csv files() #55173

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 as failure.
// for example,
// '10.11.12.13' is parsed as 10.11, res.ptr is '.12.13', so 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
Loading