Fix possible logical error in values table function

This commit is contained in:
avogar 2022-06-01 15:32:33 +00:00
parent ee302f2d9f
commit 7ef02a2e44
3 changed files with 16 additions and 2 deletions

View File

@ -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();

View File

@ -0,0 +1,2 @@
[1,2.2]
[[1,2,3],[1.1,2.2,3.3]]

View File

@ -0,0 +1,2 @@
select * from values([1, 2.2]);
select * from values([[1, 2, 3], [1.1, 2.2, 3.3]]);