@@ -11,11 +11,14 @@ import (
1111 "testing"
1212 "time"
1313
14+ "github.com/stretchr/testify/require"
15+
1416 "github.com/ydb-platform/ydb-go-sdk/v3"
1517 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xtest"
1618 "github.com/ydb-platform/ydb-go-sdk/v3/log"
1719 "github.com/ydb-platform/ydb-go-sdk/v3/table"
1820 "github.com/ydb-platform/ydb-go-sdk/v3/table/options"
21+ "github.com/ydb-platform/ydb-go-sdk/v3/table/result/indexed"
1922 "github.com/ydb-platform/ydb-go-sdk/v3/table/types"
2023 "github.com/ydb-platform/ydb-go-sdk/v3/trace"
2124)
@@ -29,6 +32,7 @@ func TestLongStream(t *testing.T) {
2932 err error
3033 upsertRowsCount = 100000
3134 batchSize = 10000
35+ expectedCheckSum = uint64 (4999950000 )
3236 ctx = xtest .Context (t )
3337 )
3438
@@ -146,6 +150,60 @@ func TestLongStream(t *testing.T) {
146150 if upserted != uint32 (upsertRowsCount ) {
147151 t .Fatalf ("wrong rows count: %v, expected: %d" , upserted , upsertRowsCount )
148152 }
153+ err := db .Table ().Do (ctx , func (ctx context.Context , s table.Session ) error {
154+ _ , res , err := s .Execute (ctx , table .DefaultTxControl (),
155+ "SELECT CAST(COUNT(*) AS Uint64) FROM `" + path .Join (db .Name (), folder , tableName )+ "`;" ,
156+ nil ,
157+ )
158+ if err != nil {
159+ return err
160+ }
161+ if ! res .NextResultSet (ctx ) {
162+ return fmt .Errorf ("no result sets" )
163+ }
164+ if ! res .NextRow () {
165+ return fmt .Errorf ("no rows" )
166+ }
167+ var rowsFromDb uint64
168+ if err := res .ScanWithDefaults (indexed .Required (& rowsFromDb )); err != nil {
169+ return err
170+ }
171+ if rowsFromDb != uint64 (upsertRowsCount ) {
172+ return fmt .Errorf ("wrong rows count: %d, expected: %d" ,
173+ rowsFromDb ,
174+ upsertRowsCount ,
175+ )
176+ }
177+ return res .Err ()
178+ }, table .WithIdempotent ())
179+ require .NoError (t , err )
180+ err = db .Table ().Do (ctx , func (ctx context.Context , s table.Session ) error {
181+ _ , res , err := s .Execute (ctx , table .DefaultTxControl (),
182+ "SELECT CAST(SUM(val) AS Uint64) FROM `" + path .Join (db .Name (), folder , tableName )+ "`;" ,
183+ nil ,
184+ )
185+ if err != nil {
186+ return err
187+ }
188+ if ! res .NextResultSet (ctx ) {
189+ return fmt .Errorf ("no result sets" )
190+ }
191+ if ! res .NextRow () {
192+ return fmt .Errorf ("no rows" )
193+ }
194+ var checkSumFromDb uint64
195+ if err := res .ScanWithDefaults (indexed .Required (& checkSumFromDb )); err != nil {
196+ return err
197+ }
198+ if checkSumFromDb != expectedCheckSum {
199+ return fmt .Errorf ("wrong checksum: %d, expected: %d" ,
200+ checkSumFromDb ,
201+ expectedCheckSum ,
202+ )
203+ }
204+ return res .Err ()
205+ }, table .WithIdempotent ())
206+ require .NoError (t , err )
149207 })
150208 })
151209 })
@@ -178,6 +236,7 @@ func TestLongStream(t *testing.T) {
178236 var (
179237 start = time .Now ()
180238 rowsCount = 0
239+ checkSum = uint64 (0 )
181240 )
182241 res , err := s .StreamExecuteScanQuery (ctx ,
183242 "SELECT val FROM `" + path .Join (db .Name (), folder , tableName )+ "`;" , nil ,
@@ -192,6 +251,11 @@ func TestLongStream(t *testing.T) {
192251 count := 0
193252 for res .NextRow () {
194253 count ++
254+ var val int64
255+ if err = res .ScanWithDefaults (indexed .Required (& val )); err != nil {
256+ return err
257+ }
258+ checkSum += uint64 (val )
195259 }
196260 rowsCount += count
197261 time .Sleep (discoveryInterval )
@@ -206,6 +270,12 @@ func TestLongStream(t *testing.T) {
206270 time .Since (start ),
207271 )
208272 }
273+ if checkSum != expectedCheckSum {
274+ return fmt .Errorf ("wrong checksum: %d, expected: %d" ,
275+ checkSum ,
276+ expectedCheckSum ,
277+ )
278+ }
209279 return res .Err ()
210280 },
211281 table .WithIdempotent (),
@@ -224,6 +294,7 @@ func TestLongStream(t *testing.T) {
224294 var (
225295 start = time .Now ()
226296 rowsCount = 0
297+ checkSum = uint64 (0 )
227298 )
228299 res , err := s .StreamReadTable (ctx , path .Join (db .Name (), folder , tableName ), options .ReadColumn ("val" ))
229300 if err != nil {
@@ -236,6 +307,11 @@ func TestLongStream(t *testing.T) {
236307 count := 0
237308 for res .NextRow () {
238309 count ++
310+ var val int64
311+ if err = res .ScanWithDefaults (indexed .Required (& val )); err != nil {
312+ return err
313+ }
314+ checkSum += uint64 (val )
239315 }
240316 rowsCount += count
241317 time .Sleep (discoveryInterval )
@@ -250,6 +326,12 @@ func TestLongStream(t *testing.T) {
250326 time .Since (start ),
251327 )
252328 }
329+ if checkSum != expectedCheckSum {
330+ return fmt .Errorf ("wrong checksum: %d, expected: %d" ,
331+ checkSum ,
332+ expectedCheckSum ,
333+ )
334+ }
253335 return res .Err ()
254336 },
255337 table .WithIdempotent (),
0 commit comments