Skip to content

Conversation

@Rafferty97
Copy link
Contributor

Which issue does this PR close?

Closes #11685.

Rationale for this change

Improve performance by eliminating unneeded heap allocations. See #11685 for details.

Are these changes tested?

Yes, new tests were added to cover the affected code.

Are there any user-facing changes?

No, it's only an implementation change.


#[test]
fn test_named_struct() {
// struct(1, 2.0, true) = { "foo": 1, "bar": 2.0, "baz": true }
Copy link
Contributor

Choose a reason for hiding this comment

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

Most of the test is already covered in datafusion/sqllogictest/test_files/struct.slt

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, should the tests be removed then? I was following the lead of struct.rs, so should the test in that file be removed too for consistency?

Copy link
Contributor

@jayzhan211 jayzhan211 Jul 29, 2024

Choose a reason for hiding this comment

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

Sure! It is prefer to add test in slt, unless it is not possible or becomes much more complex

Copy link
Contributor

Choose a reason for hiding this comment

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

Here are the instructions: https://github.com/apache/datafusion/tree/main/datafusion/sqllogictest

Ideally you should be able to extend one of the existing test files in https://github.com/apache/datafusion/tree/main/datafusion/sqllogictest/test_files

@alamb alamb marked this pull request as draft July 30, 2024 17:57
@alamb
Copy link
Contributor

alamb commented Jul 30, 2024

Marking as draft as I think this PR is no longer waiting on feedback. Please mark it as ready for review when it is ready for another look

@Rafferty97 Rafferty97 force-pushed the optimize-named-struct-expr branch from ebad5bf to dcaa717 Compare September 1, 2024 02:05
@github-actions github-actions bot added the functions Changes to functions implementation label Sep 1, 2024
@Rafferty97 Rafferty97 marked this pull request as ready for review September 1, 2024 02:33
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you @Rafferty97 -- this PR is looking good to me

This code looks nicer to me, but it is not clear that this would perform and better/worse than the existing code

Update: I see now the rationale on #11685 . I suspect the time required to create a few vecs will be hard to measure, but in any event I think the fact this code looks better makes it worth merging even if there is no performance change

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks again @Rafferty97

}
}

#[cfg(test)]
Copy link
Contributor

Choose a reason for hiding this comment

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

To anyone following along, this is already covered in struct.slt

@alamb alamb merged commit bf6c82f into apache:main Sep 3, 2024
@alamb
Copy link
Contributor

alamb commented Sep 3, 2024

Thanks again @Rafferty97

@Rafferty97 Rafferty97 deleted the optimize-named-struct-expr branch August 23, 2025 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove unnecessary allocations in struct and named_struct

3 participants