-
Notifications
You must be signed in to change notification settings - Fork 547
Description
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
I have a struct that looks like this:
type ComputerInventory struct {
ID string `json:"id,omitempty"`
Udid string `json:"udid,omitempty"`
... (omitted)
General *ComputerInventoryDataSubsetGeneral `json:"general,omitempty"`
ExtensionAttributes *[]ComputerInventoryDataSubsetExtensionAttributes `json:"extensionAttributes,omitempty"`
}
type ComputerInventoryDataSubsetGeneral struct {
Name string `json:"name,omitempty"`
...
ExtensionAttributes []struct {
DefinitionID string `json:"definitionId,omitempty"`
Name string `json:"name,omitempty"`
... (omitted)
} `json:"extensionAttributes,omitempty"`
}
Note that ComputerInventory and ComputerInventoryDataSubsetGeneral contain a ExtensionAttribute field.
I have this table:
func ComputerInventoryTable() *schema.Table {
return &schema.Table{
Name: "jamf_computer_inventory",
Description: "Jamf Computers",
Transform: transformers.TransformWithStruct(
&jamf.ComputerInventory{},
transformers.WithPrimaryKeys("ID"),
transformers.WithUnwrapStructFields("General"),
// transformers.WithSkipFields(),
),
Resolver: fetchComputers,
}
}
So during column creation, General is unwrapped, leading to an extension_attributes and a general_extension_attributes field in the database.
Goal: I want to skip the root ComputerInventory ExtensionAttributes field, but not skip the General one.
What I do: Add ExtensionAttributes to the WithSkipFields
What actually happens: Both ExtensionAttributes fields are removed -- the root and the child one.
Expected Behavior
ExtensionAttributes on the root struct is removed while the General.ExtensionAttributes field remains.
CloudQuery (redacted) config
unneccessary
Steps To Reproduce
- Have a struct like the following:
type Example struct {
ExtensionAttributes string
Child struct {
ExtensionAttributes string
}
}
- Construct a table with this struct. Unwrap the
Childfield. Skip theExtensionAttributesfield.
func AbcTable() *schema.Table {
return &schema.Table{
Name: "abc",
Description: "abc",
Transform: transformers.TransformWithStruct(
&Example{},
transformers.WithUnwrapStructFields("Child"),
transformers.WithSkipFields("ExtensionAttributes"),
),
Resolver: fetchAbc,
}
}
Expectation: Root ExtensionAttributes field is skipped while the Child field remains.
CloudQuery (redacted) logs
CloudQuery version
6.5.0
Additional Context
In the plugin-sdk when it starts unwrapping fields, it uses t.ignoreField(sf) to determine whether it should skip a field.
But sf.Name is simply just ExtensionAttributes for both the root field and the internal General struct being unwrapped. So there is no way to distinguish between the two. sf.Name perhaps should be prefixed with the name of the parent field. That way, you can do WithSkipFields("ExtensionAttributes") vs. WithSkipFields("General.ExtensionAttributes") or something.
Pull request (optional)
- I can submit a pull request