-
Notifications
You must be signed in to change notification settings - Fork 199
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
add new command: FILTERVALS #50
base: master
Are you sure you want to change the base?
Conversation
@@ -1,6 +1,7 @@ | |||
package core | |||
|
|||
import ( | |||
"path/filepath" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this a heavy library for a basic usecase? A lightweight implementation of the same is possible via reflect
and regexp
. Note: reflect
would be needed to deduce the type " INT, FLOAT, DOUBLE, BOOLEAN, STRING", so regex could match the values better. This however could be a non-issue for the time-being.
core/store.go
Outdated
value.LastAccessedAt = getCurrentClock() | ||
} | ||
|
||
return matchedValues |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also can't we convert the [][2]string to the string here itself? To encode for a very specific type with a specialized encoder implementation seems tedious for any new command in the future.
It would be easy to process the matched values cumulatively and return string here itself.
0) 0) user:1
1) value:1
1) 0) user:2
1) value:2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by string, you mean []string? because we'll have a list of matches right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manosriram the return value should be an array to two-tuple allowing we to pipe it with different commands (in the future)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arpitbbhayani @rohanverma94 noted, updated in 2fcf3d1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manosriram Since the requirement is to return an array of two-tuple so that it can be piped to another set of commands. So something on these lines maybe-
type filtervalTuple struct {
Rkey string;
Rvalue interface{}
}
func FilterVals(pattern string) []filtervalTuple {
rdevice := regexp.MustCompile(pattern)
var result []filtervalTuple
for key, value := range store {
val := value.(string)
ok := rdevice.MatchString(val)
if ok {
result = append(result, filtervalTuple{Rkey:key, Rvalue:val})
}
}
return result
}
Check a sample code here! - https://rohanverma.godbolt.org/z/oeY4rab4s
@arpitbbhayani any further input if you can give then it would be helpful for @manosriram
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rohanverma94 not sure if the regex will match wildcards, updated other parts except that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manosriram It's just a sample code for simplifying the concept 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rohanverma94 okay 😅
func FilterVals(pattern string) []string { | ||
var matchedValues []string | ||
for key, value := range store { | ||
val := value.Value.(string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not use inherent encoding that we are maintaining instead of reflect
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manosriram this would not work. Use type encodings to check. Not this. Each Dice object holds the type and encoding information. .(string)
is an expensive operation. we maintain type encoding information.
65c67bf
to
9f66a0b
Compare
clean up print statement modify [][2] string to []string: filtervals return filtered key-value pairs as a list added new case in Encode and struct for filterval tuple remove func in resp.go rename var
9f66a0b
to
f8c10ad
Compare
@manosriram Ask arpit for review. He knows the requirements well. |
func FilterVals(pattern string) []string { | ||
var matchedValues []string | ||
for key, value := range store { | ||
val := value.Value.(string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manosriram this would not work. Use type encodings to check. Not this. Each Dice object holds the type and encoding information. .(string)
is an expensive operation. we maintain type encoding information.
ok, err := filepath.Match(pattern, val) | ||
if err != nil { | ||
return []filterValTuple{}, err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are only doing wildcard match. this is an expensive operation again. please write a simple wildcard matcher and then we will extend the solution if needed.
type filterValTuple struct { | ||
Rkey string | ||
Rvalue interface{} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of creating a filterVal
type, create a generic KV tuple type because we will need it for other commands as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arpitbbhayani The project is based on Go 1.17, and we don't have generic types in that yet. We can still enable this via https://twitter.com/go_perf/status/1427540843175555086?s=20&t=3vX8nwQV5E4aye66nh2G0w . This is nonperformant.
Or you can bump the project version to Go 1.18.
@manosriram Thanks for the contribution. There are conflicts atm. |
No description provided.