Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge various branch fixes together #15

Open
wants to merge 59 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
ab0b5d7
♻️ float to decimal & set DivisionPrecision = 8
frank-hsieh-asj Feb 17, 2022
43f83f6
Merge pull request #1 from ASJadeTech/refactory/float-to-decimal
asj-martin Feb 17, 2022
574f7f3
add regexp
tbal999 Jul 7, 2022
bfd1b96
Merge pull request #2 from ASJadeTech/main
tbal999 Jul 7, 2022
5e0f34e
Merge pull request #1 from xiatechs/feature/regex
tbal999 Jul 7, 2022
328dbf9
Merge pull request #3 from xiatechs/develop
tbal999 Jul 7, 2022
840ede8
add some new features to go-jsonata [xia]
tbal999 Sep 19, 2022
68dea73
further additions
tbal999 Sep 19, 2022
f6d3217
adjust contributing
tbal999 Sep 19, 2022
f627995
Merge pull request #4 from xiatechs/feature/xia1
tbal999 Sep 19, 2022
1abafe3
1.18
tbal999 Sep 19, 2022
f06761b
add @ to lexer
tbal999 Sep 21, 2022
9af3332
different approach
tbal999 Sep 21, 2022
74852c4
change name for new funcs
tbal999 Sep 22, 2022
36922a6
add obj merge func
tbal999 Sep 22, 2022
022afb9
Merge pull request #5 from xiatechs/feature/joinoperator
tbal999 Sep 22, 2022
e1c7a4c
make left join
tbal999 Sep 26, 2022
c5c577d
join enhancement
tbal999 Sep 27, 2022
bad44b7
fix
tbal999 Sep 27, 2022
ef957bf
add test
tbal999 Sep 27, 2022
e582d2a
test & gofmt
tbal999 Sep 27, 2022
4cc632d
update dev
Nov 29, 2022
42def18
add mutex
Dec 12, 2022
bb14382
another
Dec 12, 2022
03374d4
and another
Dec 12, 2022
45655f2
fix tests etc
Dec 12, 2022
2104ff5
Merge pull request #6 from xiatechs/feature/mutex
tbal999 Dec 12, 2022
71c66fe
thread safety (#7)
tbal999 Dec 12, 2022
5befb7d
add eval functionality (#9)
tbal999 Mar 14, 2023
4276483
Feature/eval (#10)
tbal999 Mar 15, 2023
42e6f55
add go timezones (#11)
tbal999 Mar 17, 2023
7957ab7
Modify date time string to match the layout provided (#12)
pocockn Mar 23, 2023
30f0186
Timeformats fix (#13)
pocockn Mar 23, 2023
ed4855f
Update to go 1.19
pocockn Mar 24, 2023
aac0abd
Bump to Go 1.20
pocockn Mar 24, 2023
928dc02
Time/localconsts (#14)
tbal999 Mar 28, 2023
49373f6
fix null bug (#15)
tbal999 Apr 13, 2023
4a6a7c0
test
golbanstefan May 18, 2023
6775490
improve the errors
golbanstefan May 18, 2023
e7e6c48
Merge branch 'main' into improve-errors
golbanstefan May 18, 2023
cc20d0a
solve cooments and logs
golbanstefan May 18, 2023
30e9103
solve cooments and logs
golbanstefan May 18, 2023
1861ad7
delete idea files
golbanstefan May 18, 2023
d58a160
Merge pull request #17 from xiatechs/improve-errors
golbanstefan May 18, 2023
44fd010
Allow empty arrays to be returned (#18)
Jarrah-libremfg May 30, 2023
bbead99
Json objects to document func (#19)
tbal999 Oct 2, 2023
0a4fc93
XC-1364 (#20)
tbal999 Oct 10, 2023
bf6cd95
Feature/xc 1539 (#21)
tbal999 Nov 9, 2023
bfdb0aa
add time date dimension functions (#22)
tbal999 Nov 17, 2023
48c87cf
add adjustments (#23)
tbal999 Nov 20, 2023
11a33a1
Enhancement to oneToMany function to add sql like join types (#25)
tbal999 Nov 27, 2023
834811c
fix offset (#26)
tbal999 Nov 29, 2023
d1badc0
Rename keys (#29)
JamesXiatech Dec 12, 2023
933f57f
fix bug (#30)
tbal999 Dec 12, 2023
5c4e36c
add fold function & goccy (#31)
tbal999 Dec 13, 2023
353b4d4
Update env.go
tbal999 Dec 13, 2023
98098e0
fix bug - 000 end to timestamp (#33)
tbal999 Mar 20, 2024
61ce7d5
Fix panic calling $distinct on array of arrays (#34)
Jarrah-libremfg Apr 17, 2024
72bb1f2
add monday-weekday (#35)
tbal999 Apr 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributing to blues/jsonata-go
# Contributing to blues/jsonata-go [xiatechs fork]

We love pull requests from everyone. By participating in this project, you
agree to abide by the Blues Inc [code of conduct].
Expand All @@ -18,7 +18,7 @@ clean up inconsistent whitespace )
* by closing [issues][]
* by reviewing patches

[issues]: https://github.com/blues/jsonata-go/issues
[issues]: https://github.com/xiatechs/jsonata-go/issues

## Submitting an Issue

Expand Down Expand Up @@ -55,7 +55,7 @@ clean up inconsistent whitespace )
* If you don't know how to add tests, please put in a PR and leave a comment asking for help.
We love helping!

[repo]: https://github.com/blues/jsonata-go/tree/master
[repo]: https://github.com/xiatechs/jsonata-go/tree/master
[fork]: https://help.github.com/articles/fork-a-repo/
[branch]:
https://help.github.com/articles/creating-and-deleting-branches-within-your-repository/
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ It currently has feature parity with jsonata-js 1.5.4. As well as a most of the

## Install

go get github.com/blues/jsonata-go
go get github.com/xiatechs/jsonata-go

## Usage

Expand All @@ -17,7 +17,7 @@ import (
"fmt"
"log"

jsonata "github.com/blues/jsonata-go"
jsonata "github.com/xiatechs/jsonata-go"
)

const jsonString = `
Expand Down Expand Up @@ -56,7 +56,7 @@ func main() {

## JSONata Server
A locally hosted version of [JSONata Exerciser](http://try.jsonata.org/)
for testing is [available here](https://github.com/blues/jsonata-go/jsonata-server).
for testing is [available here](https://github.com/xiatechs/jsonata-go/jsonata-server).

## JSONata tests
A CLI tool for running jsonata-go against the [JSONata test suite](https://github.com/jsonata-js/jsonata/tree/master/test/test-suite) is [available here](./jsonata-test).
Expand Down
6 changes: 3 additions & 3 deletions callable.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"regexp"
"strings"

"github.com/blues/jsonata-go/jlib"
"github.com/blues/jsonata-go/jparse"
"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jlib"
"github.com/xiatechs/jsonata-go/jparse"
"github.com/xiatechs/jsonata-go/jtypes"
)

type callableName struct {
Expand Down
4 changes: 2 additions & 2 deletions callable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"strings"
"testing"

"github.com/blues/jsonata-go/jparse"
"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jparse"
"github.com/xiatechs/jsonata-go/jtypes"
)

var (
Expand Down
7 changes: 7 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package config

var defaultDivisionPrecision int32 = 8

func GetDivisionPrecision() int32 {
return defaultDivisionPrecision
}
32 changes: 29 additions & 3 deletions env.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"strings"
"unicode/utf8"

"github.com/blues/jsonata-go/jlib"
"github.com/blues/jsonata-go/jparse"
"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jlib"
"github.com/xiatechs/jsonata-go/jparse"
"github.com/xiatechs/jsonata-go/jtypes"
)

type environment struct {
Expand Down Expand Up @@ -67,6 +67,32 @@ var (

var baseEnv = initBaseEnv(map[string]Extension{

/*
EXTENDED START
*/

"objmerge": {
Func: jlib.ObjMerge,
UndefinedHandler: defaultUndefinedHandler,
EvalContextHandler: nil,
},

"sjoin": {
Func: jlib.SimpleJoin,
UndefinedHandler: defaultUndefinedHandler,
EvalContextHandler: nil,
},

"unescape": {
Func: jlib.Unescape,
UndefinedHandler: defaultUndefinedHandler,
EvalContextHandler: defaultContextHandler,
},

/*
EXTENDED END
*/

// String functions

"string": {
Expand Down
2 changes: 1 addition & 1 deletion error.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"fmt"
"regexp"

"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jtypes"
)

// ErrUndefined is returned by the evaluation methods when
Expand Down
21 changes: 14 additions & 7 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import (
"reflect"
"sort"

"github.com/blues/jsonata-go/jlib"
"github.com/blues/jsonata-go/jparse"
"github.com/blues/jsonata-go/jtypes"
"github.com/shopspring/decimal"
"github.com/xiatechs/jsonata-go/config"
"github.com/xiatechs/jsonata-go/jlib"
"github.com/xiatechs/jsonata-go/jparse"
"github.com/xiatechs/jsonata-go/jtypes"
)

var undefined reflect.Value
Expand Down Expand Up @@ -990,19 +992,24 @@ func evalNumericOperator(node *jparse.NumericOperatorNode, data reflect.Value, e
return undefined, nil
}

lhsDecimal, rhsDecimal := decimal.NewFromFloat(lhs), decimal.NewFromFloat(rhs)

var x float64

switch node.Type {
case jparse.NumericAdd:
x = lhs + rhs
x = lhsDecimal.Add(rhsDecimal).RoundCeil(config.GetDivisionPrecision()).InexactFloat64()
case jparse.NumericSubtract:
x = lhs - rhs
x = lhsDecimal.Sub(rhsDecimal).RoundCeil(config.GetDivisionPrecision()).InexactFloat64()
case jparse.NumericMultiply:
x = lhs * rhs
x = lhsDecimal.Mul(rhsDecimal).Truncate(config.GetDivisionPrecision()).InexactFloat64()
case jparse.NumericDivide:
x = lhs / rhs
if !math.IsInf(x, 0) && !math.IsNaN(x) {
x = lhsDecimal.Div(rhsDecimal).RoundCeil(config.GetDivisionPrecision()).InexactFloat64()
}
case jparse.NumericModulo:
x = math.Mod(lhs, rhs)
x = lhsDecimal.Mod(rhsDecimal).Truncate(config.GetDivisionPrecision()).InexactFloat64()
default:
panicf("unrecognised numeric operator %q", node.Type)
}
Expand Down
6 changes: 3 additions & 3 deletions eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"strings"
"testing"

"github.com/blues/jsonata-go/jlib"
"github.com/blues/jsonata-go/jparse"
"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jlib"
"github.com/xiatechs/jsonata-go/jparse"
"github.com/xiatechs/jsonata-go/jtypes"
)

type evalTestCase struct {
Expand Down
2 changes: 1 addition & 1 deletion example_eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"fmt"
"log"

jsonata "github.com/blues/jsonata-go"
jsonata "github.com/xiatechs/jsonata-go"
)

const jsonString = `
Expand Down
2 changes: 1 addition & 1 deletion example_exts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"log"
"strings"

jsonata "github.com/blues/jsonata-go"
jsonata "github.com/xiatechs/jsonata-go"
)

//
Expand Down
15 changes: 13 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
module github.com/blues/jsonata-go
module github.com/xiatechs/jsonata-go

go 1.16
go 1.18

require (
github.com/shopspring/decimal v1.3.1
github.com/stretchr/testify v1.8.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
17 changes: 17 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
16 changes: 9 additions & 7 deletions jlib/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"fmt"
"reflect"

"github.com/blues/jsonata-go/jtypes"
"github.com/shopspring/decimal"
"github.com/xiatechs/jsonata-go/config"
"github.com/xiatechs/jsonata-go/jtypes"
)

// Sum returns the total of an array of numbers. If the array is
Expand All @@ -24,17 +26,17 @@ func Sum(v reflect.Value) (float64, error) {

v = jtypes.Resolve(v)

var sum float64
var sum decimal.Decimal

for i := 0; i < v.Len(); i++ {
n, ok := jtypes.AsNumber(v.Index(i))
if !ok {
return 0, fmt.Errorf("cannot call sum on an array with non-number types")
}
sum += n
sum = sum.Add(decimal.NewFromFloat(n))
}

return sum, nil
return sum.RoundCeil(config.GetDivisionPrecision()).InexactFloat64(), nil
}

// Max returns the largest value in an array of numbers. If the
Expand Down Expand Up @@ -115,15 +117,15 @@ func Average(v reflect.Value) (float64, error) {
return 0, jtypes.ErrUndefined
}

var sum float64
var sum decimal.Decimal

for i := 0; i < v.Len(); i++ {
n, ok := jtypes.AsNumber(v.Index(i))
if !ok {
return 0, fmt.Errorf("cannot call average on an array with non-number types")
}
sum += n
sum = sum.Add(decimal.NewFromFloat(n))
}

return sum / float64(v.Len()), nil
return sum.Div(decimal.NewFromInt(int64(v.Len()))).RoundCeil(config.GetDivisionPrecision()).InexactFloat64(), nil
}
2 changes: 1 addition & 1 deletion jlib/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"reflect"
"sort"

"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jtypes"
)

// Count (golint)
Expand Down
2 changes: 1 addition & 1 deletion jlib/boolean.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package jlib
import (
"reflect"

"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jtypes"
)

// Boolean (golint)
Expand Down
4 changes: 2 additions & 2 deletions jlib/date.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"strconv"
"time"

"github.com/blues/jsonata-go/jlib/jxpath"
"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jlib/jxpath"
"github.com/xiatechs/jsonata-go/jtypes"
)

// 2006-01-02T15:04:05.000Z07:00
Expand Down
4 changes: 2 additions & 2 deletions jlib/date_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"testing"
"time"

"github.com/blues/jsonata-go/jlib"
"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jlib"
"github.com/xiatechs/jsonata-go/jtypes"
)

func TestFromMillis(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion jlib/hof.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"reflect"

"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jtypes"
)

// Map (golint)
Expand Down
2 changes: 1 addition & 1 deletion jlib/jlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"reflect"
"time"

"github.com/blues/jsonata-go/jtypes"
"github.com/xiatechs/jsonata-go/jtypes"
)

func init() {
Expand Down
Loading