mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 16:42:05 +00:00
Merge pull request #11934 from ClickHouse/fix_some_logical_errors
Fix some logical errors
This commit is contained in:
commit
0260358253
@ -17,6 +17,7 @@ namespace ErrorCodes
|
|||||||
{
|
{
|
||||||
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
|
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
|
||||||
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
|
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
|
||||||
|
extern const int UNKNOWN_TABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -110,6 +111,9 @@ void FunctionHasColumnInTable::executeImpl(Block & block, const ColumnNumbers &
|
|||||||
String table_name = get_string_from_block(arguments[arg++]);
|
String table_name = get_string_from_block(arguments[arg++]);
|
||||||
String column_name = get_string_from_block(arguments[arg++]);
|
String column_name = get_string_from_block(arguments[arg++]);
|
||||||
|
|
||||||
|
if (table_name.empty())
|
||||||
|
throw Exception("Table name is empty", ErrorCodes::UNKNOWN_TABLE);
|
||||||
|
|
||||||
bool has_column;
|
bool has_column;
|
||||||
if (host_name.empty())
|
if (host_name.empty())
|
||||||
{
|
{
|
||||||
|
@ -329,5 +329,16 @@ Field convertFieldToType(const Field & from_value, const IDataType & to_type, co
|
|||||||
return convertFieldToTypeImpl(from_value, to_type, from_type_hint);
|
return convertFieldToTypeImpl(from_value, to_type, from_type_hint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Field convertFieldToTypeOrThrow(const Field & from_value, const IDataType & to_type, const IDataType * from_type_hint)
|
||||||
|
{
|
||||||
|
bool is_null = from_value.isNull();
|
||||||
|
if (is_null && !to_type.isNullable())
|
||||||
|
throw Exception(ErrorCodes::TYPE_MISMATCH, "Cannot convert NULL to {}", to_type.getName());
|
||||||
|
Field converted = convertFieldToType(from_value, to_type, from_type_hint);
|
||||||
|
if (!is_null && converted.isNull())
|
||||||
|
throw Exception(ErrorCodes::ARGUMENT_OUT_OF_BOUND, "Cannot convert value{}: it cannot be represented as {}",
|
||||||
|
from_type_hint ? " from " + from_type_hint->getName() : "", to_type.getName());
|
||||||
|
return converted;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,4 +17,7 @@ class IDataType;
|
|||||||
*/
|
*/
|
||||||
Field convertFieldToType(const Field & from_value, const IDataType & to_type, const IDataType * from_type_hint = nullptr);
|
Field convertFieldToType(const Field & from_value, const IDataType & to_type, const IDataType * from_type_hint = nullptr);
|
||||||
|
|
||||||
|
/// Does the same, but throws ARGUMENT_OUT_OF_BOUND if value does not fall into the range.
|
||||||
|
Field convertFieldToTypeOrThrow(const Field & from_value, const IDataType & to_type, const IDataType * from_type_hint = nullptr);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ static void parseAndInsertValues(MutableColumns & res_columns, const ASTs & args
|
|||||||
{
|
{
|
||||||
const auto & [value_field, value_type_ptr] = evaluateConstantExpression(args[i], context);
|
const auto & [value_field, value_type_ptr] = evaluateConstantExpression(args[i], context);
|
||||||
|
|
||||||
Field value = convertFieldToType(value_field, *sample_block.getByPosition(0).type, value_type_ptr.get());
|
Field value = convertFieldToTypeOrThrow(value_field, *sample_block.getByPosition(0).type, value_type_ptr.get());
|
||||||
res_columns[0]->insert(value);
|
res_columns[0]->insert(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -51,11 +51,11 @@ static void parseAndInsertValues(MutableColumns & res_columns, const ASTs & args
|
|||||||
const Tuple & value_tuple = value_field.safeGet<Tuple>();
|
const Tuple & value_tuple = value_field.safeGet<Tuple>();
|
||||||
|
|
||||||
if (value_tuple.size() != sample_block.columns())
|
if (value_tuple.size() != sample_block.columns())
|
||||||
throw Exception("Values size should match with number of columns", ErrorCodes::LOGICAL_ERROR);
|
throw Exception("Values size should match with number of columns", ErrorCodes::BAD_ARGUMENTS);
|
||||||
|
|
||||||
for (size_t j = 0; j < value_tuple.size(); ++j)
|
for (size_t j = 0; j < value_tuple.size(); ++j)
|
||||||
{
|
{
|
||||||
Field value = convertFieldToType(value_tuple[j], *sample_block.getByPosition(j).type, value_types_tuple[j].get());
|
Field value = convertFieldToTypeOrThrow(value_tuple[j], *sample_block.getByPosition(j).type, value_types_tuple[j].get());
|
||||||
res_columns[j]->insert(value);
|
res_columns[j]->insert(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,3 +12,4 @@
|
|||||||
0
|
0
|
||||||
0
|
0
|
||||||
0
|
0
|
||||||
|
0
|
||||||
|
@ -18,5 +18,14 @@ SELECT hasColumnInTable(currentDatabase(), 'has_column_in_table', 'nest.not_exis
|
|||||||
SELECT hasColumnInTable('localhost', currentDatabase(), 'has_column_in_table', 'nest.not_existing');
|
SELECT hasColumnInTable('localhost', currentDatabase(), 'has_column_in_table', 'nest.not_existing');
|
||||||
SELECT hasColumnInTable(currentDatabase(), 'has_column_in_table', 'not_existing');
|
SELECT hasColumnInTable(currentDatabase(), 'has_column_in_table', 'not_existing');
|
||||||
SELECT hasColumnInTable('localhost', currentDatabase(), 'has_column_in_table', 'not_existing');
|
SELECT hasColumnInTable('localhost', currentDatabase(), 'has_column_in_table', 'not_existing');
|
||||||
|
SELECT hasColumnInTable('system', 'one', '');
|
||||||
|
|
||||||
|
/* bad queries */
|
||||||
|
SELECT hasColumnInTable('', '', ''); -- { serverError 60; }
|
||||||
|
SELECT hasColumnInTable('', 't', 'c'); -- { serverError 81; }
|
||||||
|
SELECT hasColumnInTable(currentDatabase(), '', 'c'); -- { serverError 60; }
|
||||||
|
SELECT hasColumnInTable('d', 't', 's'); -- { serverError 81; }
|
||||||
|
SELECT hasColumnInTable(currentDatabase(), 't', 's'); -- { serverError 60; }
|
||||||
|
|
||||||
|
|
||||||
DROP TABLE has_column_in_table;
|
DROP TABLE has_column_in_table;
|
||||||
|
@ -11,3 +11,4 @@ abracadabra
|
|||||||
23 23 23
|
23 23 23
|
||||||
24 24 24
|
24 24 24
|
||||||
1.6660 a b
|
1.6660 a b
|
||||||
|
\N
|
||||||
|
@ -11,4 +11,9 @@ SELECT * FROM VALUES('s String', ('abra'), ('cadabra'), ('abracadabra'));
|
|||||||
SELECT * FROM VALUES('n UInt64, s String, ss String', (1 + 22, '23', toString(23)), (toUInt64('24'), '24', concat('2', '4')));
|
SELECT * FROM VALUES('n UInt64, s String, ss String', (1 + 22, '23', toString(23)), (toUInt64('24'), '24', concat('2', '4')));
|
||||||
|
|
||||||
SELECT * FROM VALUES('a Decimal(4, 4), b String, c String', (divide(toDecimal32(5, 3), 3), 'a', 'b'));
|
SELECT * FROM VALUES('a Decimal(4, 4), b String, c String', (divide(toDecimal32(5, 3), 3), 'a', 'b'));
|
||||||
|
|
||||||
|
SELECT * FROM VALUES('x Float64', toUInt64(-1)); -- { serverError 69; }
|
||||||
|
SELECT * FROM VALUES('x Float64', NULL); -- { serverError 53; }
|
||||||
|
SELECT * FROM VALUES('x Nullable(Float64)', NULL);
|
||||||
|
|
||||||
DROP TABLE values_list;
|
DROP TABLE values_list;
|
||||||
|
Loading…
Reference in New Issue
Block a user