Skip to content

Commit

Permalink
work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
adranwit committed Jul 23, 2023
1 parent 53696a7 commit 6e5caa5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 27 deletions.
12 changes: 1 addition & 11 deletions cmd/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/viant/toolbox/format"
"github.com/viant/velty/ast/expr"
"github.com/viant/velty/parser"
"github.com/viant/xdatly/predicate"
"github.com/viant/xreflect"
"go/ast"
goFormat "go/format"
Expand Down Expand Up @@ -2091,19 +2090,10 @@ func (s *Builder) readParamConfigs(cfg *option.ParameterConfig, cursor *parsly.C
if err != nil {
return err
}

var namedArgs []*predicate.NamedArgument
for pos, argName := range args[2:] {
namedArgs = append(namedArgs, &predicate.NamedArgument{
Position: pos,
Name: argName,
})
}

cfg.Predicate = &config.PredicateConfig{
Name: args[1],
Context: ctx,
Args: namedArgs,
Args: args[2:],
}
case "UtilParam":
if len(args) != 0 {
Expand Down
2 changes: 1 addition & 1 deletion config/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type (
Parent string
Name string
Context int
Args []*predicate.NamedArgument
Args []string
}

NamedArg struct {
Expand Down
10 changes: 1 addition & 9 deletions internal/translator/parser/declarations.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/viant/sqlparser"
"github.com/viant/velty/ast/expr"
"github.com/viant/velty/parser"
"github.com/viant/xdatly/predicate"
"github.com/viant/xreflect"

"strconv"
Expand Down Expand Up @@ -227,17 +226,10 @@ func (s *Declarations) parseShorthands(declaration *Declaration, cursor *parsly.
if err != nil {
return err
}
var namedArgs []*predicate.NamedArgument
for pos, argName := range args[2:] {
namedArgs = append(namedArgs, &predicate.NamedArgument{
Position: pos,
Name: argName,
})
}
declaration.Predicate = &config.PredicateConfig{
Name: args[1],
Context: ctx,
Args: namedArgs,
Args: args[2:],
}
case "UtilParam":
//deprecated
Expand Down
12 changes: 6 additions & 6 deletions view/predicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type (
predicateEvaluatorProvider struct {
evaluator *expand.Evaluator
ctxType reflect.Type
argsIndex map[int]*predicate.NamedArgument
signature map[int]*predicate.NamedArgument
stateName string
}

Expand Down Expand Up @@ -69,12 +69,12 @@ func (c *predicateCache) getEvaluatorProvider(predicateConfig *config.PredicateC
func (p *predicateEvaluatorProvider) new(predicateConfig *config.PredicateConfig) (*predicateEvaluator, error) {
dst := types.NewValue(p.ctxType)
dstPtr := xunsafe.AsPointer(dst)
for _, field := range predicateConfig.Args {
argument, ok := p.argsIndex[field.Position]
for i, arg := range predicateConfig.Args {
argument, ok := p.signature[i]
if !ok {
return nil, fmt.Errorf("not found predicate arg %v", field.Position)
return nil, fmt.Errorf("not found predicate arg %v", i)
}
xunsafe.FieldByName(p.ctxType, argument.Name).SetString(dstPtr, field.Name)
xunsafe.FieldByName(p.ctxType, argument.Name).SetString(dstPtr, arg)
}

customCtx := &expand.CustomContext{
Expand Down Expand Up @@ -111,7 +111,7 @@ func (p *predicateEvaluatorProvider) init(predicateConfig *config.PredicateConfi

p.ctxType = ctxType
p.evaluator = evaluator
p.argsIndex = argsIndexed
p.signature = argsIndexed
p.stateName = stateName
return nil
}

0 comments on commit 6e5caa5

Please sign in to comment.