Skip to content

Commit b0848b9

Browse files
author
Dean Karn
authored
fix AND evaluating RHS if LHS is false (#13)
1 parent 1c227fb commit b0848b9

File tree

6 files changed

+39
-8
lines changed

6 files changed

+39
-8
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [0.6.1] - 2023-05-25
10+
### Fixed
11+
- Fixed AND and OR not early exiting evaluation.
12+
913
## [0.6.0] - 2023-01-05
1014
### Added
1115
- Added new `_uppercase_` & `_title_` COERCE identifiers.
@@ -58,7 +62,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5862
### Added
5963
- Initial conversion from https://github.com/rust-playground/ksql.
6064

61-
[Unreleased]: https://github.com/go-playground/ksql/compare/v0.6.0...HEAD
65+
[Unreleased]: https://github.com/go-playground/ksql/compare/v0.6.1...HEAD
66+
[0.6.1]: https://github.com/go-playground/ksql/compare/v0.6.0...v0.6.1
6267
[0.6.0]: https://github.com/go-playground/ksql/compare/v0.5.1...v0.6.0
6368
[0.5.1]: https://github.com/go-playground/ksql/compare/v0.5.0...v0.5.1
6469
[0.5.0]: https://github.com/go-playground/ksql/compare/v0.4.0...v0.5.0

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ksql
22
=====
3-
![Project status](https://img.shields.io/badge/version-0.5.1-green.svg)
3+
![Project status](https://img.shields.io/badge/version-0.6.1-green.svg)
44
[![GoDoc](https://godoc.org/github.com/go-playground/ksql?status.svg)](https://pkg.go.dev/github.com/go-playground/ksql)
55
![License](https://img.shields.io/dub/l/vibe-d.svg)
66

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ go 1.18
44

55
require (
66
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
7-
github.com/go-playground/pkg/v5 v5.11.0
7+
github.com/go-playground/itertools v0.1.0
8+
github.com/go-playground/pkg/v5 v5.18.0
89
github.com/stretchr/testify v1.8.1
910
github.com/tidwall/gjson v1.14.4
1011
)
1112

1213
require (
1314
github.com/davecgh/go-spew v1.1.1 // indirect
14-
github.com/go-playground/itertools v0.1.0 // indirect
1515
github.com/pmezard/go-difflib v1.0.0 // indirect
1616
github.com/tidwall/match v1.1.1 // indirect
1717
github.com/tidwall/pretty v1.2.0 // indirect

go.sum

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoU
33
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
44
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
55
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6+
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
67
github.com/go-playground/itertools v0.1.0 h1:isiUTLIViAz4J3qWrowvRoOYWSXy2ubkXKNJfujE3Sc=
78
github.com/go-playground/itertools v0.1.0/go.mod h1:+TD1WVpn32jr+GpvO+nnb2xXD45SSzt18Fo/C0y9PJE=
8-
github.com/go-playground/pkg/v5 v5.11.0 h1:yYYmh0RLKBxiLbEwO7HZtp8XVDDuyIqHmhtrmuO0nsg=
9-
github.com/go-playground/pkg/v5 v5.11.0/go.mod h1:eT8XZeFHnqZkfkpkbI8ayjfCw9GohV2/j8STbVmoR6s=
9+
github.com/go-playground/pkg/v5 v5.18.0 h1:qnYuhWhwLdWj6ut9jagFjaiUI6PZTo3SafR5Um9w214=
10+
github.com/go-playground/pkg/v5 v5.18.0/go.mod h1:eT8XZeFHnqZkfkpkbI8ayjfCw9GohV2/j8STbVmoR6s=
1011
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
1112
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1213
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=

parser.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,7 @@ func (e eq) Calculate(src []byte) (any, error) {
879879
if err != nil {
880880
return nil, err
881881
}
882+
882883
return reflect.DeepEqual(left, right), nil
883884
}
884885

@@ -1027,6 +1028,7 @@ func (n not) Calculate(src []byte) (any, error) {
10271028
if err != nil {
10281029
return nil, err
10291030
}
1031+
10301032
switch t := value.(type) {
10311033
case bool:
10321034
return !t, nil
@@ -1047,6 +1049,14 @@ func (o or) Calculate(src []byte) (any, error) {
10471049
if err != nil {
10481050
return nil, err
10491051
}
1052+
1053+
switch t := left.(type) {
1054+
case bool:
1055+
if t {
1056+
return true, nil
1057+
}
1058+
}
1059+
10501060
right, err := o.right.Calculate(src)
10511061
if err != nil {
10521062
return nil, err
@@ -1076,6 +1086,16 @@ func (a and) Calculate(src []byte) (any, error) {
10761086
if err != nil {
10771087
return nil, err
10781088
}
1089+
1090+
switch t := left.(type) {
1091+
case bool:
1092+
if !t {
1093+
return false, nil
1094+
}
1095+
default:
1096+
return false, nil
1097+
}
1098+
10791099
right, err := a.right.Calculate(src)
10801100
if err != nil {
10811101
return nil, err

parser_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package ksql
22

33
import (
4+
"github.com/stretchr/testify/require"
45
"testing"
56
"time"
6-
7-
"github.com/stretchr/testify/require"
87
)
98

109
func TestParser(t *testing.T) {
@@ -620,6 +619,12 @@ func TestParser(t *testing.T) {
620619
src: `{"name":"mr."}`,
621620
expected: "Mr.",
622621
},
622+
{
623+
name: "NOT NULL AND",
624+
exp: `.MyValue != NULL && .MyValue > 19`,
625+
src: `{}`,
626+
expected: false,
627+
},
623628
}
624629

625630
for _, tc := range tests {

0 commit comments

Comments
 (0)