Skip to content

Commit

Permalink
Fix enumtype system variable check (#16692)
Browse files Browse the repository at this point in the history
Fix enumtype system variable check

Approved by: @daviszhen, @sukki37
  • Loading branch information
ck89119 authored Jun 5, 2024
1 parent f900631 commit e6b2868
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
25 changes: 14 additions & 11 deletions pkg/frontend/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,19 +733,22 @@ func (ses *feSessionImpl) GetGlobalSysVar(name string) (interface{}, error) {

func (ses *Session) SetGlobalSysVar(ctx context.Context, name string, val interface{}) (err error) {
name = strings.ToLower(name)
if sv, ok := gSysVarsDefs[name]; !ok {

def, ok := gSysVarsDefs[name]
if !ok {
return moerr.NewInternalErrorNoCtx(errorSystemVariableDoesNotExist())
} else {
if sv.Scope == ScopeSession {
return moerr.NewInternalErrorNoCtx(errorSystemVariableIsSession())
}
if !sv.GetDynamic() {
return moerr.NewInternalErrorNoCtx(errorSystemVariableIsReadOnly())
}
}

if val, err = sv.GetType().Convert(val); err != nil {
return err
}
if def.Scope == ScopeSession {
return moerr.NewInternalErrorNoCtx(errorSystemVariableIsSession())
}

if !def.GetDynamic() {
return moerr.NewInternalErrorNoCtx(errorSystemVariableIsReadOnly())
}

if val, err = def.GetType().Convert(val); err != nil {
return err
}

// save to table first
Expand Down
2 changes: 1 addition & 1 deletion pkg/frontend/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ func (svet SystemVariableEnumType) String() string {

func (svet SystemVariableEnumType) Convert(value interface{}) (interface{}, error) {
cv1 := func(x int) (interface{}, error) {
if x >= 0 && x <= len(svet.id2TagName) {
if x >= 0 && x < len(svet.id2TagName) {
return svet.id2TagName[x], nil
}
return nil, errorConvertToEnumFailed
Expand Down

0 comments on commit e6b2868

Please sign in to comment.