Skip to content

Commit

Permalink
* Added table.Session.ReadRows
Browse files Browse the repository at this point in the history
  • Loading branch information
asmyasnikov committed Aug 1, 2023
1 parent b2dd070 commit 47e0630
Show file tree
Hide file tree
Showing 12 changed files with 336 additions and 17 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
env:
VERSION_CHANGE: ${{ github.event.inputs.version-change }}
RELEASE_CANDIDATE: ${{ github.event.inputs.release-candidate }}
VERSION_FILE: internal/meta/version.go
VERSION_FILE: internal/version/version.go
CHANGELOG_FILE: CHANGELOG.md
GITHUB_TOKEN: ${{ secrets.YDB_PLATFORM_BOT_TOKEN_REPO }}
steps:
Expand All @@ -39,9 +39,9 @@ jobs:
echo "CHANGELOG empty"
exit 1;
fi;
MAJOR=$(cat $VERSION_FILE | grep VersionMajor | sed -e 's/^.*\ \(=\ \)*\(\"\)*\([0-9]*\)\(\"\)*.*/\3/g');
MINOR=$(cat $VERSION_FILE | grep VersionMinor | sed -e 's/^.*\ \(=\ \)*\(\"\)*\([0-9]*\)\(\"\)*.*/\3/g');
PATCH=$(cat $VERSION_FILE | grep VersionPatch | sed -e 's/^.*\ \(=\ \)*\(\"\)*\([0-9]*\)\(\"\)*.*/\3/g');
MAJOR=$(cat $VERSION_FILE | grep Major | sed -e 's/^.*\ \(=\ \)*\(\"\)*\([0-9]*\)\(\"\)*.*/\3/g');
MINOR=$(cat $VERSION_FILE | grep Minor | sed -e 's/^.*\ \(=\ \)*\(\"\)*\([0-9]*\)\(\"\)*.*/\3/g');
PATCH=$(cat $VERSION_FILE | grep Patch | sed -e 's/^.*\ \(=\ \)*\(\"\)*\([0-9]*\)\(\"\)*.*/\3/g');
LAST_TAG="v$MAJOR.$MINOR.$PATCH";
if [ "$VERSION_CHANGE" = "MINOR" ]
then
Expand All @@ -57,8 +57,8 @@ jobs:
RC=$(git tag | grep "v$MAJOR.$MINOR.$PATCH-rc" | wc -l);
TAG="v$MAJOR.$MINOR.$PATCH-rc$RC";
else
sed -e 's/VersionMinor = "\([0-9]*\)"/VersionMinor = "'$MINOR'"/g' -i $VERSION_FILE;
sed -e 's/VersionPatch = "\([0-9]*\)"/VersionPatch = "'$PATCH'"/g' -i $VERSION_FILE;
sed -e 's/Minor = "\([0-9]*\)"/Minor = "'$MINOR'"/g' -i $VERSION_FILE;
sed -e 's/Patch = "\([0-9]*\)"/Patch = "'$PATCH'"/g' -i $VERSION_FILE;
git add $VERSION_FILE;
echo "## v$MAJOR.$MINOR.$PATCH" >> $CHANGELOG_FILE.tmp
cat $CHANGELOG_FILE >> $CHANGELOG_FILE.tmp
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Added `table.Session.ReadRows`

## v3.48.8
* Fixed `sugar.RemoveRecursive()` for column table type

Expand Down
6 changes: 3 additions & 3 deletions examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ require (
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/syndtr/goleveldb v1.0.0 // indirect
github.com/yandex-cloud/go-genproto v0.0.0-20220815090733-4c139c0154e2 // indirect
github.com/ydb-platform/ydb-go-genproto v0.0.0-20230528143953-42c825ace222 // indirect
github.com/ydb-platform/ydb-go-genproto v0.0.0-20230710134411-552fdf84e4f1 // indirect
github.com/ydb-platform/ydb-go-sdk-metrics v0.16.3 // indirect
github.com/ydb-platform/ydb-go-yc-metadata v0.5.4 // indirect
golang.org/x/crypto v0.6.0 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/mod v0.7.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/tools v0.1.12 // indirect
golang.org/x/tools v0.3.0 // indirect
google.golang.org/grpc v1.53.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
lukechampine.com/uint128 v1.1.1 // indirect
Expand Down
57 changes: 57 additions & 0 deletions examples/go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/golang-jwt/jwt/v4 v4.4.1
github.com/google/uuid v1.3.0
github.com/jonboulle/clockwork v0.3.0
github.com/ydb-platform/ydb-go-genproto v0.0.0-20230528143953-42c825ace222
github.com/ydb-platform/ydb-go-genproto v0.0.0-20230710134411-552fdf84e4f1
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
google.golang.org/grpc v1.53.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/ydb-platform/ydb-go-genproto v0.0.0-20230528143953-42c825ace222 h1:8ddsk8HKBkVPH8w3k81si6SeCVJIAtw8dnw+s3h0ciE=
github.com/ydb-platform/ydb-go-genproto v0.0.0-20230528143953-42c825ace222/go.mod h1:Er+FePu1dNUieD+XTMDduGpQuCPssK5Q4BjF+IIXJ3I=
github.com/ydb-platform/ydb-go-genproto v0.0.0-20230710134411-552fdf84e4f1 h1:+nKxgNmwZXpWqFDfQfFhXlnd2AfABNE8Z2QEBdmrxRg=
github.com/ydb-platform/ydb-go-genproto v0.0.0-20230710134411-552fdf84e4f1/go.mod h1:Er+FePu1dNUieD+XTMDduGpQuCPssK5Q4BjF+IIXJ3I=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down
45 changes: 45 additions & 0 deletions internal/table/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,51 @@ func (s *session) StreamReadTable(
), nil
}

func (s *session) ReadRows(
ctx context.Context,
path string,
keys types.Value,
opts ...options.ReadRowsOption,
) (_ result.Result, err error) {
var (
a = allocator.New()
request = Ydb_Table.ReadRowsRequest{
SessionId: s.id,
Path: path,
Keys: value.ToYDB(keys, a),
}
response *Ydb_Table.ReadRowsResponse
)
defer func() {
a.Free()
}()

for _, opt := range opts {
if opt != nil {
opt.ApplyReadRowsOption((*options.ReadRowsDesc)(&request), a)
}
}

response, err = s.tableService.ReadRows(ctx, &request)
if err != nil {
return nil, xerrors.WithStackTrace(err)
}

if response.GetStatus() != Ydb.StatusIds_SUCCESS {
return nil, xerrors.WithStackTrace(
xerrors.Operation(
xerrors.FromOperation(response),
),
)
}

return scanner.NewUnary(
[]*Ydb.ResultSet{response.GetResultSet()},
nil,
scanner.WithIgnoreTruncated(s.config.IgnoreTruncated()),
), nil
}

// StreamExecuteScanQuery scan-reads table at given path with given options.
//
// Note that given ctx controls the lifetime of the whole read, not only this
Expand Down
10 changes: 10 additions & 0 deletions table/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,7 @@ func WithExecuteScanQueryStats(stats ExecuteScanQueryStatsType) ExecuteScanQuery
}

var (
_ ReadRowsOption = readColumnsOption{}
_ ReadTableOption = readOrderedOption{}
_ ReadTableOption = readKeyRangeOption{}
_ ReadTableOption = readGreaterOrEqualOption{}
Expand All @@ -987,6 +988,11 @@ var (
)

type (
ReadRowsDesc Ydb_Table.ReadRowsRequest
ReadRowsOption interface {
ApplyReadRowsOption(*ReadRowsDesc, *allocator.Allocator)
}

ReadTableDesc Ydb_Table.ReadTableRequest
ReadTableOption interface {
ApplyReadTableOption(*ReadTableDesc, *allocator.Allocator)
Expand Down Expand Up @@ -1027,6 +1033,10 @@ func (x readLessOption) ApplyReadTableOption(desc *ReadTableDesc, a *allocator.A
}
}

func (columns readColumnsOption) ApplyReadRowsOption(desc *ReadRowsDesc, a *allocator.Allocator) {
desc.Columns = append(desc.Columns, columns...)
}

func (columns readColumnsOption) ApplyReadTableOption(desc *ReadTableDesc, a *allocator.Allocator) {
desc.Columns = append(desc.Columns, columns...)
}
Expand Down
7 changes: 7 additions & 0 deletions table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ type Session interface {
opts ...options.BulkUpsertOption,
) (err error)

ReadRows(
ctx context.Context,
path string,
keys types.Value,
opts ...options.ReadRowsOption,
) (_ result.Result, err error)

BeginTransaction(
ctx context.Context,
tx *TransactionSettings,
Expand Down
71 changes: 71 additions & 0 deletions tests/integration/kv_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//go:build integration
// +build integration

package integration

import (
"context"
"fmt"
"os"
"testing"

"github.com/ydb-platform/ydb-go-sdk/v3/internal/version"
"github.com/ydb-platform/ydb-go-sdk/v3/table"
"github.com/ydb-platform/ydb-go-sdk/v3/table/options"
"github.com/ydb-platform/ydb-go-sdk/v3/table/result/named"
"github.com/ydb-platform/ydb-go-sdk/v3/table/types"
)

func TestKeyValue(t *testing.T) {
if version.Lt(os.Getenv("YDB_VERSION"), "23.3") {
t.Skip("read rows not allowed in YDB version '" + os.Getenv("YDB_VERSION") + "'")
}

var (
scope = newScope(t)
driver = scope.Driver()
tablePath = scope.TablePath()
id = int64(100500)
value = "test value"
)

// set
err := driver.Table().Do(scope.Ctx, func(ctx context.Context, s table.Session) error {
return s.BulkUpsert(ctx, tablePath, types.ListValue(types.StructValue(
types.StructFieldValue("id", types.Int64Value(id)),
types.StructFieldValue("val", types.TextValue(value)),
)))
})
scope.Require.NoError(err)

// get
err = driver.Table().Do(scope.Ctx, func(ctx context.Context, s table.Session) error {
rows, err := s.ReadRows(ctx, tablePath, types.ListValue(types.Int64Value(id)),
options.ReadColumn("val"),
)
if err != nil {
return err
}
defer func() {
_ = rows.Close()
}()
if !rows.HasNextResultSet() {
return fmt.Errorf("no result sets")
}
if !rows.HasNextRow() {
return fmt.Errorf("no rows")
}
if rows.CurrentResultSet().RowCount() != 1 {
return fmt.Errorf("wrong rows count (%d)", rows.CurrentResultSet().RowCount())
}
if rows.CurrentResultSet().ColumnCount() != 1 {
return fmt.Errorf("wrong column count (%d)", rows.CurrentResultSet().ColumnCount())
}
var actualValue int64
if err := rows.ScanNamed(named.Optional("val", &actualValue)); err != nil {
return err
}
return rows.Err()
})
scope.Require.NoError(err)
}
10 changes: 5 additions & 5 deletions tests/slo/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.20

require (
github.com/prometheus/client_golang v1.14.0
github.com/ydb-platform/gorm-driver v0.0.6-0.20230529184330-9104dd08ecae
github.com/ydb-platform/ydb-go-sdk/v3 v3.47.3
github.com/ydb-platform/gorm-driver v0.1.1
github.com/ydb-platform/ydb-go-sdk/v3 v3.48.7
golang.org/x/sync v0.1.0
golang.org/x/time v0.3.0
gorm.io/gorm v1.25.1
Expand Down Expand Up @@ -33,8 +33,8 @@ require (
github.com/prometheus/procfs v0.8.0 // indirect
github.com/syndtr/goleveldb v1.0.0 // indirect
github.com/yandex-cloud/go-genproto v0.0.0-20230403093326-123923969dc6 // indirect
github.com/ydb-platform/ydb-go-genproto v0.0.0-20230528143953-42c825ace222 // indirect
github.com/ydb-platform/ydb-go-sdk-auth-environ v0.1.3 // indirect
github.com/ydb-platform/ydb-go-genproto v0.0.0-20230710134411-552fdf84e4f1 // indirect
github.com/ydb-platform/ydb-go-sdk-auth-environ v0.2.0 // indirect
github.com/ydb-platform/ydb-go-yc v0.10.2 // indirect
github.com/ydb-platform/ydb-go-yc-metadata v0.5.3 // indirect
golang.org/x/net v0.9.0 // indirect
Expand All @@ -48,4 +48,4 @@ require (

replace github.com/ydb-platform/ydb-go-sdk/v3 => ../../.

replace xorm.io/xorm => github.com/ydb-platform/xorm v0.0.3
replace xorm.io/xorm => github.com/ydb-platform/xorm v0.0.6
Loading

0 comments on commit 47e0630

Please sign in to comment.