Merge pull request #11936 from ClickHouse/fix_11918

Fix query parameter visitor
This commit is contained in:
alexey-milovidov 2020-06-26 00:54:37 +03:00 committed by GitHub
commit 6a45f3e960
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 6 deletions

View File

@ -25,14 +25,18 @@ namespace ErrorCodes
void ReplaceQueryParameterVisitor::visit(ASTPtr & ast)
{
if (ast->as<ASTQueryParameter>())
visitQueryParameter(ast);
else
visitChildren(ast);
}
void ReplaceQueryParameterVisitor::visitChildren(ASTPtr & ast)
{
for (auto & child : ast->children)
{
if (child->as<ASTQueryParameter>())
visitQueryParameter(child);
else
visit(child);
}
visit(child);
}
const String & ReplaceQueryParameterVisitor::getParamValue(const String & name)

View File

@ -22,6 +22,7 @@ private:
const NameToNameMap & query_parameters;
const String & getParamValue(const String & name);
void visitQueryParameter(ASTPtr & ast);
void visitChildren(ASTPtr & ast);
};
}

View File

@ -3,3 +3,4 @@
2 testparam [0.3]
3 paramparam []
4 evaluateparam [0.2]
5 param [0.2,0.3]

View File

@ -15,6 +15,9 @@ $CLICKHOUSE_CLIENT --input_format_values_deduce_templates_of_expressions=1 --inp
$CLICKHOUSE_CLIENT --input_format_values_deduce_templates_of_expressions=0 --input_format_values_interpret_expressions=1 --param_p_n="-1" --param_p_s="param" --param_p_a="[0.2,0.3]" --query="INSERT INTO insert_values_parametrized VALUES \
(5 + {p_n:Int8}, lower(concat('Evaluate', {p_s:String})), arrayIntersect([0, 0.2, 0.6], {p_a:Array(Nullable(Float32))}))"
$CLICKHOUSE_CLIENT --param_p_n="5" --param_p_s="param" --param_p_a="[0.2,0.3]" --query="INSERT INTO insert_values_parametrized VALUES \
({p_n:Int8}, {p_s:String}, {p_a:Array(Nullable(Float32))})"
$CLICKHOUSE_CLIENT --query="SELECT * FROM insert_values_parametrized ORDER BY n";
$CLICKHOUSE_CLIENT --query="DROP TABLE insert_values_parametrized";