Skip to content

Conversation

@zhjwpku
Copy link
Collaborator

@zhjwpku zhjwpku commented Nov 7, 2025

No description provided.

Copy link
Member

@wgtmac wgtmac left a comment

Choose a reason for hiding this comment

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

Thanks for working on this! I have left some minor comments.

@zhjwpku zhjwpku changed the title feat: add SortOrder::Make and SortOrder::IsBoundToSchema feat: add SortOrder::Make and SortOrder::Validate Nov 8, 2025
Comment on lines 118 to 120
if (schema_field == std::nullopt) {
return InvalidArgument("Cannot find schema field for sort field: {}", field);
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (schema_field == std::nullopt) {
return InvalidArgument("Cannot find schema field for sort field: {}", field);
}
if (schema_field == std::nullopt) {
continue;
}

I think we should not error out if the field is missing. The Java impl is as below:

  public SortOrder bind(Schema schema) {
    SortOrder.Builder builder = SortOrder.builderFor(schema).withOrderId(orderId);

    for (UnboundSortField field : fields) {
      Type sourceType = schema.findType(field.sourceId);
      Transform<?, ?> transform;
      if (sourceType != null) {
        transform = Transforms.fromString(sourceType, field.transform.toString());
      } else {
        transform = field.transform;
      }
      builder.addSortField(transform, field.sourceId, field.direction, field.nullOrder);
    }

    return builder.build();
  }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, UnboundSortOrder doesn't check, but checkCompatibility should do the check, see [1].

[1] https://github.com/apache/iceberg/blob/main/api/src/main/java/org/apache/iceberg/SortOrder.java#L300-L302

Copy link
Member

Choose a reason for hiding this comment

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

Good catch!

/// \brief Checks whether this function can be applied to the given Type.
/// \param source_type The source type to check.
/// \return true if this transform can be applied to the type, false otherwise
bool CanTransform(const Type& source_type) const;
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider changing the parameter to const std::shared_ptr& for consistency?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think a const ref of Type here should be fine, the Bind function takes a const shared_ptr& because the returned TransformFunction holds its own shared_ptr.

I'm open to using const shared_ptr& if more people think it's the better approach.

@wgtmac
Copy link
Member

wgtmac commented Nov 10, 2025

Thanks @zhjwpku and @lishuxu! Let me merge this to move forward.

@wgtmac wgtmac merged commit e759807 into apache:main Nov 10, 2025
10 checks passed
@zhjwpku zhjwpku deleted the make_sort_order branch November 12, 2025 15:00
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.

3 participants