Skip to content

feat(metadata): validated SortOrders constructor, validations & tests - #571

Merged
zeroshade merged 6 commits into
apache:mainfrom
twuebi:tp/sort-orders
Sep 22, 2025
Merged

zeroshade merged 6 commits into
apache:mainfrom
twuebi:tp/sort-orders

Conversation

@twuebi

@twuebi twuebi commented Sep 19, 2025 •

Copy link
Copy Markdown
Contributor
  1. adds a NewSortOrder constructor & makes SortOrder fields private to prevent mutation
  2. NewSortOrder validates fields SortField, i.e. Transform / NullOrder / Direction are now mandatory fields
  3. reuse sort-orders
  4. checkCompatibility of sort-orders against schema
  5. sort-orders & partition-specs are mandatory fields for format-version > 1
  6. update tests & add new ones

Comment thread table/sorting.go Outdated
Comment on lines +178 to +187
if len(s.fields) == 0 {
s.fields = []SortField{}
s.orderID = 0

return nil
}

if s.orderID == -1 {
s.orderID = InitialSortOrderID // initialize default sort order id
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to have the same error as NewSortOrder if order-id == UnsortedSortOrderID and len(fields) == 0?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The if statement in NewSortOrder has a bug, it should've been if orderID == UnsortedSortOrderID && len(fields) != 0 {, gonna add a test..

Comment thread table/sorting.go Outdated

for idx, field := range fields {
if field.Transform == nil {
return SortOrder{}, fmt.Errorf("sort field at index %d has no transform", idx)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should have a %w with ErrInvalid or something of that sort

Comment thread table/sorting.go
Comment on lines +204 to +209
if field.Direction != SortASC && field.Direction != SortDESC {
return SortOrder{}, ErrInvalidSortDirection
}
if field.NullOrder != NullsFirst && field.NullOrder != NullsLast {
return SortOrder{}, ErrInvalidNullOrder
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as with the transform, you should use fmt.Errorf("%w: sort field at index %d", ErrInvalidSortDirection) etc.

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last couple nit picks

Comment thread table/sorting.go
return nil
}

func NewSortOrder(orderID int, fields []SortField) (SortOrder, error) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs a docstring comment

Comment thread table/metadata_internal_test.go Resolved
@zeroshade
zeroshade merged commit 9492274 into apache:main Sep 22, 2025
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

Successfully merging this pull request may close these issues.

2 participants