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

docs: clarify nullability information source for empty literals #602

Merged
merged 1 commit into from
Apr 18, 2024

Conversation

vbarua
Copy link
Member

@vbarua vbarua commented Feb 10, 2024

Looking at the oneof literal_type block I noticed that the empty_list variant and empty_map variant reuse a Type message, much like the null variant.

      Type null = 29; // a typed null literal
      ...
      Type.List empty_list = 31;
      Type.Map empty_map = 32;

Like Type, Type.List and Type.Map also declare their nullability directly. To avoid ambiguity, I updated the docs to specify that the nullability of these literals should come from the inner message here, and not from the nullable field of the Literal message.

Copy link

ACTION NEEDED

Substrait follows the Conventional Commits
specification
for
release automation.

The PR title and description are used as the merge commit message. Please update your PR title and description to match the specification.

@vbarua vbarua changed the title doc: clarify nullability information source for empty literals docs: clarify nullability information source for empty literals Feb 10, 2024
// * Type null
// * Type.List empty_list
// * Type.Map empty_map
// which should declare their nullability directly instead.
Copy link
Member

Choose a reason for hiding this comment

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

I need to verify but the text format appears to set both for empty lists and just the type for empty maps (based on its test cases taken from Isthmus).

Copy link
Member Author

Choose a reason for hiding this comment

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

@EpsilonPrime where you able to verify this?

Copy link
Member

Choose a reason for hiding this comment

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

It shouldn't matter going forward, I will make sure that the text format follows this guideline by adding some tests.

Copy link
Member

Choose a reason for hiding this comment

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

For empty lists the following behavior is present for the text format:

{}_list<string> -> nothing nullable
{}_list<string?> -> literal is nullable, list is not nullable
{}_list?<string> -> list is nullable, literal is not
{}_list?<string?> -> both are nullable

It seems like this nullability covers the nullability of the list even if it's empty. Even if it's empty is it legal to have a nullable version of it?

Copy link
Member

Choose a reason for hiding this comment

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

Added the empty_map tests in substrait-io/substrait-cpp#97.

Copy link
Member

Choose a reason for hiding this comment

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

The text format is definitely using this nullability over the one in the type. It's the same behavior it uses for non-empty lists and maps.

Copy link
Member

@westonpace westonpace 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 removing the ambiguity

EpsilonPrime
EpsilonPrime previously approved these changes Feb 22, 2024
proto/substrait/algebra.proto Outdated Show resolved Hide resolved
westonpace
westonpace previously approved these changes Feb 28, 2024
Copy link
Member

@westonpace westonpace left a comment

Choose a reason for hiding this comment

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

This wording is ok. I have a suggestion for something slightly different if we want.

proto/substrait/algebra.proto Outdated Show resolved Hide resolved
@vbarua
Copy link
Member Author

vbarua commented Mar 27, 2024

I want to double check something before merging this, will look at it this week.

@vbarua vbarua dismissed stale reviews from westonpace and EpsilonPrime via 08ad96f April 3, 2024 01:41
@vbarua vbarua force-pushed the vbarua/clarify-literal-nullability branch from 81dfb73 to 08ad96f Compare April 3, 2024 01:41
@vbarua
Copy link
Member Author

vbarua commented Apr 3, 2024

I want to double check something before merging this, will look at it this week.

Weston's suggestion clarified this for me. I think this should be good as is with his changes incorporated.

@EpsilonPrime
Copy link
Member

Will check this on Thursday.

// Whether the literal_type above should be treated as a nullable type.
// Applies to all members of the literal_type oneof EXCEPT:
// * Type null (must be nullable by definition)
// * Type.List empty_list (use Type.List::nullability)
Copy link
Member

Choose a reason for hiding this comment

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

If the Type.List::nullability is the nullability of the type inside the list then I don't think this applies.

Copy link
Member Author

@vbarua vbarua Apr 15, 2024

Choose a reason for hiding this comment

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

message List {
Type type = 1;
uint32 type_variation_reference = 2;
Nullability nullability = 3;
}

I believe that Type.List::nullability is the nullability of the list itself, and Type.List::type::nullability is the nullability of the internal type.

Copy link
Member

Choose a reason for hiding this comment

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

That matches what I believe. But for empty lists and empty maps why is that any different than populated lists and maps?

Copy link
Member

Choose a reason for hiding this comment

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

Empty lists and empty maps have two spots for list nullability (so we need to pick one to be authoritative):

// List nullability (authoritative)
Literal::empty_list::list::nullability
// Also list nullability (redundant)
Literal::nullability

Populated lists and maps have one spot for list nullability and one spot for item nullability:

// Applies to the item
Literal::list::values...nullability
// Applies to the list (only option, thus authoritative)
Literal::nullability

Copy link
Member

Choose a reason for hiding this comment

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

Okay, I see it now. An alternative would be to change the type of of empty_list and empty_map to Type but that doesn't work simply for maps (which would need two nullability values for its key and type).

@vbarua vbarua merged commit abf7818 into main Apr 18, 2024
13 checks passed
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.

4 participants