Function dictGet check arguments size

This commit is contained in:
Maksim Kita 2022-06-08 17:19:30 +02:00
parent 929ab82024
commit b7152fa2bf
3 changed files with 72 additions and 0 deletions

View File

@ -458,6 +458,8 @@ public:
{
default_cols.emplace_back(result);
}
++current_arguments_index;
}
else
{
@ -465,6 +467,13 @@ public:
default_cols.emplace_back(nullptr);
}
if (current_arguments_index < arguments.size())
throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH,
"Number of arguments for function {} doesn't match: passed {} should be {}",
getName(),
arguments.size(),
current_arguments_index);
auto key_col_with_type = arguments[2];
bool key_is_only_null = key_col_with_type.type->onlyNull();

View File

@ -0,0 +1,4 @@
Value
DefaultValue
Value
DefaultValue

View File

@ -0,0 +1,59 @@
DROP TABLE IF EXISTS dictionary_source_table;
CREATE TABLE dictionary_source_table
(
id UInt64,
value String
) ENGINE=TinyLog;
INSERT INTO dictionary_source_table VALUES (0, 'Value');
DROP DICTIONARY IF EXISTS test_dictionary;
CREATE DICTIONARY test_dictionary
(
id UInt64,
value String
)
PRIMARY KEY id
LAYOUT(FLAT())
SOURCE(CLICKHOUSE(TABLE 'dictionary_source_table'))
LIFETIME(0);
SELECT dictGet('test_dictionary', 'value', 0);
SELECT dictGet('test_dictionary', 'value', 0, 'DefaultValue'); --{serverError 42}
SELECT dictGetOrDefault('test_dictionary', 'value', 1, 'DefaultValue');
SELECT dictGetOrDefault('test_dictionary', 'value', 1, 'DefaultValue', 1); --{serverError 42}
DROP DICTIONARY test_dictionary;
DROP TABLE dictionary_source_table;
CREATE TABLE dictionary_source_table
(
key UInt64,
start UInt64,
end UInt64,
value String
) Engine = TinyLog;
INSERT INTO dictionary_source_table values (0, 0, 5, 'Value');
DROP DICTIONARY IF EXISTS range_hashed_dictionary;
CREATE DICTIONARY range_hashed_dictionary
(
key UInt64,
start UInt64,
end UInt64,
value String
)
PRIMARY KEY key
SOURCE(CLICKHOUSE(TABLE 'dictionary_source_table'))
LAYOUT(RANGE_HASHED())
RANGE(MIN start MAX end)
LIFETIME(0);
SELECT dictGet('range_hashed_dictionary', 'value', 0, toUInt64(4));
SELECT dictGet('range_hashed_dictionary', 'value', 4, toUInt64(6), 'DefaultValue'); --{serverError 42}
SELECT dictGetOrDefault('range_hashed_dictionary', 'value', 1, toUInt64(6), 'DefaultValue');
SELECT dictGetOrDefault('range_hashed_dictionary', 'value', 1, toUInt64(6), 'DefaultValue', 1); --{serverError 42}
DROP DICTIONARY range_hashed_dictionary;
DROP TABLE dictionary_source_table;