Skip to content

Commit d622dd5

Browse files
committed
fix
1 parent c860ee1 commit d622dd5

File tree

4 files changed

+16
-56
lines changed

4 files changed

+16
-56
lines changed

internal/table/session.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,9 @@ func (s *session) DescribeTable(
413413
var typ options.IndexType
414414
switch idx.Type.(type) {
415415
case *Ydb_Table.TableIndexDescription_GlobalAsyncIndex:
416-
typ = options.GlobalAsyncIndex()
416+
typ = options.IndexTypeGlobalAsync
417417
case *Ydb_Table.TableIndexDescription_GlobalIndex:
418-
typ = options.GlobalIndex()
418+
typ = options.IndexTypeGlobal
419419
}
420420
indexes[i] = options.IndexDescription{
421421
Name: idx.GetName(),

table/example_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func Example_createTable() {
8080
),
8181
options.WithIndex("idx_series_title",
8282
options.WithIndexColumns("title"),
83-
options.WithIndexType(options.GlobalAsyncIndex()),
83+
options.WithIndexType(options.IndexTypeGlobalAsync),
8484
),
8585
)
8686
},
@@ -166,7 +166,7 @@ func Example_alterTable() {
166166
options.WithAddIndex("idx_series_series_id",
167167
options.WithIndexColumns("series_id"),
168168
options.WithDataColumns("title"),
169-
options.WithIndexType(options.GlobalAsyncIndex()),
169+
options.WithIndexType(options.IndexTypeGlobalAsync),
170170
),
171171
options.WithDropIndex("idx_series_title"),
172172
options.WithAlterAttribute("hello", "world"),

table/options/models.go

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,11 @@ type IndexDescription struct {
4545

4646
//nolint:unused
4747
func (i IndexDescription) toYDB() *Ydb_Table.TableIndexDescription {
48-
res := &Ydb_Table.TableIndexDescription{
48+
return &Ydb_Table.TableIndexDescription{
4949
Name: i.Name,
5050
IndexColumns: i.IndexColumns,
5151
Status: i.Status,
5252
}
53-
if i.Type.Type() == IndexTypeGlobal {
54-
res.Type = &Ydb_Table.TableIndexDescription_GlobalIndex{}
55-
} else {
56-
res.Type = &Ydb_Table.TableIndexDescription_GlobalAsyncIndex{}
57-
}
58-
return res
5953
}
6054

6155
type Description struct {
@@ -277,50 +271,24 @@ func NewPartitioningSettings(ps *Ydb_Table.PartitioningSettings) PartitioningSet
277271
}
278272
}
279273

280-
type IndexTypeValue uint8
274+
type (
275+
IndexType uint8
276+
)
281277

282278
const (
283-
IndexTypeGlobal IndexTypeValue = iota
279+
IndexTypeGlobal = IndexType(iota)
284280
IndexTypeGlobalAsync
285281
)
286282

287-
type IndexType interface {
288-
setup(*indexDesc)
289-
Type() IndexTypeValue
290-
}
291-
292-
type globalIndex struct{}
293-
294-
func GlobalIndex() IndexType {
295-
return globalIndex{}
296-
}
297-
298-
func (globalIndex) setup(d *indexDesc) {
299-
d.Type = &Ydb_Table.TableIndex_GlobalIndex{
300-
GlobalIndex: new(Ydb_Table.GlobalIndex),
283+
func (t IndexType) ApplyIndexOption(d *indexDesc) {
284+
switch t {
285+
case IndexTypeGlobal:
286+
d.Type = &Ydb_Table.TableIndex_GlobalIndex{}
287+
case IndexTypeGlobalAsync:
288+
d.Type = &Ydb_Table.TableIndex_GlobalAsyncIndex{}
301289
}
302290
}
303291

304-
func (globalIndex) Type() IndexTypeValue {
305-
return IndexTypeGlobal
306-
}
307-
308-
type globalAsyncIndex struct{}
309-
310-
func GlobalAsyncIndex() IndexType {
311-
return globalAsyncIndex{}
312-
}
313-
314-
func (globalAsyncIndex) setup(d *indexDesc) {
315-
d.Type = &Ydb_Table.TableIndex_GlobalAsyncIndex{
316-
GlobalAsyncIndex: new(Ydb_Table.GlobalAsyncIndex),
317-
}
318-
}
319-
320-
func (globalAsyncIndex) Type() IndexTypeValue {
321-
return IndexTypeGlobalAsync
322-
}
323-
324292
type PartitioningMode byte
325293

326294
const (

table/options/options.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,16 +219,8 @@ func WithDataColumns(columns ...string) IndexOption {
219219
return dataColumns(columns)
220220
}
221221

222-
type indexType struct {
223-
t IndexType
224-
}
225-
226-
func (i indexType) ApplyIndexOption(d *indexDesc) {
227-
i.t.setup(d)
228-
}
229-
230222
func WithIndexType(t IndexType) IndexOption {
231-
return indexType{t: t}
223+
return t
232224
}
233225

234226
type columnFamilies []ColumnFamily

0 commit comments

Comments
 (0)