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

misc(examples): Extend simple functions example to use nested complex types #12061

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kKPulla
Copy link
Contributor

@kKPulla kKPulla commented Jan 11, 2025

Summary:

  1. Added a new set of UDFs w/ input, output args using nested complex types between array, map and row.
  2. Changed the required struct level template arg from 'T' to 'TExecParams' as a best practice

Differential Revision: D68047322

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 11, 2025
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D68047322

Copy link

netlify bot commented Jan 11, 2025

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit c5be800
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/67883f9ce33538000889b374

velox/examples/SimpleFunctions.cpp Outdated Show resolved Hide resolved
struct MyNestedComplexTimesTwoFunction {
VELOX_DEFINE_FUNCTION_TYPES(TExecParams);

FOLLY_ALWAYS_INLINE bool call(
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a comment here to describe the exact input and output types? Just to ensure folks without a deeper understand can still follow what is going on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Added comments here and across all of the new code as a walkthrough. PTAL

const arg_type<Array<Map<int64_t, double>>>& inputArrayOfMap) {
result.reserve(inputArrayOfMap.size());
for (const auto& innerMap : inputArrayOfMap) {
if (!innerMap.has_value()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

just in case, please comment the body as well. This is not "real" code, so the more we walk the reader through what is going on, the better.

… types (facebookincubator#12061)

Summary:

1. Added a new set of UDFs w/ input, output args using nested complex types between array, map and row.
2. Changed the required struct level template arg from 'T' to 'TExecParams' as a best practice

Differential Revision: D68047322
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D68047322

Copy link
Contributor

@pedroerp pedroerp left a comment

Choose a reason for hiding this comment

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

Looks good overall. Please just rephrase the comment.

// This method takes and returns an Array of Maps. The return value has the
// values of the inner map doubled. Both array and map proxy objects are
// currently implemented based on std::vector and std::unordered_map,
// respectively. Vector elements and map values are currently wrapped by
Copy link
Contributor

Choose a reason for hiding this comment

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

Both array and map proxy objects are currently implemented based on std::vector and std::unordered_map, respectively.

What do you mean by this? It sounds like they are internally backed by std containers, which is not the case. Maybe rephrase to make it clearer that they are implemented in such as way as to follow the std API as much as possible, but in come cases this can't be done (but that they are not in fact based on slow std containers)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied this comment from the existing plustwo functions above which said the same about implementing based on std:: containers. I agree it can be misleading, can rephrase that too if we agree.

continue;
}
for (const auto& val : arrayVal.value()) {
valueWriter.add_item() = val.has_value() ? val.value() * 2 : 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: if an array element is null, shouldn't the output (NULL*2) also be NULL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True :) I kept the output null free, again matching with the plustwo functions above. No strong preference either way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants