Skip to content

Commit

Permalink
updated converter
Browse files Browse the repository at this point in the history
  • Loading branch information
klarysz committed Aug 2, 2023
1 parent 4dfa5b6 commit 6d61217
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 19 deletions.
6 changes: 3 additions & 3 deletions config/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ func NewNotInPredicate() *predicate.Template {
}

func newInPredicate(name string, equal bool) *predicate.Template {
column := "${Alias}.${ColumnName}"
in := fmt.Sprintf("$criteria.In(%v, $FilterValue)", column)
column := `${Alias} + "." + ${ColumnName}`
in := fmt.Sprintf(`$criteria.In(%v, $FilterValue)`, column)

if !equal {
in = fmt.Sprintf("$criteria.NotIn(%v, $FilterValue)", column)
in = fmt.Sprintf(`$criteria.NotIn(%v, $FilterValue)`, column)
}

return &predicate.Template{
Expand Down
9 changes: 7 additions & 2 deletions converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package converter
import (
"context"
"encoding/json"
"github.com/viant/toolbox"
"github.com/viant/xreflect"
"reflect"
"strconv"
Expand Down Expand Up @@ -174,8 +175,12 @@ func Convert(raw string, toType reflect.Type, skipValidation bool, format string
format = time.RFC3339
}

asTime, err := time.Parse(format, raw)
return asTime, false, err
asTime, err := toolbox.ToTime(raw, format)
if err != nil {
return nil, false, err
}

return *asTime, false, nil
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Templates:
Predicates:
- Name: "price_range"
Args:
- Name: "Alias"
Expand Down
2 changes: 1 addition & 1 deletion e2e/local/regression/cases/065_params_group/templates.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Templates:
Predicates:
- Name: "custom_range"
Args:
- Name: "Alias"
Expand Down
3 changes: 2 additions & 1 deletion utils/types/accessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ func (a *Accessor) adjustAndSet(ptr unsafe.Pointer, value interface{}, format st
return nil, err
}

converted, _, err := converter.Convert(string(marshal), xField.Type, false, format)
raw := string(marshal)
converted, _, err := converter.Convert(raw, xField.Type, false, format)
if err != nil {
return nil, err
}
Expand Down
20 changes: 10 additions & 10 deletions view/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ type Resource struct {
_visitors config.CodecsRegistry
ModTime time.Time `json:",omitempty"`

Templates []*predicate.Template
_templates *config.PredicateRegistry
Predicates []*predicate.Template
_predicates *config.PredicateRegistry

_columnsCache map[string]Columns

Expand Down Expand Up @@ -668,34 +668,34 @@ func (r *Resource) mergeMessageBuses(resource *Resource) {

func (r *Resource) initTemplates(registry *config.PredicateRegistry) error {
if registry != nil {
r._templates = registry.Scope()
r._predicates = registry.Scope()
}

r.ensureTemplatesIndex()

for _, template := range r.Templates {
r._templates.Add(template)
for _, template := range r.Predicates {
r._predicates.Add(template)
}

return nil
}

func (r *Resource) ensureTemplatesIndex() {
if r._templates == nil {
r._templates = config.NewPredicates()
if r._predicates == nil {
r._predicates = config.NewPredicates()
}
}

func (r *Resource) mergeTemplates(resource *Resource) {
r.ensureTemplatesIndex()
for _, template := range resource.Templates {
for _, template := range resource.Predicates {
r.addTemplate(template)
}
}

func (r *Resource) addTemplate(template *predicate.Template) {
r.Templates = append(r.Templates, template)
r._templates.Add(template)
r.Predicates = append(r.Predicates, template)
r._predicates.Add(template)
}

func (r *Resource) expandStringField(value reflect.Value) error {
Expand Down
2 changes: 1 addition & 1 deletion view/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func (t *Template) initSqlEvaluator(resource *Resource) error {
var predicates []*expand.PredicateConfig
for _, p := range t.Parameters {
for _, predicate := range p.Predicates {
evaluator, err := cache.get(predicate, p, resource._templates, t.PresenceSchema.Type())
evaluator, err := cache.get(predicate, p, resource._predicates, t.PresenceSchema.Type())
if err != nil {
return err
}
Expand Down

0 comments on commit 6d61217

Please sign in to comment.