Skip to content

Commit 216ea35

Browse files
committed
modified set registration ttl as uint32
1 parent e9acebb commit 216ea35

4 files changed

Lines changed: 29 additions & 6 deletions

File tree

go.mod

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
module github.com/viant/sqlparser
22

3-
go 1.17
3+
go 1.21.3
4+
5+
toolchain go1.21.12
46

57
require (
6-
github.com/stretchr/testify v1.8.1
7-
github.com/viant/parsly v0.3.2-0.20231120160314-11ec855ce00a
8+
github.com/stretchr/testify v1.8.4
9+
github.com/viant/parsly v0.3.3-0.20240717150634-e1afaedb691b
810
)
911

1012
require (

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
1010
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
1111
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
1212
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
13+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
1314
github.com/viant/parsly v0.3.2-0.20231120160314-11ec855ce00a h1:H+7xS8C8Ywjxc0EfiKL9m+A7AF6JqkJKu5W+7zus/W0=
1415
github.com/viant/parsly v0.3.2-0.20231120160314-11ec855ce00a/go.mod h1:4PKQzioRT9R99ceIhZ6tCD3tp0H0n2dEoIOaLulVvrg=
16+
github.com/viant/parsly v0.3.3-0.20240717150634-e1afaedb691b h1:3q166tV28yFdbFV+tXXjH7ViKAmgAgGdoWzMtvhQv28=
17+
github.com/viant/parsly v0.3.3-0.20240717150634-e1afaedb691b/go.mod h1:85fneXJbErKMGhSQto3A5ElTQCwl3t74U9cSV0waBHw=
1518
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1619
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1720
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

schema.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"github.com/viant/parsly"
66
"github.com/viant/sqlparser/schema"
7+
"math"
78
"strings"
89
)
910

@@ -71,11 +72,17 @@ func parseRegisterSet(cursor *parsly.Cursor, destination *schema.RegisterSet) er
7172
return cursor.NewError(setKeywordMatcher)
7273
}
7374

74-
ttl64, err := match.Int(cursor)
75+
ttl64, err := match.Uint(cursor)
7576
if err != nil {
7677
return fmt.Errorf("parseregisterset unable to get int value due to: %w", err)
7778
}
78-
destination.TTL = int(ttl64)
79+
80+
ttlUint32, err := uint64ToUint32(ttl64)
81+
if err != nil {
82+
return fmt.Errorf("parseregisterset unable to get uint32 value due to: %w", err)
83+
}
84+
85+
destination.TTL = ttlUint32
7986
}
8087

8188
match = cursor.MatchAfterOptional(whitespaceMatcher, selectorMatcher)
@@ -90,3 +97,14 @@ func parseRegisterSet(cursor *parsly.Cursor, destination *schema.RegisterSet) er
9097
destination.Spec = strings.TrimSpace(string(cursor.Input[cursor.Pos:]))
9198
return nil
9299
}
100+
101+
func uint64ToUint32(value uint64) (uint32, error) {
102+
if value > math.MaxUint32 {
103+
return 0, fmt.Errorf("value %d is out of range for uint32, max value accepted: %d", value, math.MaxUint32)
104+
}
105+
106+
if value < 0 {
107+
return 0, fmt.Errorf("value %d is out of range for uint32, min value accepted: %d", value, 0)
108+
}
109+
return uint32(value), nil
110+
}

schema/register.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ type Register struct {
99

1010
type RegisterSet struct {
1111
Register
12-
TTL int
12+
TTL uint32
1313
}

0 commit comments

Comments
 (0)