mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 09:32:06 +00:00
Merge pull request #48133 from ClickHouse/allow-to-skip-errors-of-enums
Allow skipping errors related to unknown enum values in row input formats
This commit is contained in:
commit
13761fe891
@ -649,6 +649,7 @@
|
||||
M(678, IO_URING_INIT_FAILED) \
|
||||
M(679, IO_URING_SUBMIT_ERROR) \
|
||||
M(690, MIXED_ACCESS_PARAMETER_TYPES) \
|
||||
M(691, UNKNOWN_ELEMENT_OF_ENUM) \
|
||||
\
|
||||
M(999, KEEPER_EXCEPTION) \
|
||||
M(1000, POCO_EXCEPTION) \
|
||||
|
@ -10,7 +10,7 @@ namespace ErrorCodes
|
||||
{
|
||||
extern const int SYNTAX_ERROR;
|
||||
extern const int EMPTY_DATA_PASSED;
|
||||
extern const int BAD_ARGUMENTS;
|
||||
extern const int UNKNOWN_ELEMENT_OF_ENUM;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@ -69,7 +69,7 @@ T EnumValues<T>::getValue(StringRef field_name, bool try_treat_as_id) const
|
||||
}
|
||||
auto hints = this->getHints(field_name.toString());
|
||||
auto hints_string = !hints.empty() ? ", maybe you meant: " + toString(hints) : "";
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Unknown element '{}' for enum{}", field_name.toString(), hints_string);
|
||||
throw Exception(ErrorCodes::UNKNOWN_ELEMENT_OF_ENUM, "Unknown element '{}' for enum{}", field_name.toString(), hints_string);
|
||||
}
|
||||
return it->getMapped();
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ namespace ErrorCodes
|
||||
extern const int CANNOT_PARSE_DOMAIN_VALUE_FROM_STRING;
|
||||
extern const int CANNOT_PARSE_IPV4;
|
||||
extern const int CANNOT_PARSE_IPV6;
|
||||
extern const int UNKNOWN_ELEMENT_OF_ENUM;
|
||||
}
|
||||
|
||||
|
||||
@ -48,7 +49,8 @@ bool isParseError(int code)
|
||||
|| code == ErrorCodes::INCORRECT_DATA /// For some ReadHelpers
|
||||
|| code == ErrorCodes::CANNOT_PARSE_DOMAIN_VALUE_FROM_STRING
|
||||
|| code == ErrorCodes::CANNOT_PARSE_IPV4
|
||||
|| code == ErrorCodes::CANNOT_PARSE_IPV6;
|
||||
|| code == ErrorCodes::CANNOT_PARSE_IPV6
|
||||
|| code == ErrorCodes::UNKNOWN_ELEMENT_OF_ENUM;
|
||||
}
|
||||
|
||||
IRowInputFormat::IRowInputFormat(Block header, ReadBuffer & in_, Params params_)
|
||||
|
@ -12,6 +12,6 @@ INSERT INTO cast_enums SELECT 2 AS type, toDate('2017-01-01') AS date, number AS
|
||||
|
||||
SELECT type, date, id FROM cast_enums ORDER BY type, id;
|
||||
|
||||
INSERT INTO cast_enums VALUES ('wrong_value', '2017-01-02', 7); -- { clientError 36 }
|
||||
INSERT INTO cast_enums VALUES ('wrong_value', '2017-01-02', 7); -- { clientError 691 }
|
||||
|
||||
DROP TABLE IF EXISTS cast_enums;
|
||||
|
@ -3,4 +3,4 @@ INSERT INTO enum VALUES ('hello');
|
||||
|
||||
SELECT count() FROM enum WHERE x = 'hello';
|
||||
SELECT count() FROM enum WHERE x = 'world';
|
||||
SELECT count() FROM enum WHERE x = 'xyz'; -- { serverError 36 }
|
||||
SELECT count() FROM enum WHERE x = 'xyz'; -- { serverError 691 }
|
||||
|
@ -5,8 +5,8 @@ SELECT CAST(CAST(NULL AS Nullable(String)) AS Nullable(Enum8('Hello' = 1)));
|
||||
SELECT CAST(CAST(NULL AS Nullable(FixedString(1))) AS Nullable(Enum8('Hello' = 1)));
|
||||
|
||||
-- empty string still not acceptable
|
||||
SELECT CAST(CAST('' AS Nullable(String)) AS Nullable(Enum8('Hello' = 1))); -- { serverError 36 }
|
||||
SELECT CAST(CAST('' AS Nullable(FixedString(1))) AS Nullable(Enum8('Hello' = 1))); -- { serverError 36 }
|
||||
SELECT CAST(CAST('' AS Nullable(String)) AS Nullable(Enum8('Hello' = 1))); -- { serverError 691 }
|
||||
SELECT CAST(CAST('' AS Nullable(FixedString(1))) AS Nullable(Enum8('Hello' = 1))); -- { serverError 691 }
|
||||
|
||||
-- non-Nullable Enum() still not acceptable
|
||||
SELECT CAST(CAST(NULL AS Nullable(String)) AS Enum8('Hello' = 1)); -- { serverError 349 }
|
||||
|
@ -0,0 +1,2 @@
|
||||
Hello
|
||||
World
|
15
tests/queries/0_stateless/02702_allow_skip_errors_enum.sh
Executable file
15
tests/queries/0_stateless/02702_allow_skip_errors_enum.sh
Executable file
@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
# shellcheck source=../shell_config.sh
|
||||
. "$CURDIR"/../shell_config.sh
|
||||
|
||||
$CLICKHOUSE_CLIENT --multiquery --query "DROP TABLE IF EXISTS t; CREATE TABLE t (x Enum('Hello' = 1, 'World' = 2)) ENGINE = Memory;"
|
||||
$CLICKHOUSE_CLIENT --input_format_allow_errors_num 1 --query "INSERT INTO t FORMAT CSV" <<END
|
||||
Hello
|
||||
Goodbye
|
||||
World
|
||||
END
|
||||
|
||||
$CLICKHOUSE_CLIENT --query "SELECT x FROM t ORDER BY x"
|
||||
$CLICKHOUSE_CLIENT --query "DROP TABLE t"
|
Loading…
Reference in New Issue
Block a user