Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unset a column? #99

Open
delaneyj opened this issue Jan 6, 2024 · 4 comments
Open

Unset a column? #99

delaneyj opened this issue Jan 6, 2024 · 4 comments

Comments

@delaneyj
Copy link

delaneyj commented Jan 6, 2024

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?

@Dreeseaw
Copy link
Collaborator

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()
...

@delaneyj
Copy link
Author

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

@Dreeseaw
Copy link
Collaborator

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.

@delaneyj
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants