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

added Query.SeekPrefix #119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

added Query.SeekPrefix #119

wants to merge 1 commit into from

Conversation

drew-512
Copy link

@drew-512 drew-512 commented Feb 6, 2019

No description provided.

@Stebalien
Copy link
Member

There should probably be a naive implementation in query_impl.go

@drew-512
Copy link
Author

drew-512 commented Feb 6, 2019

Something like:

type FilterKeySeekPrefix struct {
    SeekPrefix string
}

func (f FilterKeySeekPrefix) Filter(e Entry) bool {
	return e.Key >= f.SeekPrefix
}

and

func NaiveQueryApply(q Query, qr Results) Results {
	if q.Prefix != "" {
		qr = NaiveFilter(qr, FilterKeyPrefix{q.Prefix})
	}
	if q.SeekPrefix != "" {
		qr = NaiveFilter(qr, FilterKeySeekPrefix{q.SeekPrefix})
	}
	...

?

@Stebalien
Copy link
Member

That will just act like Prefix. This one will have to skip everything until SeekPrefix. It also needs to be applied after any ordering.

@drew-512
Copy link
Author

drew-512 commented Feb 6, 2019

That will just act like Prefix. This one will have to skip everything until SeekPrefix. It also needs to be applied after any ordering.

Let's say we have entries whose keys are zero-padded time codes for speedy scanning by time:
/txn/000009-DEADBEEF
/txn/000015-FEEDFACE
/txn/000055-BEEFBEEF
/txn/000055-B01DFACE
/txn/000103-D0D0CACA

.SeekPrefix could be something like /txn/000050 and .Prefix would be /txn/, so the thing I'm seeing is that NaiveQueryApply should look at OrderByKeyDescending (as you described in the other thread) in order to know which way to compare the key with .SeekPrefix:

type FilterKeySeekPrefix struct {
    Ascending bool
    SeekPrefix string
}

func (f FilterKeySeekPrefix) Filter(e Entry) bool {
	if f.Ascending {
		return e.Key >= f.SeekPrefix
	} else {
		return e.Key <= f.SeekPrefix
        }
}

Is the only place NaiveQueryApply is used is in example code? Maybe it was helpful when demoing Datastore way back, but is it likely to ever see production? I would have a sit down w/ someone under me who ever used it, but that's just me. Not that these SeekPrefix changes should drive code to be dropped from ds, but is this candidate code to be dropped? Disclaimer: I'm super OCD about non-production/non-scalable staying around, so feel free to ignore this -- I always like to ask this question. ¯\(ツ)

@Stebalien
Copy link
Member

You're right, assuming ordering by key, that should work. Actually, I'm starting to wonder how this should interact with sorting by value. Let's discuss here: #116 (comment)

Is the only place NaiveQueryApply is used is in example code?

We use it in the MapDatastore (in-memory datastore) and many datastores use the component functions (e.g., NaiveFilter).

@drew-512
Copy link
Author

drew-512 commented Feb 7, 2019

Ok cool, thanks for indulging me on that ques and glad you're catching this stuff.

Like that we're gettin through this together and adding a nice feature to ds.

@sanderpick
Copy link

This looks pretty stale... does that mean another avenue was chosen? Or key seeking is still not possible?

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

Successfully merging this pull request may close these issues.

3 participants