refactored data-types to reduce plugin sizes
This commit is contained in:
+9
-6
@@ -11,6 +11,9 @@ import (
|
||||
|
||||
"git.portale-stac.it/go-pkg/expr/kern"
|
||||
"git.portale-stac.it/go-pkg/expr/scan"
|
||||
"git.portale-stac.it/go-pkg/expr/types/array"
|
||||
"git.portale-stac.it/go-pkg/expr/types/dict"
|
||||
"git.portale-stac.it/go-pkg/expr/types/str"
|
||||
)
|
||||
|
||||
//-------- group by term
|
||||
@@ -52,13 +55,13 @@ func evalGroupBy(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
||||
keyByIndex = true
|
||||
} else if rightValue, err = opTerm.Children[1].Compute(ctx); err != nil {
|
||||
return
|
||||
} else if kern.IsString(rightValue) {
|
||||
} else if str.IsString(rightValue) {
|
||||
sKey = rightValue.(string)
|
||||
} else {
|
||||
return nil, fmt.Errorf("right operand of GROUPBY must be a string or identifier '__'; got %s", kern.TypeName(rightValue))
|
||||
}
|
||||
|
||||
values := kern.MakeDict()
|
||||
values := dict.MakeDict()
|
||||
for item, err = it.Next(); err == nil; item, err = it.Next() {
|
||||
ctx.SetVar("_", item)
|
||||
ctx.SetVar("__", it.Index())
|
||||
@@ -66,7 +69,7 @@ func evalGroupBy(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
||||
|
||||
var sItemKey string
|
||||
|
||||
if d, ok := item.(*kern.DictType); ok {
|
||||
if d, ok := item.(*dict.DictType); ok {
|
||||
if keyByIndex || len(sKey) == 0 {
|
||||
sItemKey = strconv.Itoa(int(it.Index()))
|
||||
} else if d.HasKey(sKey) {
|
||||
@@ -86,12 +89,12 @@ func evalGroupBy(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
||||
sItemKey = strconv.Itoa(int(it.Index()))
|
||||
}
|
||||
|
||||
var ls *kern.ListType
|
||||
var ls *array.ListType
|
||||
if lsAny, exists := values.GetItem(sItemKey); exists && lsAny != nil {
|
||||
ls = lsAny.(*kern.ListType)
|
||||
ls = lsAny.(*array.ListType)
|
||||
}
|
||||
if ls == nil {
|
||||
ls = kern.NewListA()
|
||||
ls = array.NewListA()
|
||||
}
|
||||
ls.AppendItem(item)
|
||||
values.SetItem(sItemKey, ls)
|
||||
|
||||
Reference in New Issue
Block a user