Code review comment: It seems that it is not necessary to be that complicated, I use a easier realization.

Code under review:
public void analyze(Analyzer analyzer) throws AnalysisException, UserException {
        if (type == null) {
            type = SetType.DEFAULT;
        }

        if (Strings.isNullOrEmpty(variable)) {
            throw new AnalysisException("No variable name in set statement.");
        }

        if (type == SetType.GLOBAL) {
            if (!Catalog.getCurrentCatalog().getAuth().checkGlobalPriv(ConnectContext.get(), PrivPredicate.ADMIN)) {
                ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR,
                        "ADMIN");
            }
        }

        if (value == null) {
            return;
        }

        
        if (value instanceof SlotRef) {
            value = new StringLiteral(((SlotRef) value).getColumnName());
        }

        value.analyze(analyzer);
        if (!value.isConstant()) {
            throw new AnalysisException("Set statement does't support non-constant expr.");
        }

        final Expr literalExpr = value.getResultValue();
        if (!(literalExpr instanceof LiteralExpr)) {
            throw new AnalysisException("Set statement does't support computing expr:" + literalExpr.toSql());
        }

        result = (LiteralExpr)literalExpr;

        if (variable.equalsIgnoreCase(SessionVariable.SQL_MODE)) {
            
            if (result instanceof StringLiteral) {
                String sqlMode = result.getStringValue();
                result = new StringLiteral(SqlModeHelper.encode(sqlMode).toString());
            }
            
            else if (result instanceof IntLiteral) {
                String sqlMode = SqlModeHelper.decode(result.getLongValue());
                result = new IntLiteral(SqlModeHelper.encode(sqlMode).toString(), Type.BIGINT);
            }
        }
        if (variable.equalsIgnoreCase(GlobalVariable.HEARTBEAT_FLAGS)) {
            
            if (result instanceof StringLiteral) {
                String flags = result.getStringValue();
                result = new StringLiteral(HeartbeatFlagHelper.analyze(flags).toString());
            } else if (result instanceof IntLiteral) {
                
                String sqlMode = HeartbeatFlagHelper.analyze(result.getLongValue());
                result = new IntLiteral(result.getLongValue(), Type.BIGINT);
            }
        }

        
        if (variable.equalsIgnoreCase(SessionVariable.RESOURCE_VARIABLE)) {
            if (result != null && !UserResource.isValidGroup(result.getStringValue())) {
                throw new AnalysisException("Invalid resource group, now we support {low, normal, high}.");
            }
        }
    }

Line commented on: if (variable.equalsIgnoreCase(GlobalVariable.HEARTBEAT_FLAGS)) {

Revised code:
public void analyze(Analyzer analyzer) throws AnalysisException, UserException {
        if (type == null) {
            type = SetType.DEFAULT;
        }

        if (Strings.isNullOrEmpty(variable)) {
            throw new AnalysisException("No variable name in set statement.");
        }

        if (type == SetType.GLOBAL) {
            if (!Catalog.getCurrentCatalog().getAuth().checkGlobalPriv(ConnectContext.get(), PrivPredicate.ADMIN)) {
                ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR,
                        "ADMIN");
            }
        }

        if (value == null) {
            return;
        }

        
        if (value instanceof SlotRef) {
            value = new StringLiteral(((SlotRef) value).getColumnName());
        }

        value.analyze(analyzer);
        if (!value.isConstant()) {
            throw new AnalysisException("Set statement does't support non-constant expr.");
        }

        final Expr literalExpr = value.getResultValue();
        if (!(literalExpr instanceof LiteralExpr)) {
            throw new AnalysisException("Set statement does't support computing expr:" + literalExpr.toSql());
        }

        result = (LiteralExpr)literalExpr;

        if (variable.equalsIgnoreCase(SessionVariable.SQL_MODE)) {
            
            if (result instanceof StringLiteral) {
                String sqlMode = result.getStringValue();
                result = new StringLiteral(SqlModeHelper.encode(sqlMode).toString());
            }
            
            else if (result instanceof IntLiteral) {
                String sqlMode = SqlModeHelper.decode(result.getLongValue());
                result = new IntLiteral(SqlModeHelper.encode(sqlMode).toString(), Type.BIGINT);
            }
        }

        
        if (variable.equalsIgnoreCase(SessionVariable.RESOURCE_VARIABLE)) {
            if (result != null && !UserResource.isValidGroup(result.getStringValue())) {
                throw new AnalysisException("Invalid resource group, now we support {low, normal, high}.");
            }
        }
        if (variable.equalsIgnoreCase(SessionVariable.DEFAULT_ROWSET_TYPE)) {
            if (type != SetType.GLOBAL) {
                throw new AnalysisException("default_rowset_type must be global. use set global");
            }
            if (result != null && !HeartbeatFlags.isValidRowsetType(result.getStringValue())) {
                throw new AnalysisException("Invalid rowset type, now we support {alpha, beta}.");
            }
        }
    }