kelindar / column

High-performance, columnar, in-memory store with bitmap indexing in Go
MIT License
1.44k stars 57 forks source link

Duplicate key records getting inserted #57

Closed mxs00 closed 2 years ago

mxs00 commented 2 years ago

Thanks for such an excellent implementation, your efforts are commendable.

I am able to insert multiple records with same key, is this default behavior? if column has been flagged ForKey then should it allows for duplicate keys to be inserted?

// Create a new columnar collection type Tcolumns struct { players *column.Collection }

func (gC *Tcolumns) LoadData() {

gC.players = column.NewCollection()

gC.players.CreateColumn("dataelementid", column.ForKey())
gC.players.CreateColumn("periodid", column.ForFloat64())
gC.players.CreateColumn("sourceid", column.ForFloat64())
gC.players.CreateColumn("catid", column.ForFloat64())
gC.players.CreateColumn("attribid", column.ForFloat64())
gC.players.CreateColumn("value", column.ForEnum())

// Load the items into the collection
loaded := loadFixture("pem1.json")
gC.players.Query(func(txn *column.Txn) error {
    for _, v := range loaded {
        txn.InsertObject(v)
    }
    return nil
})

gC.players.Query(func(txn *column.Txn) error {
    b := []byte(`{"dataelementid": 56594, "periodid": 58044, "sourceid": 48464, "catid": 244, "attribid": 244, "value": "blah"}`)
    var f column.Object
    if err := json.Unmarshal(b, &f); err != nil {
        panic(err)
    }
    // fmt.Println(f)       
    // fmt.Println(b)

    txn.InsertObject(f)
    c := []byte(`{"dataelementid": 56594, "periodid": 58044, "sourceid": 48464, "catid": 244, "attribid": 244, "value": "blah"}`)
            //n := map[string]interface{}b
    var g column.Object
    if err := json.Unmarshal(c, &g); err != nil {
        panic(err)
    }
    // fmt.Println(f)       
    // fmt.Println(b)

    txn.InsertObject(g)
    return nil
})

}

kelindar commented 2 years ago

Good point, will need to add a check to avoid inserting duplicates in the first place.