public void execute() throws DdlException {
        Map<String, UserVariable> clonedUserVars = new ConcurrentHashMap<>();
        boolean hasUserVar = stmt.getSetListItems().stream().anyMatch(var -> var instanceof UserVariable);
        boolean executeSuccess = true;
        if (hasUserVar) {
            clonedUserVars.putAll(ctx.getUserVariables());
            ctx.modifyUserVariablesCopyInWrite(clonedUserVars);
        }
        try {
            for (SetListItem var : stmt.getSetListItems()) {
                setVariablesOfAllType(var);
            }
        } catch (Throwable e) {
            if (hasUserVar) {
                executeSuccess = false;
            }
            throw e;
        } finally {
            //If the set sql contains more than one user variable,
            //the atomicity of the modification of this set of variables must be ensured.
            if (hasUserVar) {
                ctx.resetUserVariableCopyInWrite();
                if (executeSuccess) {
                    ctx.modifyUserVariables(clonedUserVars);
                }
            }
        }
    }
@Test
    public void testUserDefineVariable2() throws Exception {
        ConnectContext ctx = starRocksAssert.getCtx();
        String sql = "set @var = cast(10 as decimal)";
        SetStmt stmt = (SetStmt) UtFrameUtils.parseStmtWithNewParser(sql, ctx);
        SetExecutor executor = new SetExecutor(ctx, stmt);
        executor.execute();
        UserVariable userVariable = ctx.getUserVariable("var");
        Assert.assertTrue(userVariable.getEvaluatedExpression().getType().isDecimalV3());
        LiteralExpr literalExpr = (LiteralExpr) userVariable.getEvaluatedExpression();
        Assert.assertEquals("10", literalExpr.getStringValue());

        sql = "set @var = cast(1 as boolean)";
        stmt = (SetStmt) UtFrameUtils.parseStmtWithNewParser(sql, ctx);
        executor = new SetExecutor(ctx, stmt);
        executor.execute();
        userVariable = ctx.getUserVariable("var");
        Assert.assertTrue(userVariable.getEvaluatedExpression().getType().isBoolean());
        BoolLiteral literal = (BoolLiteral) userVariable.getEvaluatedExpression();
        Assert.assertTrue(literal.getValue());

        sql = "set @var = cast(0 as boolean)";
        stmt = (SetStmt) UtFrameUtils.parseStmtWithNewParser(sql, ctx);
        executor = new SetExecutor(ctx, stmt);
        executor.execute();
        userVariable = ctx.getUserVariable("var");
        Assert.assertTrue(userVariable.getEvaluatedExpression().getType().isBoolean());
        literal = (BoolLiteral) userVariable.getEvaluatedExpression();
        Assert.assertFalse(literal.getValue());
    }