Skip to content

Commit

Permalink
fix map2table (#168)
Browse files Browse the repository at this point in the history
I think this should work though bahla never got around to it
  • Loading branch information
skothari-tibco committed Jul 23, 2020
1 parent 6071035 commit e6ae264
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
5 changes: 3 additions & 2 deletions operations/restructuring/map2table/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ func (a *Operation) Eval(inputs map[string]interface{}) (interface{}, error) {
a.logger.Debug("The inputs of Operation Map to Table.", inputs)
for _, ord := range in.ColOrder {
if val, ok := in.Map[ord.(string)]; ok {
ValLen = len(val.([]interface{}))
givenType, _ = data.GetType(val.([]interface{})[0])
valArr, _ := coerce.ToArray(val)
ValLen = len(valArr)
givenType, _ = data.GetType(valArr[0])
break
}
}
Expand Down
38 changes: 27 additions & 11 deletions operations/restructuring/map2table/operation_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package map2table

import (
"github.com/project-flogo/core/support/log"
"testing"

"github.com/project-flogo/core/support/log"

"github.com/stretchr/testify/assert"
)

func TestSample0(t *testing.T) {
//params := Params{}
opt := &Operation{logger : log.RootLogger(), params :&Params{Axis: 0}}
opt := &Operation{logger: log.RootLogger(), params: &Params{Axis: 0}}
var err error
inputs := make(map[string]interface{})
inputs["colOrder"] = []string{"a","b","c","d"}
inputs["map"] = map[string]interface{}{"a":[]interface{}{1,2,4}, "b":[]interface{}{3,5,6}, "c":[]interface{}{7,8,9}}
inputs["colOrder"] = []string{"a", "b", "c", "d"}
inputs["map"] = map[string]interface{}{"a": []interface{}{1, 2, 4}, "b": []interface{}{3, 5, 6}, "c": []interface{}{7, 8, 9}}

_, err = opt.Eval(inputs)

Expand All @@ -20,11 +23,11 @@ func TestSample0(t *testing.T) {
}
func TestSample1(t *testing.T) {
//params := Params{}
opt := &Operation{logger : log.RootLogger(), params :&Params{Axis: 1}}
opt := &Operation{logger: log.RootLogger(), params: &Params{Axis: 1}}
var err error
inputs := make(map[string]interface{})
inputs["colOrder"] = []string{"x","a","b","c","d"}
inputs["map"] = map[string]interface{}{"a":[]interface{}{1,2,4}, "b":[]interface{}{3,5,6}, "c":[]interface{}{7,8,9}}
inputs["colOrder"] = []string{"x", "a", "b", "c", "d"}
inputs["map"] = map[string]interface{}{"a": []interface{}{1, 2, 4}, "b": []interface{}{3, 5, 6}, "c": []interface{}{7, 8, 9}}

_, err = opt.Eval(inputs)

Expand All @@ -34,14 +37,27 @@ func TestSample1(t *testing.T) {

func TestSampleString(t *testing.T) {
//params := Params{}
opt := &Operation{logger : log.RootLogger(), params :&Params{Axis: 1}}
opt := &Operation{logger: log.RootLogger(), params: &Params{Axis: 1}}
var err error
inputs := make(map[string]interface{})
inputs["colOrder"] = []string{"x","a","b","c","d"}
inputs["map"] = map[string]interface{}{"a":[]interface{}{"a","b","c"}, "b":[]interface{}{"d","e","f"}, "c":[]interface{}{"g","h","k"}}
inputs["colOrder"] = []string{"x", "a", "b", "c", "d"}
inputs["map"] = map[string]interface{}{"a": []interface{}{"a", "b", "c"}, "b": []interface{}{"d", "e", "f"}, "c": []interface{}{"g", "h", "k"}}

_, err = opt.Eval(inputs)

assert.Nil(t, err)

}
}
func TestSingleInt(t *testing.T) {
//params := Params{}
opt := &Operation{logger: log.RootLogger(), params: &Params{Axis: 1}}
var err error
inputs := make(map[string]interface{})
inputs["colOrder"] = []string{"x", "a", "b", "c", "d"}
inputs["map"] = map[string]interface{}{"a": 1}

_, err = opt.Eval(inputs)

assert.Nil(t, err)

}

0 comments on commit e6ae264

Please sign in to comment.