Skip to content

Commit

Permalink
Merge pull request #4888 from b41sh/fix-validate-func-args
Browse files Browse the repository at this point in the history
fix(function): validate function args before get type
  • Loading branch information
BohuTANG authored Apr 16, 2022
2 parents ae1698f + c0e6350 commit 16fa1c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions common/planners/src/plan_expression_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use common_exception::ErrorCode;
use common_exception::Result;
use common_functions::scalars::FunctionFactory;

use crate::validate_function_arg;
use crate::Expression;
use crate::ExpressionVisitor;
use crate::Recursion;
Expand Down Expand Up @@ -395,6 +396,14 @@ impl ExpressionDataTypeVisitor {
}

fn visit_function(mut self, op: &str, args_size: usize) -> Result<ExpressionDataTypeVisitor> {
let features = FunctionFactory::instance().get_features(op)?;
validate_function_arg(
op,
args_size,
features.variadic_arguments,
features.num_arguments,
)?;

let mut arguments = Vec::with_capacity(args_size);
for index in 0..args_size {
arguments.push(match self.stack.pop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ select parse_json(parse_json('123'));
select parse_json(parse_json('"\\\"abc\\\""'));
select parse_json(parse_json('"abc"')); -- {ErrorCode 1010}
select parse_json(todate32('2022-01-01')); -- {ErrorCode 1010}
select parse_json(); -- {ErrorCode 1028}
select parse_json('a', 'aa'); -- {ErrorCode 1028}
select get(parse_json('a', 'aa')); -- {ErrorCode 1028}

select '==try_parse_json==';
select try_parse_json(null);
Expand Down

0 comments on commit 16fa1c2

Please sign in to comment.