Skip to content

Commit fe77212

Browse files
ajroetkerAJ Roetker
andauthored
Add float array support (#38)
* Add float array support * Add array support to insert statements too * Modernize the qlbridge repo * test: Add test for CREATE INDEX IF NOT EXISTS WITH syntax * test: Add test for CREATE INDEX IF NOT EXISTS WITH syntax * Add support for index expressions * Add parsing support for indexes * Port Jan's geodistance functions * Fix test --------- Co-authored-by: AJ Roetker <aj.roetker@contentstack.com>
1 parent 85f4541 commit fe77212

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+679
-388
lines changed

datasource/context.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var (
2727
)
2828

2929
// MessageConversion convert values of type schema.Message.
30-
func MessageConversion(vals []interface{}) []schema.Message {
30+
func MessageConversion(vals []any) []schema.Message {
3131
msgs := make([]schema.Message, len(vals))
3232
for i, v := range vals {
3333
msgs[i] = v.(schema.Message)
@@ -69,8 +69,8 @@ type (
6969
func NewSqlDriverMessage(id uint64, row []driver.Value) *SqlDriverMessage {
7070
return &SqlDriverMessage{IdVal: id, Vals: row}
7171
}
72-
func (m *SqlDriverMessage) Id() uint64 { return m.IdVal }
73-
func (m *SqlDriverMessage) Body() interface{} { return m.Vals }
72+
func (m *SqlDriverMessage) Id() uint64 { return m.IdVal }
73+
func (m *SqlDriverMessage) Body() any { return m.Vals }
7474
func (m *SqlDriverMessage) ToMsgMap(colidx map[string]int) *SqlDriverMessageMap {
7575
return NewSqlDriverMessageMap(m.IdVal, m.Vals, colidx)
7676
}
@@ -111,7 +111,7 @@ func (m *SqlDriverMessageMap) SetKeyHashed(key string) {
111111
hasher64.Write([]byte(key))
112112
m.IdVal = hasher64.Sum64()
113113
}
114-
func (m *SqlDriverMessageMap) Body() interface{} { return m }
114+
func (m *SqlDriverMessageMap) Body() any { return m }
115115
func (m *SqlDriverMessageMap) Values() []driver.Value { return m.Vals }
116116
func (m *SqlDriverMessageMap) SetRow(row []driver.Value) { m.Vals = row }
117117
func (m *SqlDriverMessageMap) Ts() time.Time { return time.Time{} }
@@ -150,21 +150,21 @@ func NewContextSimple() *ContextSimple {
150150
func NewContextSimpleData(data map[string]value.Value) *ContextSimple {
151151
return &ContextSimple{Data: data, ts: time.Now(), cursor: 0}
152152
}
153-
func NewContextSimpleNative(data map[string]interface{}) *ContextSimple {
153+
func NewContextSimpleNative(data map[string]any) *ContextSimple {
154154
vals := make(map[string]value.Value)
155155
for k, v := range data {
156156
vals[k] = value.NewValue(v)
157157
}
158158
return &ContextSimple{Data: vals, ts: time.Now(), cursor: 0, namespacing: true}
159159
}
160-
func NewContextMap(data map[string]interface{}, namespacing bool) *ContextSimple {
160+
func NewContextMap(data map[string]any, namespacing bool) *ContextSimple {
161161
vals := make(map[string]value.Value)
162162
for k, v := range data {
163163
vals[k] = value.NewValue(v)
164164
}
165165
return &ContextSimple{Data: vals, ts: time.Now(), cursor: 0, namespacing: namespacing}
166166
}
167-
func NewContextMapTs(data map[string]interface{}, namespacing bool, ts time.Time) *ContextSimple {
167+
func NewContextMapTs(data map[string]any, namespacing bool, ts time.Time) *ContextSimple {
168168
vals := make(map[string]value.Value)
169169
for k, v := range data {
170170
vals[k] = value.NewValue(v)
@@ -178,7 +178,7 @@ func NewContextSimpleTs(data map[string]value.Value, ts time.Time) *ContextSimpl
178178
func (m *ContextSimple) SupportNamespacing() { m.namespacing = true }
179179
func (m *ContextSimple) All() map[string]value.Value { return m.Data }
180180
func (m *ContextSimple) Row() map[string]value.Value { return m.Data }
181-
func (m *ContextSimple) Body() interface{} { return m }
181+
func (m *ContextSimple) Body() any { return m }
182182
func (m *ContextSimple) Id() uint64 { return m.keyval }
183183
func (m *ContextSimple) Ts() time.Time { return m.ts }
184184
func (m ContextSimple) Get(key string) (value.Value, bool) {

datasource/context_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var (
1717
vals = []driver.Value{1, "name", time.Now()}
1818
cols = []string{"id", "name", "time"}
1919
colidx = map[string]int{"id": 0, "name": 1, "time": 2}
20-
data = make(map[string]interface{})
20+
data = make(map[string]any)
2121
datav = make(map[string]value.Value)
2222
)
2323

@@ -66,14 +66,14 @@ func TestContext(t *testing.T) {
6666
t.Run("test.context", contextReaderTests(ctx))
6767
}
6868

69-
ctxValues := make([]interface{}, len(ctxall))
69+
ctxValues := make([]any, len(ctxall))
7070
for i, ctx := range ctxall {
7171
ctxValues[i] = ctx
7272
}
7373
// make sure it doesn't panic
7474
datasource.MessageConversion(ctxValues)
7575

76-
mv2 := make(map[string]interface{})
76+
mv2 := make(map[string]any)
7777
for i, val := range vals {
7878
mv2[cols[i]] = val
7979
}

datasource/context_wrapper.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type ContextWrapper struct {
2020
s *state
2121
}
2222

23-
func NewContextWrapper(val interface{}) *ContextWrapper {
23+
func NewContextWrapper(val any) *ContextWrapper {
2424
s := state{}
2525
return &ContextWrapper{reflect.ValueOf(val), &s}
2626
}
@@ -80,7 +80,7 @@ var (
8080
fmtStringerType = reflect.TypeOf((*fmt.Stringer)(nil)).Elem()
8181
)
8282

83-
func (s *state) errorf(format string, args ...interface{}) reflect.Value {
83+
func (s *state) errorf(format string, args ...any) reflect.Value {
8484
s.err = fmt.Errorf(format, args...)
8585
return zero
8686
}
@@ -90,7 +90,7 @@ func (s *state) errorf(format string, args ...interface{}) reflect.Value {
9090
// receiver is the value being walked along the chain.
9191
func (s *state) evalFieldChain(dot, receiver reflect.Value, node *expr.IdentityNode, ident []string, args []expr.Node, final reflect.Value) reflect.Value {
9292
n := len(ident)
93-
for i := 0; i < n-1; i++ {
93+
for i := range n - 1 {
9494
receiver = s.evalField(dot, ident[i], node, nil, zero, receiver)
9595
}
9696
// Now if it's a method, it gets the arguments.
@@ -152,7 +152,7 @@ func (s *state) evalField(dot reflect.Value, fieldName string, node expr.Node, a
152152
tagName := strings.ToLower(fieldName)
153153
// Wow, this is pretty bruttaly expensive
154154
// Iterate over all available fields and read the tag value
155-
for i := 0; i < receiver.NumField(); i++ {
155+
for i := range receiver.NumField() {
156156
// Get the field, returns https://golang.org/pkg/reflect/#StructField
157157
field := receiver.Type().Field(i)
158158

datasource/context_wrapper_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestStructWrapper(t *testing.T) {
5353

5454
readers := []expr.ContextReader{
5555
datasource.NewContextWrapper(user),
56-
datasource.NewContextSimpleNative(map[string]interface{}{
56+
datasource.NewContextSimpleNative(map[string]any{
5757
"str1": "str1",
5858
"int1": 1,
5959
"t1": t1,
@@ -62,7 +62,7 @@ func TestStructWrapper(t *testing.T) {
6262
}
6363

6464
nc := datasource.NewNestedContextReader(readers, time.Now())
65-
expected := value.NewMapValue(map[string]interface{}{
65+
expected := value.NewMapValue(map[string]any{
6666
"str1": "str1",
6767
"int1": 1,
6868
"Name": "Yoda",

datasource/datatypes.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (m *TimeValue) Time() time.Time {
6161
return time.Time(*m)
6262
}
6363

64-
func (m *TimeValue) Scan(src interface{}) error {
64+
func (m *TimeValue) Scan(src any) error {
6565

6666
var t time.Time
6767
var dstr string
@@ -113,7 +113,7 @@ func (m JsonWrapper) Value() (driver.Value, error) {
113113
return []byte(m), nil
114114
}
115115

116-
func (m *JsonWrapper) Scan(src interface{}) error {
116+
func (m *JsonWrapper) Scan(src any) error {
117117
var jsonBytes []byte
118118
switch src.(type) {
119119
case string:
@@ -127,7 +127,7 @@ func (m *JsonWrapper) Scan(src interface{}) error {
127127
return nil
128128
}
129129

130-
func (m *JsonWrapper) Unmarshal(v interface{}) error {
130+
func (m *JsonWrapper) Unmarshal(v any) error {
131131
return json.Unmarshal([]byte(*m), v)
132132
}
133133

@@ -160,7 +160,7 @@ func (m JsonHelperScannable) Value() (driver.Value, error) {
160160

161161
// Scan the database/sql interface for scanning sql byte vals into this
162162
// typed structure.
163-
func (m *JsonHelperScannable) Scan(src interface{}) error {
163+
func (m *JsonHelperScannable) Scan(src any) error {
164164
var jsonBytes []byte
165165
switch tv := src.(type) {
166166
case string:
@@ -203,7 +203,7 @@ func (m StringArray) Value() (driver.Value, error) {
203203

204204
// Scan the database/sql interface for scanning sql byte vals into this
205205
// typed structure.
206-
func (m *StringArray) Scan(src interface{}) error {
206+
func (m *StringArray) Scan(src any) error {
207207

208208
var srcBytes []byte
209209
switch val := src.(type) {

datasource/files/filesource_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (m *testSource) Setup(s *schema.Schema) error {
5656
fileStore = os.Getenv("FILESTORE")
5757
}
5858

59-
settings := u.JsonHelper(map[string]interface{}{
59+
settings := u.JsonHelper(map[string]any{
6060
"path": "baseball",
6161
"filetype": "csv",
6262
"type": fileStore,

datasource/files/json_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (m *jsonTestSource) Setup(ss *schema.Schema) error {
3939
if os.Getenv("FILESTORE") != "" {
4040
fileStore = os.Getenv("FILESTORE")
4141
}
42-
settings := u.JsonHelper(map[string]interface{}{
42+
settings := u.JsonHelper(map[string]any{
4343
"path": "github",
4444
"filetype": "json",
4545
"format": "github_json",

datasource/introspect.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func IntrospectTable(tbl *schema.Table, iter schema.Iterator) error {
7171
//u.Debugf("add field? %+v", fld)
7272
//u.Debugf("%s = %v type: %T vt:%s new? %v", k, val, val, valType, !exists)
7373
}
74-
case map[string]interface{}:
74+
case map[string]any:
7575
tbl.AddFieldType(k, value.JsonType)
7676
default:
7777
u.Debugf("not implemented: %T", val)
@@ -116,9 +116,9 @@ func IntrospectTable(tbl *schema.Table, iter schema.Iterator) error {
116116
//u.Debugf("add field? %+v", fld)
117117
//u.Debugf("%s = %v type: %T vt:%s new? %v", k, val, val, valType, !exists)
118118
}
119-
case map[string]interface{}:
119+
case map[string]any:
120120
tbl.AddFieldType(k, value.JsonType)
121-
case []interface{}:
121+
case []any:
122122
tbl.AddFieldType(k, value.JsonType)
123123
case nil:
124124
// hm.....

datasource/json.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func (m *JsonSource) Next() schema.Message {
170170
}
171171

172172
func (m *JsonSource) jsonDefaultLine(line []byte) (schema.Message, error) {
173-
jm := make(map[string]interface{})
173+
jm := make(map[string]any)
174174
err := json.Unmarshal(line, &jm)
175175
if err != nil {
176176
return nil, fmt.Errorf("could not read json line: %w %s", err, string(line))

datasource/key.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (m KeyCol) Key() driver.Value { return m.Val }
4444
// Given a Where expression, lets try to create a key which
4545
//
4646
// requires form `idenity = "value"`
47-
func KeyFromWhere(wh interface{}) schema.Key {
47+
func KeyFromWhere(wh any) schema.Key {
4848
switch n := wh.(type) {
4949
case *rel.SqlWhere:
5050
return KeyFromWhere(n.Expr)

0 commit comments

Comments
 (0)