Repository navigation
feat(metadata): PartitionSpec builder & validations - #558
Conversation
| const ( | ||
| PartitionDataIDStart = 1000 | ||
| InitialPartitionSpecID = 0 | ||
| unassignedFieldID = 0 |
There was a problem hiding this comment.
should this be -1 instead of 0?
There was a problem hiding this comment.
field-ids semantic space starts at 1000, so 0 for unassigned is fine? Can also change to -1 if preferred
| type PartitionOption func(*PartitionSpec) error | ||
|
|
||
| func NewPartitionSpecOpts(opts ...PartitionOption) (PartitionSpec, error) { |
There was a problem hiding this comment.
these need docstring comments to explain why someone would use this instead of NewPartitionSpec etc.
There was a problem hiding this comment.
I think it'd make sense to eventually get rid of NewPartitionSpec since it allows to construct invalid partition specs?
| func (p *PartitionSpec) SetID(id int) { | ||
| p.id = id | ||
| } |
There was a problem hiding this comment.
if we're adding a SetID function, we might as well just make the ID field a public field instead of having SetID and ID() methods. That's more idiomatic for Go.
That said, I would rather this instead be a WithID(id int) *PartitionSpec method which returns a copy of the partition spec with the updated ID. That way we maintain that the PartitionSpec object itself can still be immutable
There was a problem hiding this comment.
removed, only callsite was better served by moving all of it into the new method PartitionSpec.BindToSchema
| p.id = id | ||
| } | ||
|
|
||
| func (ps *PartitionSpec) AssignPartitionFieldIds(lastAssignedFieldIDPtr *int) error { |
There was a problem hiding this comment.
same argument as above, I'd rather keep a PartitionSpec as an immutable object, so my preference is this should return a copy of the PartitionSpec with the new IDs
There was a problem hiding this comment.
Made it an unexported function + a PartitionOption, maybe don't even need that, we're maybe ok with just calling it from PartitionSpec.BindToSchema?
| type removeSpecUpdate struct { | ||
| baseUpdate | ||
| SpecIds []int64 `json:"spec-ids"` | ||
| SpecIds []int `json:"spec-ids"` |
There was a problem hiding this comment.
specIds are int not int64, I made a mistake when originally adding the updates
There was a problem hiding this comment.
technically spec ids are JSON ints according to the spec, which means that an int64 would be valid. But I'm fine with changing them back to just being an int for now
There was a problem hiding this comment.
java uses int which is signed 32bit, rust uses i32, I think for cross language compatibility's sake it makes sense to keep it 32bit
There was a problem hiding this comment.
Then you should use int32. On a 64-bit system, int in Go is 64-bit. 😄
There was a problem hiding this comment.
fixing that now will have a lot of changes all over the place, I'll create an issue and we'll do it as a follow up?
- BindToSchema function on PartitionSpec to a) validate a partition spec on addSpec and b) do the field re-assignment in the constructor
8d51586 to
891ac47
Compare
- move reassigning of spec ids into metadata constructor - construct all metadata through builder to have a single point of validation
e615618 to
15a593b
Compare
| freshSchema, err := iceberg.AssignFreshSchemaIDs(schema, nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| freshPartitionSpec, err := iceberg.AssignFreshPartitionSpecIDs(cfg.PartitionSpec, schema, freshSchema) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| freshSortOrder, err := table.AssignFreshSortOrderIDs(cfg.SortOrder, schema, freshSchema) | ||
| if err != nil { | ||
| return nil, err | ||
| } |
There was a problem hiding this comment.
neither java, nor rust are doing this, I'd prefer to get rid of it to remove the last callsite of iceberg.AssignFreshPartitionSpecIDs. Any rest catalog needs to recheck this on createTable, servers can't trust clients to do this beforehand so I think this is largely redundant
There was a problem hiding this comment.
I think this is why the REST catalog integration is failing, maybe something needs to change (or get updated?) with the iceberg rest catalog image?
There was a problem hiding this comment.
It makes very little sense for view or namespace changes to fail based on these changes?
--- PASS: TestRestIntegration/TestCreateNamespace (0.03s)
--- FAIL: TestRestIntegration/TestCreateTable (0.02s)
--- FAIL: TestRestIntegration/TestCreateView (0.01s)
--- PASS: TestRestIntegration/TestLoadNamespaceProps (0.01s)
--- PASS: TestRestIntegration/TestUpdateNamespaceProps (0.03s)
--- FAIL: TestRestIntegration/TestWriteCommitTable (0.02s)
maybe test setup is already failing?
There was a problem hiding this comment.
I'll rerun the test on main, but it doesn't appear to be failing. The test failing with these changes is likely due to the field/partition/schema ID values
There was a problem hiding this comment.
Yeah, it's just the zero value of var cfg catalog.CreateTableCfg ruining the day
There was a problem hiding this comment.
yea, the default in CreateTableCfg is the zero value which has nil for the slice instead of an empty slice. The rest-fixture errors on the null.
You can fix it by adding:
if cfg.SortOrder.Fields == nil {
cfg.SortOrder = table.UnsortedSortOrder
}before the payload is created
There was a problem hiding this comment.
eventually we can shift to jsonv2 which will use an empty slice as the default instead of nil
There was a problem hiding this comment.
I was about to add a constructor which would put sane defaults?
func NewCreateTableCfg() CreateTableCfg {
return CreateTableCfg{
Location: "",
PartitionSpec: nil,
SortOrder: table.UnsortedSortOrder,
Properties: nil,
}
}
There was a problem hiding this comment.
Not sure how much of a go-ism that'd be - I thought it'd make sense to make those fields private so that mutators would protect users from building stuff that won't work?
That'd somewhat conflict with funct-opts being consumer-extendable I guess?
| _, err = builder.SetUUID(tableUuid) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| formatVersion := DefaultFormatVersion | ||
| if props != nil { | ||
| verStr, ok := props["format-version"] | ||
| if ok { | ||
| if formatVersion, err = strconv.Atoi(verStr); err != nil { | ||
| formatVersion = DefaultFormatVersion | ||
| } | ||
| delete(props, "format-version") | ||
| _, err = builder.AddSortOrder(&reassignedIds.sortOrder, true) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| _, err = builder.SetDefaultSortOrderID(-1) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| _, err = builder.AddSchema(reassignedIds.schema) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| _, err = builder.SetCurrentSchemaID(-1) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| _, err = builder.AddPartitionSpec(reassignedIds.partitionSpec, true) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| _, err = builder.SetLoc(location) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| _, err = builder.SetProperties(props) | ||
| if err != nil { | ||
| return nil, err | ||
| } |
There was a problem hiding this comment.
We should make this a funct-opts thing eventually, I think. I went for the builder to replace the struct literal so that there's a single place of validation
… NewPartitionSpecOpts
|
Hmm, i wonder why the REST catalog integration tests are failing. It's likely somehow related to this change as they don't seem to be failing on main. |
…ed order if fields are missing
This PR:
It's mostly contained within partitions, there's a more fundamental change to json deserialization in there which initializes the deserialization target with
-1in all int fields so that we are able to determine if we received / did not receive a certain field and are consequently able to reject requests where mandatory IDs are missing.There's currently still some duplication between the funct-opts constructor of
PartitionSpecandupdate_spec.go. I'm still working on that one, I hope to arrive at something close to java's apply() of BaseUpdatePartitionSpec