-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.go
76 lines (69 loc) · 1.89 KB
/
index.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package aerospike
import (
"database/sql/driver"
"fmt"
as "github.com/aerospike/aerospike-client-go/v6"
"github.com/viant/sqlparser"
"strings"
"time"
)
func (s *Statement) handleDropIndex(args []driver.NamedValue) (driver.Result, error) {
writePolicy := as.NewWritePolicy(0, 0)
err := s.client.DropIndex(writePolicy, s.dropIndex.Schema, s.dropIndex.Table, s.dropIndex.Name)
if s.dropIndex.IfExists {
return &result{}, nil
}
return &result{}, err
}
func (s *Statement) prepareDropIndex(SQL string) error {
dropIndex, err := sqlparser.ParseDropIndex(SQL)
if err != nil {
return err
}
s.dropIndex = dropIndex
if s.dropIndex.Schema == "" {
s.dropIndex.Schema = s.namespace
}
return nil
}
func (s *Statement) prepareCreateIndex(SQL string) error {
createIndex, err := sqlparser.ParseCreateIndex(SQL)
if err != nil {
return err
}
s.createIndex = createIndex
if s.createIndex.Schema == "" {
s.createIndex.Schema = s.namespace
}
return nil
}
func (s *Statement) handleCreateIndex(args []driver.NamedValue) (driver.Result, error) {
var indexType as.IndexType
switch strings.ToLower(s.createIndex.Type) {
case "numeric":
indexType = as.NUMERIC
case "string":
indexType = as.STRING
case "geo2dsphere":
indexType = as.GEO2DSPHERE
}
if len(s.createIndex.Columns) != 1 {
return nil, fmt.Errorf("unsupported secondaryIndex columns: %v", s.createIndex.Columns)
}
if indexType == "" {
return nil, fmt.Errorf("unsupported secondaryIndex type: %v", s.createIndex.Type)
}
writePolicy := as.NewWritePolicy(0, 0)
task, err := s.client.CreateIndex(writePolicy, s.createIndex.Schema, s.createIndex.Table, s.createIndex.Name, s.createIndex.Columns[0].Name, indexType)
for i := 0; i < 1000; i++ {
ok, err := task.IsDone()
if ok || err != nil {
if err == nil {
err = <-task.OnComplete()
}
return &result{}, err
}
time.Sleep(100 * time.Millisecond)
}
return &result{}, err
}