Skip to content

Commit 24fbd42

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 24fbd42

12 files changed

+339
-134
lines changed

CHANGELOG.md

+3
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

+6
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

+16-7
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,34 @@ var expectedOpts = map[string]interface{}{
7272
type ValidSchemeResolver struct {
7373
}
7474

75-
func (*ValidSchemeResolver) ResolveSpaceIndex(s, i interface{}) (uint32, uint32, error) {
76-
var spaceNo, indexNo uint32
75+
func (*ValidSchemeResolver) ResolveSpace(s interface{}) (uint32, error) {
76+
var spaceNo uint32
7777
if s != nil {
7878
spaceNo = uint32(s.(int))
7979
} else {
8080
spaceNo = defaultSpace
8181
}
82+
if spaceNo == invalidSpace {
83+
return 0, errors.New(invalidSpaceMsg)
84+
}
85+
return spaceNo, nil
86+
}
87+
88+
func (*ValidSchemeResolver) ResolveIndex(i interface{}, spaceNo uint32) (uint32, error) {
89+
var indexNo uint32
8290
if i != nil {
8391
indexNo = uint32(i.(int))
8492
} else {
8593
indexNo = defaultIndex
8694
}
87-
if spaceNo == invalidSpace {
88-
return 0, 0, errors.New(invalidSpaceMsg)
89-
}
9095
if indexNo == invalidIndex {
91-
return 0, 0, errors.New(invalidIndexMsg)
96+
return 0, errors.New(invalidIndexMsg)
9297
}
93-
return spaceNo, indexNo, nil
98+
return indexNo, nil
99+
}
100+
101+
func (*ValidSchemeResolver) NamesUseSupported() bool {
102+
return false
94103
}
95104

96105
var resolver ValidSchemeResolver

example_test.go

+1
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

+20-8
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

+1
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)