mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 23:52:03 +00:00
Merge pull request #37754 from Avogar/fix-values-func
Fix possible logical error in values table function
This commit is contained in:
commit
9f0ebb4eac
@ -31,11 +31,21 @@ namespace ErrorCodes
|
||||
extern const int BAD_ARGUMENTS;
|
||||
}
|
||||
|
||||
static std::pair<Field, std::shared_ptr<const IDataType>> getFieldAndDataTypeFromLiteral(ASTLiteral * literal)
|
||||
{
|
||||
auto type = applyVisitor(FieldToDataType(), literal->value);
|
||||
/// In case of Array field nested fields can have different types.
|
||||
/// Example: Array [1, 2.3] will have 2 fields with types UInt64 and Float64
|
||||
/// when result type is Array(Float64).
|
||||
/// So, we need to convert this field to the result type.
|
||||
Field res = convertFieldToType(literal->value, *type);
|
||||
return {res, type};
|
||||
}
|
||||
|
||||
std::pair<Field, std::shared_ptr<const IDataType>> evaluateConstantExpression(const ASTPtr & node, ContextPtr context)
|
||||
{
|
||||
if (ASTLiteral * literal = node->as<ASTLiteral>())
|
||||
return std::make_pair(literal->value, applyVisitor(FieldToDataType(), literal->value));
|
||||
return getFieldAndDataTypeFromLiteral(literal);
|
||||
|
||||
NamesAndTypesList source_columns = {{ "_dummy", std::make_shared<DataTypeUInt8>() }};
|
||||
|
||||
@ -63,7 +73,7 @@ std::pair<Field, std::shared_ptr<const IDataType>> evaluateConstantExpression(co
|
||||
/// AST potentially could be transformed to literal during TreeRewriter analyze.
|
||||
/// For example if we have SQL user defined function that return literal AS subquery.
|
||||
if (ASTLiteral * literal = ast->as<ASTLiteral>())
|
||||
return std::make_pair(literal->value, applyVisitor(FieldToDataType(), literal->value));
|
||||
return getFieldAndDataTypeFromLiteral(literal);
|
||||
|
||||
ExpressionActionsPtr expr_for_constant_folding = ExpressionAnalyzer(ast, syntax_result, context).getConstActions();
|
||||
|
||||
|
@ -0,0 +1,2 @@
|
||||
[1,2.2]
|
||||
[[1,2,3],[1.1,2.2,3.3]]
|
@ -0,0 +1,2 @@
|
||||
select * from values([1, 2.2]);
|
||||
select * from values([[1, 2, 3], [1.1, 2.2, 3.3]]);
|
Loading…
Reference in New Issue
Block a user