Skip to content

Commit e136353

Browse files
committed
fixed slo and optional.castTo
1 parent c36e0ba commit e136353

File tree

5 files changed

+32
-17
lines changed

5 files changed

+32
-17
lines changed

.github/workflows/slo.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
workload_build_context0: ../..
5050
workload_build_options0: -f Dockerfile --build-arg SRC_PATH=native/table --build-arg JOB_NAME=workload-native-table
5151

52-
language_id1: 'query'
52+
language_id1: 'native/query'
5353
workload_path1: 'tests/slo'
5454
language1: 'Go SDK native over query-service'
5555
workload_build_context1: ../..

internal/value/value.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,14 @@ func (v *optionalValue) castTo(dst interface{}) error {
13151315
inner := reflect.Indirect(ptr)
13161316

13171317
if inner.Kind() != reflect.Pointer {
1318+
if v.value == nil {
1319+
if ptr.CanAddr() {
1320+
ptr.SetZero()
1321+
}
1322+
1323+
return nil
1324+
}
1325+
13181326
if err := v.value.castTo(ptr.Interface()); err != nil {
13191327
return xerrors.WithStackTrace(err)
13201328
}

tests/slo/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.21 as build
1+
FROM golang:1.22 as build
22
ARG SRC_PATH
33
ARG JOB_NAME
44
COPY . /src

tests/slo/internal/generator/row.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import "time"
44

55
type RowID = uint64
66

7+
//nolint:tagalign
78
type Row struct {
8-
Hash uint64 `gorm:"column:hash;primarykey;autoIncrement:false" xorm:"pk 'hash'"`
9-
ID RowID `gorm:"column:id;primarykey;autoIncrement:false" xorm:"pk 'id'"` //nolint:tagalign
10-
PayloadStr *string `gorm:"column:payload_str" xorm:"'payload_str'"` //nolint:tagalign
11-
PayloadDouble *float64 `gorm:"column:payload_double" xorm:"'payload_double'"` //nolint:tagalign
12-
PayloadTimestamp *time.Time `gorm:"column:payload_timestamp" xorm:"'payload_timestamp'"` //nolint:tagalign
13-
PayloadHash uint64 `gorm:"column:payload_hash" xorm:"'payload_hash'"` //nolint:tagalign
9+
Hash uint64 `sql:"hash" gorm:"column:hash;primarykey;autoIncrement:false" xorm:"pk 'hash'"`
10+
ID RowID `sql:"id" gorm:"column:id;primarykey;autoIncrement:false" xorm:"pk 'id'"`
11+
PayloadStr *string `sql:"payload_str" gorm:"column:payload_str" xorm:"'payload_str'"`
12+
PayloadDouble *float64 `sql:"payload_double" gorm:"column:payload_double" xorm:"'payload_double'"`
13+
PayloadTimestamp *time.Time `sql:"payload_timestamp" gorm:"column:payload_timestamp" xorm:"'payload_timestamp'"`
14+
PayloadHash uint64 `sql:"payload_hash" gorm:"column:payload_hash" xorm:"'payload_hash'"`
1415
}

tests/slo/native/query/storage.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package main
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
7+
"io"
68
"path"
79
"strconv"
810
"time"
@@ -120,20 +122,23 @@ func (s *Storage) Read(ctx context.Context, entryID generator.RowID) (_ generato
120122

121123
rs, err := res.NextResultSet(ctx)
122124
if err != nil {
125+
if errors.Is(err, io.EOF) {
126+
return nil
127+
}
128+
123129
return err
124130
}
125131

126132
row, err := rs.NextRow(ctx)
127133
if err != nil {
134+
if errors.Is(err, io.EOF) {
135+
return nil
136+
}
137+
128138
return err
129139
}
130140

131-
err = row.ScanNamed(
132-
query.Named("id", &e.ID),
133-
query.Named("payload_str", &e.PayloadStr),
134-
query.Named("payload_double", &e.PayloadDouble),
135-
query.Named("payload_timestamp", &e.PayloadTimestamp),
136-
)
141+
err = row.ScanStruct(&e, query.WithAllowMissingColumnsFromSelect())
137142
if err != nil {
138143
return err
139144
}
@@ -244,9 +249,10 @@ func (s *Storage) dropTable(ctx context.Context) error {
244249

245250
return s.db.Query().Do(ctx,
246251
func(ctx context.Context, session query.Session) error {
247-
_, _, err := session.Execute(ctx, `
248-
DROP TABLE `+"`"+path.Join(s.prefix, s.cfg.Table)+"`"+`
249-
`)
252+
_, _, err := session.Execute(ctx,
253+
fmt.Sprintf("DROP TABLE `%s`", path.Join(s.prefix, s.cfg.Table)),
254+
query.WithTxControl(query.NoTx()),
255+
)
250256

251257
return err
252258
},

0 commit comments

Comments
 (0)