Union is buggy
on99 opened this issue · comments
on99 commented
package main
import (
"fmt"
"github.com/kelindar/column"
)
func main() {
statistics := column.NewCollection()
// schema
(statistics.CreateColumn("d_a", column.ForString()))
statistics.CreateIndex("d_a_1", "d_a", func(r column.Reader) bool { return r.String() == "1" })
statistics.CreateIndex("d_a_2", "d_a", func(r column.Reader) bool { return r.String() == "2" })
statistics.CreateIndex("d_a_3", "d_a", func(r column.Reader) bool { return r.String() == "3" })
// insert
statistics.InsertObject(map[string]interface{}{
"d_a": "1",
})
statistics.InsertObject(map[string]interface{}{
"d_a": "2",
})
statistics.InsertObject(map[string]interface{}{
"d_a": "3",
})
(statistics.Query(func(tx *column.Txn) error {
fmt.Println(tx.With("d_a_1").Count()) // 1, correct
return nil
}))
(statistics.Query(func(tx *column.Txn) error {
fmt.Println(tx.With("d_a_2").Count()) // 1, correct
return nil
}))
(statistics.Query(func(tx *column.Txn) error {
fmt.Println(tx.With("d_a_3").Count()) // 1, correct
return nil
}))
(statistics.Query(func(tx *column.Txn) error {
fmt.Println(tx.Union("d_a_1", "d_a_2").Count()) // 3, incorrect, should be 2
return nil
}))
(statistics.Query(func(tx *column.Txn) error {
fmt.Println(tx.Union("d_a_1", "d_a_3").Count()) // 3, incorrect, should be 2
return nil
}))
(statistics.Query(func(tx *column.Txn) error {
fmt.Println(tx.Union("d_a_2", "d_a_3").Count()) // 3, incorrect, should be 2
return nil
}))
(statistics.Query(func(tx *column.Txn) error {
fmt.Println(tx.With("d_a_1", "d_a_2").Count()) // 0, correct
return nil
}))
(statistics.Query(func(tx *column.Txn) error {
fmt.Println(tx.With("d_a_1", "d_a_3").Count()) // 0, correct
return nil
}))
(statistics.Query(func(tx *column.Txn) error {
fmt.Println(tx.With("d_a_2", "d_a_3").Count()) // 0, correct
return nil
}))
(statistics.Query(func(tx *column.Txn) error {
fmt.Println(tx.With("d_a_1").Union("d_a_2").Count()) // 2, correct
return nil
}))
(statistics.Query(func(tx *column.Txn) error {
fmt.Println(tx.With("d_a_1").Union("d_a_3").Count()) // 2, correct
return nil
}))
(statistics.Query(func(tx *column.Txn) error {
fmt.Println(tx.With("d_a_2").Union("d_a_3").Count()) // 2, correct
return nil
}))
}
William Dreese commented
@on99 Looks like a new transaction's index is copied from the collection's fill bitmap, so all Union calls after init (but only before any other indexing function), are neglected
Roman Atachiants commented
Thanks @Dreeseaw for looking into this