Skip to content

Commit

Permalink
Bump jsonpath library to fix issue regarding filtering on nested array (
Browse files Browse the repository at this point in the history
#244) (#245)

* Bump jsonpath library to fix issue regarding filtering on nested array

* Update test for jsonpath

Co-authored-by: Tio Pramayudi <[email protected]>

Co-authored-by: Tio Pramayudi <[email protected]>
  • Loading branch information
tiopramayudi and tiopramayudi authored Apr 21, 2022
1 parent b8cb622 commit f6b8491
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/gojek/heimdall/v7 v7.0.2
github.com/gojek/merlin-pyspark-app v0.0.3
github.com/gojek/mlp v0.0.0-20201002030420-4e35e69a9ab8
github.com/gojekfarm/jsonpath v0.1.0
github.com/gojekfarm/jsonpath v0.1.1
github.com/golang-migrate/migrate/v4 v4.11.0
github.com/golang/geo v0.0.0-20210211234256-740aa86cb551
github.com/golang/protobuf v1.5.2
Expand Down
4 changes: 2 additions & 2 deletions api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,8 @@ github.com/gojek/valkyrie v0.0.0-20180215180059-6aee720afcdf h1:5xRGbUdOmZKoDXkG
github.com/gojek/valkyrie v0.0.0-20180215180059-6aee720afcdf/go.mod h1:QzhUKaYKJmcbTnCYCAVQrroCOY7vOOI8cSQ4NbuhYf0=
github.com/gojekfarm/gota v0.12.1-0.20220329041038-bdee6822d003 h1:P9ph+Dcd7xMe/GQ9k24T9NqVS6HRyrNqyscpV0HUBtM=
github.com/gojekfarm/gota v0.12.1-0.20220329041038-bdee6822d003/go.mod h1:0N1RwZc60ImjH0LMLUTDCvPWdtxk419HJScoigjR66k=
github.com/gojekfarm/jsonpath v0.1.0 h1:ofQpGrZiv75uO2mB1gTk5l9BmJLVIMB+uQh4bY2Nq7g=
github.com/gojekfarm/jsonpath v0.1.0/go.mod h1:1cPoGRnDKrtGXzs4z/IkEPosicPFZ0Drn2prBo7cyHM=
github.com/gojekfarm/jsonpath v0.1.1 h1:6GPJ+dBF6pPAQ536FmZw6trUD8uMXEeK//LZ7icgIy0=
github.com/gojekfarm/jsonpath v0.1.1/go.mod h1:1cPoGRnDKrtGXzs4z/IkEPosicPFZ0Drn2prBo7cyHM=
github.com/golang-migrate/migrate/v4 v4.11.0 h1:uqtd0ysK5WyBQ/T1K2uDIooJV0o2Obt6uPwP062DupQ=
github.com/golang-migrate/migrate/v4 v4.11.0/go.mod h1:nqbpDbckcYjsCD5I8q5+NI9Tkk7SVcmaF40Ax1eAWhg=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
Expand Down
93 changes: 93 additions & 0 deletions api/pkg/transformer/jsonpath/jsonpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ const (
"array_object": [
{"exist_key":1},
{"exist_key":2}
],
"inputs": [
{
"variable": [
{"name": "A", "value": 200}, {"name": "B", "value": 250}
]
},
{
"variable": [
{"name": "C", "value": 300}, {"name": "D", "value": 350}
]
}
]
}
`
Expand Down Expand Up @@ -279,6 +291,87 @@ func TestCompiledWithOption_LookupFromContainer(t *testing.T) {
wantErr: false,
err: nil,
},
{
desc: "filtering nested array",
opt: JsonPathOption{
JsonPath: "$.inputs[*].variable[?(@.value > 200)]",
},
sourceJSONs: jsonContainer,
want: []interface{}{
map[string]interface{}{
"name": "B",
"value": float64(250),
},
map[string]interface{}{
"name": "C",
"value": float64(300),
},
map[string]interface{}{
"name": "D",
"value": float64(350),
},
},
wantErr: false,
err: nil,
},
{
desc: "range nested array",
opt: JsonPathOption{
JsonPath: "$.inputs[*].variable[*]",
},
sourceJSONs: jsonContainer,
want: []interface{}{
map[string]interface{}{
"name": "A",
"value": float64(200),
},
map[string]interface{}{
"name": "B",
"value": float64(250),
},
map[string]interface{}{
"name": "C",
"value": float64(300),
},
map[string]interface{}{
"name": "D",
"value": float64(350),
},
},
wantErr: false,
err: nil,
},
{
desc: "access nested array",
opt: JsonPathOption{
JsonPath: "$.inputs[*].variable",
},
sourceJSONs: jsonContainer,
want: []interface{}{
[]interface{}{
map[string]interface{}{
"name": "A",
"value": float64(200),
},
map[string]interface{}{
"name": "B",
"value": float64(250),
},
},
[]interface{}{
map[string]interface{}{
"name": "C",
"value": float64(300),
},
map[string]interface{}{
"name": "D",
"value": float64(350),
},
},
},
wantErr: false,
err: nil,
},
}
for _, tC := range testCases {
t.Run(tC.desc, func(t *testing.T) {
Expand Down

0 comments on commit f6b8491

Please sign in to comment.