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

Support dynamic filter query on slice value and map value #390

Open
wuudjac opened this issue Aug 8, 2022 · 1 comment
Open

Support dynamic filter query on slice value and map value #390

wuudjac opened this issue Aug 8, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@wuudjac
Copy link

wuudjac commented Aug 8, 2022

Hi goccy, glad to see your dynamic filter feature perfectly meets what we need in our JSON log situation.

What we face is, we have a lot of huge thrift-generated request/response structs that we cannot control how to dump as JSON. But with dynamic filter feature, we may drastically shrink our logs and reduce performance loss.

However, seems like it only supports pure nested struct data model, I've found that if value.Filter() is chained through SliceCode and MapCode, it could handle slice layers and map layers properly.

func (c *SliceCode) Filter(query *FieldQuery) Code {
	sliceCode := &SliceCode{
		typ:   c.typ,
		value: c.value.Filter(query),
	}
	return sliceCode
}
func (c *MapCode) Filter(query *FieldQuery) Code {
	mapCode := &MapCode{
		typ:   c.typ,
		key:   c.key,
		value: c.value.Filter(query),
	}
	return mapCode
}

With that said, when query is set as "XA", a JSON like [{"XA":1,"XB":2}] will be serialized as [{"XA":1}].

So, do you think it's reasonable to allow query apply on slice value and map value? Maybe I can fire a pull request for this.

@goccy
Copy link
Owner

goccy commented Aug 18, 2022

Thank you for the contribution !!

As you said, regarding map, it seems that it can be handled by implementing Filter. You can do the same with slice , but you have to think about how the user will specify the elements of slice. Currently, it is specified based on the ( struct's ) field name.

@goccy goccy added the enhancement New feature or request label Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants