public static void setSystemVariable(SessionVariable sessionVariable, SystemVariable setVar, boolean onlySetSessionVar)
            throws DdlException {
        if (SessionVariable.DEPRECATED_VARIABLES.stream().anyMatch(c -> c.equalsIgnoreCase(setVar.getVariable()))) {
            return;
        }
        checkSystemVariableExist(setVar);

        if (setVar.getType() == SetType.VERBOSE) {
            ErrorReport.reportDdlException(ErrorCode.ERR_WRONG_TYPE_FOR_VAR, setVar.getVariable());
        }

        // Check variable attribute and setVar
        VarContext ctx = getVarContext(setVar.getVariable());
        checkUpdate(setVar, ctx.getFlag());

        // To modify to default value.
        VarAttr attr = ctx.getField().getAnnotation(VarAttr.class);
        String value;
        // If value is null, this is `set variable = DEFAULT`
        if (setVar.getResolvedExpression() != null) {
            value = setVar.getResolvedExpression().getStringValue();
        } else {
            value = ctx.getDefaultValue();
            if (value == null) {
                ErrorReport.reportDdlException(ErrorCode.ERR_NO_DEFAULT, attr.name());
            }
        }

        if (!onlySetSessionVar && setVar.getType() == SetType.GLOBAL) {
            WLOCK.lock();
            try {
                setValue(ctx.getObj(), ctx.getField(), value);
                // write edit log
                GlobalVarPersistInfo info =
                        new GlobalVarPersistInfo(DEFAULT_SESSION_VARIABLE, Lists.newArrayList(attr.name()));
                EditLog editLog = GlobalStateMgr.getCurrentState().getEditLog();
                editLog.logGlobalVariableV2(info);
            } finally {
                WLOCK.unlock();
            }
        }

        // set session variable
        setValue(sessionVariable, ctx.getField(), value);
    }
@Test
    public void testWarehouseVar() {
        SystemVariable systemVariable =
                new SystemVariable(SetType.GLOBAL, SessionVariable.WAREHOUSE_NAME, new StringLiteral("warehouse_1"));
        try {
            VariableMgr.setSystemVariable(null, systemVariable, false);
        } catch (DdlException e) {
            Assert.assertEquals("Variable 'warehouse' is a SESSION variable and can't be used with SET GLOBAL",
                    e.getMessage());
        }
    }