Fix s3select TRIM function's nil pointer dereference bug (#7817)

master
Yao Zongyou 6 years ago committed by kannappanr
parent 48cb271a46
commit 23b9df0694
  1. 9
      pkg/s3select/sql/analysis.go
  2. 21
      pkg/s3select/sql/funceval.go

@ -274,6 +274,15 @@ func (e *FuncExpr) analyze(s *Select) (result qProp) {
} }
return result return result
case sqlFnTrim:
if e.Trim.TrimChars != nil {
result.combine(e.Trim.TrimChars.analyze(s))
}
if e.Trim.TrimFrom != nil {
result.combine(e.Trim.TrimFrom.analyze(s))
}
return result
case sqlFnSubstring: case sqlFnSubstring:
errVal := fmt.Errorf("Invalid argument(s) to %s", string(funcName)) errVal := fmt.Errorf("Invalid argument(s) to %s", string(funcName))
result.combine(e.Substring.Expr.analyze(s)) result.combine(e.Substring.Expr.analyze(s))

@ -337,20 +337,25 @@ func handleSQLSubstring(r Record, e *SubstringFunc) (val *Value, err error) {
} }
func handleSQLTrim(r Record, e *TrimFunc) (res *Value, err error) { func handleSQLTrim(r Record, e *TrimFunc) (res *Value, err error) {
charsV, cerr := e.TrimChars.evalNode(r) chars := ""
if cerr != nil { ok := false
return nil, cerr if e.TrimChars != nil {
} charsV, cerr := e.TrimChars.evalNode(r)
inferTypeAsString(charsV) if cerr != nil {
chars, ok := charsV.ToString() return nil, cerr
if !ok { }
return nil, errNonStringTrimArg inferTypeAsString(charsV)
chars, ok = charsV.ToString()
if !ok {
return nil, errNonStringTrimArg
}
} }
fromV, ferr := e.TrimFrom.evalNode(r) fromV, ferr := e.TrimFrom.evalNode(r)
if ferr != nil { if ferr != nil {
return nil, ferr return nil, ferr
} }
inferTypeAsString(fromV)
from, ok := fromV.ToString() from, ok := fromV.ToString()
if !ok { if !ok {
return nil, errNonStringTrimArg return nil, errNonStringTrimArg

Loading…
Cancel
Save