column icon indicating copy to clipboard operation
column copied to clipboard

Unset a column?

Open delaneyj opened this issue 1 year ago • 4 comments

const nPos = 9000
const nPosVel = 1000

func BenchmarkIterColumn(b *testing.B) {
	b.StopTimer()
	entities := column.NewCollection()
	if err := errors.Join(
		entities.CreateColumn("px", column.ForFloat64()),
		entities.CreateColumn("py", column.ForFloat64()),
		entities.CreateColumn("vx", column.ForFloat64()),
		entities.CreateColumn("vy", column.ForFloat64()),
		entities.CreateColumn("foo", column.ForBool()),
	); err != nil {
		b.Fatal(err)
	}

	entities.Query(func(txn *column.Txn) error {
		for i := 0; i < nPos; i++ {
			_, err := txn.Insert(func(r column.Row) error {
				r.SetFloat64("px", 1.0)
				r.SetFloat64("py", 2.0)

				return nil
			})
			if err != nil {
				return err
			}
		}

		for i := 0; i < nPosVel; i++ {
			_, err := txn.Insert(func(r column.Row) error {
				r.SetFloat64("px", 1.0)
				r.SetFloat64("py", 2.0)
				r.SetFloat64("vx", 1.0)
				r.SetFloat64("vy", 2.0)
				return nil
			})
			if err != nil {
				return err
			}
		}
		return nil
	})

	b.StartTimer()
	for i := 0; i < b.N; i++ {
		entities.Query(func(txn *column.Txn) error {
			posX := txn.Float64("px")
			posY := txn.Float64("py")
			velX := txn.Float64("vx")
			velY := txn.Float64("vy")
			txn.With("px", "py", "vx", "vy").Range(func(idx uint32) {
				px, _ := posX.Get()
				py, _ := posY.Get()
				vx, _ := velX.Get()
				vy, _ := velY.Get()
				posX.Set(px + vx)
				posY.Set(py + vy)
			})
			return nil
		})
	}
	b.StopTimer()

	count := 0
	entities.Query(func(txn *column.Txn) error {
		count = txn.With("px", "py", "vx", "vy").Count()
		return nil
	})
	assert.Equal(b, nPosVel, count)
}

Note I can add Position and Velocity easily, and the number of PosVel are correct (1000). but how would I then remove the vx/vy later?

delaneyj avatar Jan 06 '24 20:01 delaneyj

Is the ability to "unset" a column necessary, when you can already set something to 0? Wouldn't this work for your use case -

...
	b.StartTimer()
	for i := 0; i < b.N; i++ {
		entities.Query(func(txn *column.Txn) error {
			posX := txn.Float64("px")
			posY := txn.Float64("py")
			velX := txn.Float64("vx")
			velY := txn.Float64("vy")
			txn.With("px", "py", "vx", "vy").Range(func(idx uint32) {
				px, _ := posX.Get()
				py, _ := posY.Get()
				vx, _ := velX.Get()
				vy, _ := velY.Get()
				posX.Set(px + vx)
				posY.Set(py + vy)
				velX.Set(0)
				velY.Set(0)
			})
			return nil
		})
	}
	b.StopTimer()
...

Dreeseaw avatar Jan 18 '24 02:01 Dreeseaw

Is the ability to "unset" a column necessary Yes, the semantics of something existing in a column is different from being the zero value. There is already the concept of a row existing in the column, but not the ability to remove

delaneyj avatar Jan 18 '24 17:01 delaneyj

Is the ability to "unset" a column necessary

Yes, the semantics of something existing in a column is different from being the zero value. There is already the concept of a row existing in the column, but not the ability to remove

Are you saying you'd like to have a row (record) that's partially deleted in the collection? While what your saying makes sense in the context of one singular column, it doesn't hold up over a collection of multiple columns that use a singular index value.

That'd mean each column would contain an independent mapping of the row index to that column's data for the row, as opposed to just using a list, and I don't think the overhead is worth it.

In this case, I'd just set them to 0.

Dreeseaw avatar Jan 18 '24 18:01 Dreeseaw

Zero value it different from no value. Once you add a column to an id currently there is no way to get back to the original state.

delaneyj avatar Feb 25 '24 17:02 delaneyj