@@ -5,16 +5,22 @@ import (
55
66 "github.com/jonboulle/clockwork"
77 "github.com/ydb-platform/ydb-go-genproto/Ydb_Table_V1"
8+ "github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
9+ "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Table"
810 "google.golang.org/grpc"
911
1012 "github.com/ydb-platform/ydb-go-sdk/v3/internal/allocator"
1113 "github.com/ydb-platform/ydb-go-sdk/v3/internal/pool"
1214 "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack"
1315 "github.com/ydb-platform/ydb-go-sdk/v3/internal/table/config"
16+ "github.com/ydb-platform/ydb-go-sdk/v3/internal/table/scanner"
17+ "github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
1418 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext"
1519 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
1620 "github.com/ydb-platform/ydb-go-sdk/v3/retry"
1721 "github.com/ydb-platform/ydb-go-sdk/v3/table"
22+ "github.com/ydb-platform/ydb-go-sdk/v3/table/options"
23+ "github.com/ydb-platform/ydb-go-sdk/v3/table/result"
1824 "github.com/ydb-platform/ydb-go-sdk/v3/trace"
1925)
2026
@@ -332,6 +338,87 @@ func (c *Client) BulkUpsert(
332338 return nil
333339}
334340
341+ func makeReadRowsRequest (
342+ a * allocator.Allocator ,
343+ sessionID string ,
344+ path string ,
345+ keys value.Value ,
346+ readRowOpts []options.ReadRowsOption ,
347+ ) * Ydb_Table.ReadRowsRequest {
348+ request := Ydb_Table.ReadRowsRequest {
349+ SessionId : sessionID ,
350+ Path : path ,
351+ Keys : value .ToYDB (keys , a ),
352+ }
353+ for _ , opt := range readRowOpts {
354+ if opt != nil {
355+ opt .ApplyReadRowsOption ((* options .ReadRowsDesc )(& request ), a )
356+ }
357+ }
358+
359+ return & request
360+ }
361+
362+ func makeReadRowsResponse (response * Ydb_Table.ReadRowsResponse , err error , isTruncated bool ) (result.Result , error ) {
363+ if err != nil {
364+ return nil , xerrors .WithStackTrace (err )
365+ }
366+
367+ if response .GetStatus () != Ydb .StatusIds_SUCCESS {
368+ return nil , xerrors .WithStackTrace (
369+ xerrors .FromOperation (response ),
370+ )
371+ }
372+
373+ return scanner .NewUnary (
374+ []* Ydb.ResultSet {response .GetResultSet ()},
375+ nil ,
376+ scanner .WithIgnoreTruncated (isTruncated ),
377+ ), nil
378+ }
379+
380+ func (c * Client ) ReadRows (
381+ ctx context.Context ,
382+ path string ,
383+ keys value.Value ,
384+ readRowOpts []options.ReadRowsOption ,
385+ retryOptions ... table.Option ,
386+ ) (_ result.Result , err error ) {
387+ var (
388+ a = allocator .New ()
389+ request = makeReadRowsRequest (a , "" , path , keys , readRowOpts )
390+ response * Ydb_Table.ReadRowsResponse
391+ )
392+ defer func () {
393+ a .Free ()
394+ }()
395+
396+ client := Ydb_Table_V1 .NewTableServiceClient (c .cc )
397+
398+ attempts , config := 0 , c .retryOptions (retryOptions ... )
399+ config .RetryOptions = append (config .RetryOptions ,
400+ retry .WithIdempotent (true ),
401+ retry .WithTrace (& trace.Retry {
402+ OnRetry : func (info trace.RetryLoopStartInfo ) func (trace.RetryLoopDoneInfo ) {
403+ return func (info trace.RetryLoopDoneInfo ) {
404+ attempts = info .Attempts
405+ }
406+ },
407+ }),
408+ )
409+ err = retry .Retry (ctx ,
410+ func (ctx context.Context ) (err error ) {
411+ attempts ++
412+ response , err = client .ReadRows (ctx , request )
413+
414+ return err
415+ },
416+ config .RetryOptions ... ,
417+ )
418+
419+ return makeReadRowsResponse (response , err , c .config .IgnoreTruncated ())
420+ }
421+
335422func executeTxOperation (ctx context.Context , c * Client , op table.TxOperation , tx table.Transaction ) (err error ) {
336423 if panicCallback := c .config .PanicCallback (); panicCallback != nil {
337424 defer func () {
0 commit comments