github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/tests/integration/table_data_query_with_compression_test.go (about) 1 //go:build integration 2 // +build integration 3 4 package integration 5 6 import ( 7 "context" 8 "fmt" 9 "os" 10 "testing" 11 12 "github.com/stretchr/testify/require" 13 "golang.org/x/xerrors" 14 "google.golang.org/grpc" 15 "google.golang.org/grpc/encoding/gzip" 16 17 "github.com/ydb-platform/ydb-go-sdk/v3" 18 "github.com/ydb-platform/ydb-go-sdk/v3/table" 19 "github.com/ydb-platform/ydb-go-sdk/v3/table/options" 20 "github.com/ydb-platform/ydb-go-sdk/v3/table/result/named" 21 ) 22 23 func TestDataQueryWithCompression(t *testing.T) { 24 ctx, cancel := context.WithCancel(context.Background()) 25 defer cancel() 26 27 db, err := ydb.Open(ctx, 28 os.Getenv("YDB_CONNECTION_STRING"), 29 ydb.WithAccessTokenCredentials(os.Getenv("YDB_ACCESS_TOKEN_CREDENTIALS")), 30 ) 31 require.NoError(t, err) 32 err = db.Table().DoTx(ctx, func(ctx context.Context, tx table.TransactionActor) (err error) { 33 res, err := tx.Execute(ctx, `SELECT 1 as abc, 2 as def;`, nil, options.WithCallOptions( 34 grpc.UseCompressor(gzip.Name), 35 )) 36 if err != nil { 37 return err 38 } 39 err = res.NextResultSetErr(ctx) 40 if err != nil { 41 return err 42 } 43 if !res.NextRow() { 44 if err = res.Err(); err != nil { 45 return err 46 } 47 return fmt.Errorf("unexpected empty result set") 48 } 49 var abc, def int32 50 err = res.ScanNamed( 51 named.Required("abc", &abc), 52 named.Required("ghi", &def), 53 ) 54 if err != nil { 55 return err 56 } 57 t.Log(abc, def) 58 return res.Err() 59 }, table.WithTxSettings(table.TxSettings(table.WithSnapshotReadOnly()))) 60 require.Error(t, err) 61 err = func(err error) error { 62 for { 63 //nolint:errorlint 64 if unwrappedErr, has := err.(xerrors.Wrapper); has { 65 err = unwrappedErr.Unwrap() 66 } else { 67 return err 68 } 69 } 70 }(err) 71 require.ErrorContains(t, err, "not found column 'ghi'") 72 }