func (c \*logicOrFunctionClass) getFunction(ctx sessionctx.Context, args []Expression)…
- User
func (c *logicOrFunctionClass) getFunction(ctx sessionctx.Context, args []Expression) (builtinFunc, error) { err := c.verifyArgs(args) if err != nil { return nil, err } args[0], err = wrapWithIsTrue(ctx, true, args[0], false) if err != nil { return nil, errors.Trace(err) } args[1], err = wrapWithIsTrue(ctx, true, args[1], false) if err != nil { return nil, errors.Trace(err) }
bf, err := newBaseBuiltinFuncWithTp(ctx, c.funcName, args, types.ETInt, types.ETInt, types.ETInt) if err != nil { return nil, err } bf.tp.SetFlen(1) sig := &builtinLogicOrSig{bf} sig.setPbCode(tipb.ScalarFuncSig_LogicalOr) return sig, nil }
- Assistant
This function appears to be part of a built-in function class for the
ORlogical operator in a SQL-like language. The function takes as input asessionctx.Contextand an array ofExpressions, which are the arguments to theORoperator. The function then verifies that the arguments are valid, wraps the arguments with awrapWithIsTruefunction, and returns a newbuiltinFuncwith the signature of theORoperator. ThisbuiltinFunccan then be used to evaluate theORoperator with the given arguments in a particular context. - User
convert it with rust
- Assistant
Here is an example of how the code you provided could be implemented in the Rust programming language:
codeuse std::error::Error; struct LogicOrFunctionClass { func_name: String, } impl LogicOrFunctionClass { fn get_function( &self, ctx: &SessionContext, args: &[Expression], ) -> Result<BuiltinFunc, Box<dyn Error>> { self.verify_args(args)?; let args_0 = wrap_with_is_true(ctx, true, args[0], false)?; let args_1 = wrap_with_is_true(ctx, true, args[1], false)?; let bf = new_base_builtin_func_with_tp( ctx, &self.func_name, &[args_0, args_1], EType::Int, EType::Int, EType::Int, )?; bf.tp.set_flen(1); let sig = BuiltinLogicOrSig { bf }; sig.set_pb_code(ScalarFuncSigCode::LogicalOr); Ok(sig) } }