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

Embedded struct error: all fields must have non-empty names #2

Open
bminer opened this issue Sep 28, 2018 · 4 comments
Open

Embedded struct error: all fields must have non-empty names #2

bminer opened this issue Sep 28, 2018 · 4 comments

Comments

@bminer
Copy link
Contributor

bminer commented Sep 28, 2018

If I have a struct that uses "type embedding" to embed another struct, even if the embedded struct has influx tags on its fields, influxdbhelper complains:

Error writing ... data to influx:  all fields must have non-empty names

Ideally, embedded structs should be supported.

@cbrake
Copy link
Owner

cbrake commented Sep 28, 2018

Do you have any thoughts on naming fields of embedded structs in influx, as influx records are flat?

@bminer
Copy link
Contributor Author

bminer commented Sep 28, 2018

I think influxdbhelper should flatten embedded structs. The Go compiler supports this strange flattening property of embedded structs. For example, if you have:

type A struct {
  FieldA string `influx: fieldA,tag`
}
type B struct {
  A
  FieldB string `influx: fieldB,tag`
}

In this case, B.A.FieldA and B.FieldA are synonymous, and it appears that the embedded struct has been "flattened" in the latter case. Disclaimer: I'm unsure how the reflection API in Go works for embedded structs.

@bminer
Copy link
Contributor Author

bminer commented Sep 28, 2018

@cbrake
Copy link
Owner

cbrake commented Sep 28, 2018

agreed, it would be handy to be able to "compose" structs and essentially flatten them for storage in influx.

The workaround for now is to create another struct for writing into influx, and then copy your data to that. Since influx schemas are generally not huge, this has not been a big problem.

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