kelindar / column

High-performance, columnar, in-memory store with bitmap indexing in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Union is buggy

on99 opened this issue · comments

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
	}))
}

@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

Thanks @Dreeseaw for looking into this