mirror of
https://github.com/minio/minio.git
synced 2025-11-21 02:09:08 -05:00
Add JSON Path expression evaluation support (#7315)
- Includes support for FROM clause JSON path
This commit is contained in:
committed by
Harshavardhana
parent
b296b3cf8b
commit
e463386921
@@ -17,8 +17,11 @@
|
||||
package sql
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/bcicen/jstream"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -319,7 +322,44 @@ func (e *JSONPath) evalNode(r Record) (*Value, error) {
|
||||
if len(ps) == 2 {
|
||||
keypath = ps[1]
|
||||
}
|
||||
return r.Get(keypath)
|
||||
objFmt, rawVal := r.Raw()
|
||||
switch objFmt {
|
||||
case SelectFmtJSON, SelectFmtParquet:
|
||||
rowVal := rawVal.(jstream.KVS)
|
||||
|
||||
pathExpr := e.PathExpr
|
||||
if len(pathExpr) == 0 {
|
||||
pathExpr = []*JSONPathElement{{Key: &ObjectKey{ID: e.BaseKey}}}
|
||||
}
|
||||
|
||||
result, err := jsonpathEval(pathExpr, rowVal)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch rval := result.(type) {
|
||||
case string:
|
||||
return FromString(rval), nil
|
||||
case float64:
|
||||
return FromFloat(rval), nil
|
||||
case int64:
|
||||
return FromInt(rval), nil
|
||||
case bool:
|
||||
return FromBool(rval), nil
|
||||
case jstream.KVS, []interface{}:
|
||||
bs, err := json.Marshal(result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return FromBytes(bs), nil
|
||||
case nil:
|
||||
return FromNull(), nil
|
||||
default:
|
||||
return nil, errors.New("Unhandled value type")
|
||||
}
|
||||
default:
|
||||
return r.Get(keypath)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *PrimaryTerm) evalNode(r Record) (res *Value, err error) {
|
||||
|
||||
Reference in New Issue
Block a user