Skip to content

Commit f2a0b39

Browse files
committed
api: support IPROTO_FEATURE_SPACE_AND_INDEX_NAMES
Support `IPROTO_FEATURE_SPACE_AND_INDEX_NAMES` for Tarantool version >= 3.0.0-alpha. It allows to use space and index names instead of their IDs. `ResolveSpaceIndex` function for `SchemaResolver` interface split into two: `ResolveSpace` and `ResolveIndex`. `NamesUseSupported` function added into the interface to get information if usage of space and index names is supported. Closes #338
1 parent a664c6b commit f2a0b39

File tree

12 files changed

+348
-134
lines changed

12 files changed

+348
-134
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
2222
- Support `crud.schema` request (#336)
2323
- Support `IPROTO_WATCH_ONCE` request type for Tarantool
2424
version >= 3.0.0-alpha1 (#337)
25+
- Support `IPROTO_FEATURE_SPACE_AND_INDEX_NAMES` for Tarantool
26+
version >= 3.0.0-alpha1 (#338). It allows to use space and index names instead
27+
of their IDs
2528

2629
### Changed
2730

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,12 @@ and user may cancel it in process.
239239
* `iproto.Feature` type used instead of `ProtocolFeature`.
240240
* `iproto.IPROTO_FEATURE_` constants used instead of local ones.
241241

242+
#### Schema changes
243+
244+
`ResolveSpaceIndex` function for `SchemaResolver` interface split into two:
245+
`ResolveSpace` and `ResolveIndex`. `NamesUseSupported` function added into the
246+
interface to get information if usage of space and index names is supported.
247+
242248
## Contributing
243249

244250
See [the contributing guide](CONTRIBUTING.md) for detailed instructions on how

crud/request_test.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/tarantool/go-tarantool/v2"
1414
"github.com/tarantool/go-tarantool/v2/crud"
15+
"github.com/tarantool/go-tarantool/v2/test_helpers"
1516
)
1617

1718
const invalidSpaceMsg = "invalid space"
@@ -72,25 +73,38 @@ var expectedOpts = map[string]interface{}{
7273
type ValidSchemeResolver struct {
7374
}
7475

75-
func (*ValidSchemeResolver) ResolveSpaceIndex(s, i interface{}) (uint32, uint32, error) {
76-
var spaceNo, indexNo uint32
76+
func (*ValidSchemeResolver) ResolveSpace(s interface{}) (uint32, error) {
77+
var spaceNo uint32
7778
if s != nil {
7879
spaceNo = uint32(s.(int))
7980
} else {
8081
spaceNo = defaultSpace
8182
}
83+
if spaceNo == invalidSpace {
84+
return 0, errors.New(invalidSpaceMsg)
85+
}
86+
return spaceNo, nil
87+
}
88+
89+
func (*ValidSchemeResolver) ResolveIndex(i interface{}, spaceNo uint32) (uint32, error) {
90+
var indexNo uint32
8291
if i != nil {
8392
indexNo = uint32(i.(int))
8493
} else {
8594
indexNo = defaultIndex
8695
}
87-
if spaceNo == invalidSpace {
88-
return 0, 0, errors.New(invalidSpaceMsg)
89-
}
9096
if indexNo == invalidIndex {
91-
return 0, 0, errors.New(invalidIndexMsg)
97+
return 0, errors.New(invalidIndexMsg)
98+
}
99+
return indexNo, nil
100+
}
101+
102+
func (*ValidSchemeResolver) NamesUseSupported() bool {
103+
isLess, err := test_helpers.IsTarantoolVersionLess(3, 0, 0)
104+
if err != nil {
105+
return false
92106
}
93-
return spaceNo, indexNo, nil
107+
return !isLess
94108
}
95109

96110
var resolver ValidSchemeResolver

example_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ func ExampleProtocolVersion() {
634634
// Connector client protocol feature: IPROTO_FEATURE_ERROR_EXTENSION
635635
// Connector client protocol feature: IPROTO_FEATURE_WATCHERS
636636
// Connector client protocol feature: IPROTO_FEATURE_PAGINATION
637+
// Connector client protocol feature: IPROTO_FEATURE_SPACE_AND_INDEX_NAMES
637638
// Connector client protocol feature: IPROTO_FEATURE_WATCH_ONCE
638639
}
639640

export_test.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"net"
66
"time"
77

8+
"github.com/tarantool/go-iproto"
89
"github.com/vmihailenco/msgpack/v5"
910
)
1011

@@ -25,39 +26,50 @@ func RefImplPingBody(enc *msgpack.Encoder) error {
2526

2627
// RefImplSelectBody is reference implementation for filling of a select
2728
// request's body.
28-
func RefImplSelectBody(enc *msgpack.Encoder, space, index, offset, limit uint32, iterator Iter,
29-
key, after interface{}, fetchPos bool) error {
30-
return fillSelect(enc, space, index, offset, limit, iterator, key, after, fetchPos)
29+
func RefImplSelectBody(enc *msgpack.Encoder, space, index interface{},
30+
offset, limit uint32, iterator Iter, key, after interface{}, fetchPos bool) error {
31+
iprotoSpaceKey := iproto.IPROTO_SPACE_ID
32+
iprotoIndexKey := iproto.IPROTO_INDEX_ID
33+
if _, ok := space.(string); ok {
34+
iprotoSpaceKey = iproto.IPROTO_SPACE_NAME
35+
}
36+
if _, ok := index.(string); ok {
37+
iprotoIndexKey = iproto.IPROTO_INDEX_NAME
38+
}
39+
return fillSelect(enc, space, index, offset, limit, iterator, key, after,
40+
fetchPos, iprotoSpaceKey, iprotoIndexKey)
3141
}
3242

3343
// RefImplInsertBody is reference implementation for filling of an insert
3444
// request's body.
3545
func RefImplInsertBody(enc *msgpack.Encoder, space uint32, tuple interface{}) error {
36-
return fillInsert(enc, space, tuple)
46+
return fillInsert(enc, space, tuple, iproto.IPROTO_SPACE_ID)
3747
}
3848

3949
// RefImplReplaceBody is reference implementation for filling of a replace
4050
// request's body.
4151
func RefImplReplaceBody(enc *msgpack.Encoder, space uint32, tuple interface{}) error {
42-
return fillInsert(enc, space, tuple)
52+
return fillInsert(enc, space, tuple, iproto.IPROTO_SPACE_ID)
4353
}
4454

4555
// RefImplDeleteBody is reference implementation for filling of a delete
4656
// request's body.
4757
func RefImplDeleteBody(enc *msgpack.Encoder, space, index uint32, key interface{}) error {
48-
return fillDelete(enc, space, index, key)
58+
return fillDelete(enc, space, index, key,
59+
iproto.IPROTO_SPACE_ID, iproto.IPROTO_INDEX_ID)
4960
}
5061

5162
// RefImplUpdateBody is reference implementation for filling of an update
5263
// request's body.
5364
func RefImplUpdateBody(enc *msgpack.Encoder, space, index uint32, key, ops interface{}) error {
54-
return fillUpdate(enc, space, index, key, ops)
65+
return fillUpdate(enc, space, index, key, ops,
66+
iproto.IPROTO_SPACE_ID, iproto.IPROTO_INDEX_ID)
5567
}
5668

5769
// RefImplUpsertBody is reference implementation for filling of an upsert
5870
// request's body.
5971
func RefImplUpsertBody(enc *msgpack.Encoder, space uint32, tuple, ops interface{}) error {
60-
return fillUpsert(enc, space, tuple, ops)
72+
return fillUpsert(enc, space, tuple, ops, iproto.IPROTO_SPACE_ID)
6173
}
6274

6375
// RefImplCallBody is reference implementation for filling of a call or call17

protocol.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ var clientProtocolInfo ProtocolInfo = ProtocolInfo{
5656
iproto.IPROTO_FEATURE_ERROR_EXTENSION,
5757
iproto.IPROTO_FEATURE_WATCHERS,
5858
iproto.IPROTO_FEATURE_PAGINATION,
59+
iproto.IPROTO_FEATURE_SPACE_AND_INDEX_NAMES,
5960
iproto.IPROTO_FEATURE_WATCH_ONCE,
6061
},
6162
}

0 commit comments

Comments
 (0)