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

Add IPPrefix Presto type #10816

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

Conversation

mohsaka
Copy link
Contributor

@mohsaka mohsaka commented Aug 22, 2024

Written with similar comments addressed from #10650
Part of #10538

Some comments.

  1. IPPREFIX uses VARBINARY type, therefore it should not be subject to the same issue as IPADDRESS Comparisons for values of logical types are not handled correctly throughout the library #10338.
  2. The cast to and from functions for IPADDRESS <-> IPPREFIX are both in the IPADDRESS and IPPREFIX. This is not necessary since castTo gets priority. However isSupported* is necessary for the check. I could remove the castFroms and just return in the castFrom function since it will never be called.
  3. Limited fuzzer will be added later.
  4. auto const vec = splitIpSlashCidr(ipAddressString); is not outside the switch statement for efficiency. Don't want to re-parse if not necessary. Folly does the same but in a different way which seemed a little messy.
    https://github.com/facebook/folly/blob/556e17ac7b1f6cda68de789d5b06e79b2d3b990f/folly/IPAddress.cpp#L84C24-L84C37

@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 Aug 22, 2024
Copy link

netlify bot commented Aug 22, 2024

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit b21aafa
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/66f596d0547b0700084b123a

@mohsaka mohsaka changed the title Add IPPREFIX type Add IPPrefix Presto type Aug 26, 2024
Copy link
Collaborator

@czentgr czentgr 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!

velox/docs/develop/types.rst Outdated Show resolved Hide resolved
velox/docs/develop/types.rst Outdated Show resolved Hide resolved
velox/docs/develop/types.rst Show resolved Hide resolved
velox/docs/functions/presto/conversion.rst Show resolved Hide resolved
velox/docs/functions/presto/conversion.rst Outdated Show resolved Hide resolved
velox/functions/prestosql/types/IPAddressType.cpp Outdated Show resolved Hide resolved
velox/functions/prestosql/types/IPPrefixType.cpp Outdated Show resolved Hide resolved
@mohsaka mohsaka requested a review from czentgr August 27, 2024 00:14
@mohsaka mohsaka force-pushed the ipprefix_final branch 2 times, most recently from 7f4a345 to 325df43 Compare August 28, 2024 16:23
@mohsaka mohsaka force-pushed the ipprefix_final branch 4 times, most recently from 9cbaa6e to a0e4692 Compare August 29, 2024 08:28
Copy link
Collaborator

@czentgr czentgr left a comment

Choose a reason for hiding this comment

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

Thanks!
@mbasmanova when you get a chance can you please take a look?

Copy link
Contributor

@mbasmanova mbasmanova left a comment

Choose a reason for hiding this comment

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

@mohsaka Thank you for adding this. Looks good, but I haven't read every line. I assume @czentgr has reviewed carefully. Let me know if that's not the case.

velox/docs/develop/types.rst Outdated Show resolved Hide resolved
velox/docs/functions/presto/conversion.rst Outdated Show resolved Hide resolved
velox/functions/prestosql/TypeOf.cpp Outdated Show resolved Hide resolved
velox/functions/prestosql/types/IPAddressType.cpp Outdated Show resolved Hide resolved
velox/functions/prestosql/types/UuidType.cpp Outdated Show resolved Hide resolved
velox/functions/prestosql/types/IPPrefixType.cpp Outdated Show resolved Hide resolved
exec::StringWriter<false> result(flatResult, row);
if (v6Addr.isIPv4Mapped()) {
result.append(
v6Addr.createIPv4().str() + "/" +
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we avoid creating and copying intermediate strings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to fmt::format. Is this what you meant? Please let me know. Thanks!

});
}

static auto splitIpSlashCidr(folly::StringPiece ipSlashCidr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use std::string_view?

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 can switch to string view, but the function will get a little messy in that it will be switched to a find + creation of a vector<string_view> + creation of these string_views. This is used for error reporting and is taken straight from

https://github.com/facebook/folly/blob/556e17ac7b1f6cda68de789d5b06e79b2d3b990f/folly/IPAddress.cpp#L75

Please let me know. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update.
Maybe misinterpreted the comment. Changed function argument to std::string_view. Function itself is still using StringPiece.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted back to StringPiece, however switched to const &. string_view caused string output issue.

Expected error message to contain 'Invalid IP address '2001:db8::1::1'', but received 'Invalid IP address 'ck\0\0\0\0\0\0_�����''.

velox/functions/prestosql/types/IPPrefixType.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@czentgr czentgr left a comment

Choose a reason for hiding this comment

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

@mbasmanova Thank you for your review. But I was not nearly careful enough given the issues you found that are real. I will have to re-review after all this is fixed.

velox/functions/prestosql/types/IPAddressType.cpp Outdated Show resolved Hide resolved
@mohsaka mohsaka requested a review from czentgr September 9, 2024 22:12
Copy link
Collaborator

@czentgr czentgr 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. Only some minor comments.

velox/docs/functions/presto/conversion.rst Outdated Show resolved Hide resolved
velox/functions/prestosql/types/IPPrefixType.cpp Outdated Show resolved Hide resolved
velox/functions/prestosql/types/IPPrefixType.cpp Outdated Show resolved Hide resolved
velox/functions/prestosql/types/IPPrefixType.cpp Outdated Show resolved Hide resolved
@czentgr
Copy link
Collaborator

czentgr commented Sep 13, 2024

@mohsaka looks like one of the functions tests is failing. Might be related to your new type. Please take a look.

@mohsaka mohsaka force-pushed the ipprefix_final branch 2 times, most recently from c0ced7d to f8bc3d7 Compare September 13, 2024 16:47
Copy link
Collaborator

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

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

@mohsaka : Did a very high level review. The code looks good. Will read it closely again.

@czentgr
Copy link
Collaborator

czentgr commented Sep 19, 2024

@mohsaka Please squash your commits. Otherwise, looks good.

Copy link
Collaborator

@czentgr czentgr left a comment

Choose a reason for hiding this comment

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

Minor question on the doc external links.

velox/docs/functions/presto/conversion.rst Outdated Show resolved Hide resolved
@mohsaka
Copy link
Contributor Author

mohsaka commented Sep 25, 2024

@mbasmanova Could I get a review when you have the time? Thank you!

return vec;
}

static void castFromString(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this logic consistent with Java ? Would the same invalid values return the same errors ?

Copy link
Contributor Author

@mohsaka mohsaka Sep 26, 2024

Choose a reason for hiding this comment

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

Not the same error message, but will return an error for the same input as java. The reason is that we are using folly for the parsing etc. I think a lot of changes will be necessary in the velox code if we want all of the error messages to match java for any library we are using, ex boost, folly.

Copy link
Collaborator

@aditi-pandit aditi-pandit Sep 26, 2024

Choose a reason for hiding this comment

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

@mohsaka : I agree that it might not be possible to use the same errors in all places. But we should be as consistent as we can else its very hard during any kind of traffic migration to validate the builds. Meta has big issues with it.

In general, I feel it might be good to split this work as follows:
i) First PR just adds all the type classes for the IPPrefixType. So this PR minus all the casting code.
ii) Add the fuzzer for IPPrefix Casts that compares with Presto.
iii) Add the cast code with the fuzzer in place. That will ensure that we have most consistency. This would also make it simpler to validate the code you have in IPPrefixCastTest.

Based on prior experience I feel the fuzzer should not be an afterthought.

@amitkdutta @kagamiori @kgpai

velox/functions/prestosql/types/IPPrefixType.cpp Outdated Show resolved Hide resolved
velox/functions/prestosql/types/UuidType.cpp Outdated Show resolved Hide resolved
facebook-github-bot pushed a commit that referenced this pull request Sep 26, 2024
Summary:
Requested here to split off from the PR.
#10816 (comment)

Pull Request resolved: #11105

Reviewed By: Yuhta, amitkdutta

Differential Revision: D63475266

Pulled By: kagamiori

fbshipit-source-id: 11c7830b1cd4b665bc7915fd59b52673a7d39537
@mohsaka mohsaka mentioned this pull request Sep 27, 2024
@mohsaka
Copy link
Contributor Author

mohsaka commented Sep 27, 2024

Current split PR for IPPREFIX type only here:
#11122

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants