Index on time field will fail select statement
Created by: nekrondev
I created an index on a time field. If I execute a select statement including the time field ql will report the following error:
panic: EncodeScalars: unsupported type: time.Time in []interface {}{time.Time{sec:63590021584, nsec:621565300, loc:(*time.Location)(0xa83ee0)}, 0}
I broke down program execution flow to find at file.go func (x *fileIndex) Seek(indexedValues []interface{}) (indexIterator, bool, error) where EncodeScalars() is called. EncodeScalars has currently no transformation from time.Time to []byte.
Current workaround is to not create indices on time fields.
Example code snippet:
func test() {
INITTABLE := `BEGIN TRANSACTION;
CREATE TABLE foo (bar int, when time, );
INSERT INTO foo VALUES (1, parseTime("2006-01-02", "2017-02-01"));
CREATE INDEX FooWhen ON foo (when);
COMMIT;`
dboption := &ql.Options{CanCreate: true}
os.Remove("test.db")
db, _ = ql.OpenFile("test.db", dboption)
_, _, err := db.Run(ql.NewRWCtx(), INITTABLE)
if err != nil {
panic(err)
}
sel := ql.MustCompile(`SELECT * FROM foo WHERE when > $1;`)
rss, _, err := db.Execute(ctx, sel, time.Now())
if err != nil {
panic(err)
}
for _, rs := range rss {
if err := rs.Do(false, func(data []interface{}) (bool, error) {
fmt.Println(data)
return true, nil
}); err != nil {
panic(err)
}
fmt.Println("----")
}
}
`