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

path/1 behaviour and path expression question #81

Closed
wader opened this issue Jul 2, 2021 · 4 comments
Closed

path/1 behaviour and path expression question #81

wader opened this issue Jul 2, 2021 · 4 comments

Comments

@wader
Copy link
Contributor

wader commented Jul 2, 2021

Hello, I noticed this difference from jq while trying to understand the path tracking code in gojq

$ jq -n '{} | path({})'
jq: error (at <unknown>): Invalid path expression with result {}
$ go run cmd/gojq/main.go -n '{} | path({})'
[]

Don't think i understand what the reflect.DeepEqual checks are doing, ex: https://github.com/itchyny/gojq/blob/main/execute.go#L226
and https://github.com/itchyny/gojq/blob/main/execute.go#L303 i guess it's to make sure the expression was a "path" expression and did not include other things?

@itchyny
Copy link
Owner

itchyny commented Jul 2, 2021

This is due to the difference of checking the equality of path target and input value. jq checks by the pointer addresses but gojq does not. I know this problem since I implemented here but not sure there's workaround in Go, and I stopped wondering for solution because I believe there's no query which should run successfully with jq but not with gojq.

@wader
Copy link
Contributor Author

wader commented Jul 2, 2021

I see, thanks for explaining. Yes i don't think it will cause any issues for me neither. I only noticed the difference while reading the code and testing different expressions.

To support doing it similar to jq I guess gojq would have to wrap all values in some struct that includes some unique value?

A bit unrelated thing I thought about while reading the code: would replace[2]interface{} with some struct like struct PathPart { key interface{}; value interface{} } make the code clearer? ... also if go supported some kind of lightweight ADT:s it would benefit gojq i think :)

@itchyny
Copy link
Owner

itchyny commented Jul 2, 2021

It needs to wrap like that but should be recursive. But it causes various problems against WithFunction options.

@wader
Copy link
Contributor Author

wader commented Jul 3, 2021

Ok! Thanks for the info. Closing.

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