-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Cast support to generic #1417
Closed
Closed
Cast support to generic #1417
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This pull request was exported from Phabricator. Differential Revision: D35616634 |
laithsakka
added a commit
to laithsakka/velox
that referenced
this pull request
Apr 14, 2022
Summary: Pull Request resolved: facebookincubator#1417 - This diff adds the support of type access and cast to generics. - It introduces 4 functions that can be called on the GenericView: - type() - kind() - castTo<T>: performs an unchecked cast and returns arg_type<T>. A safety debug time type check will happen. - tryCastTo<T>: return std::optional<returns arg_type<T>>, performs unchecked cast. return std::null opt if T does not match the type of the vector. - **Cost**: - The first time we do the cast we create the readers corresponding to that type. Then for the coming rows, the cost is a couple of instructions; checking reader is created, accessing the reader in the variant and returning the element at the row index. - TryCastTo is more expensive, since it does a type check as well. - In general its not expensive to use it with complex types, but avoid using it with primitives by either implementing a function specialized when input is primitive (see == function as example ). Or casting to complex types already specialized with primitive types, i.e. Array<int> Array<double> instead of Array<Any> and then casting Any to int for every element. - **What can be casted to?** This diff enabled cast to all basic types plus Array<Any> Map<Any, Any>, Row<Any>, Row<Any, Any> and Row<Any, Any,..etc> up to 5.. This allow to recursively traverse complex types. - **How to add a new casted to type?** - its a one line code change, just add the type to readers_variant_t e.g. you can add reader_t<Array<int>>, then someone can cast or tryCast to Array<int> directly instead of casting to Array<Any> and then casting the each inner element. - We can allow user to pass additional types through the generic itself instead of changing readers_variant_t. Ex: allowing the user to say Generic<T, Array<int>, std::shared_ptr<X>..etc> where those are things that this generic can be casted to in addition to the basic types. (this is not done yet but future work). - The diff adds example function HasDuplicate, which checks if an array has duplicate items. Differential Revision: D35616634 fbshipit-source-id: d75cebc56a89fb13a1e8b75e5be37b2ebd809ced
9dab2ea
to
969dc7b
Compare
This pull request was exported from Phabricator. Differential Revision: D35616634 |
laithsakka
added a commit
to laithsakka/velox
that referenced
this pull request
Apr 16, 2022
Summary: Pull Request resolved: facebookincubator#1417 - This diff adds the support of type access and cast to generics. - It introduces 4 functions that can be called on the GenericView: - type() - kind() - castTo<T>: performs an unchecked cast and returns arg_type<T>. A safety debug time type check will happen. - tryCastTo<T>: return std::optional<returns arg_type<T>>, performs unchecked cast. return std::null opt if T does not match the type of the vector. - **Cost**: - The first time we do the cast we create the readers corresponding to that type. Then for the coming rows, the cost is a couple of instructions; checking reader is created, accessing the reader in the variant and returning the element at the row index. In some non-common cases there is additional check that the type casted to is consistent across rows. - TryCastTo is more expensive, since it does a type check as well. - In general its not expensive to use it with complex types, but avoid using it with primitives by either implementing a function specialized when input is primitive (see == function as example ). Or casting to complex types already specialized with primitive types, i.e. Array<int> Array<double> instead of Array<Any> and then casting Any to int for every element. - **What can be casted to?** This diff enabled cast to all basic types plus Array<Any> Map<Any, Any>, Row<Any>, Row<Any, Any> and Row<Any, Any,..etc> up to 5.. This allow to recursively traverse complex types. - **How to add a new casted to type?** - Any type except Generic<> it self, (Cast to self type) or Variadic<...>. - The diff adds example function HasDuplicate, which checks if an array has duplicate items. Differential Revision: D35616634 fbshipit-source-id: 203170e4b680032b0616cc6aee89305dbc57a61f
969dc7b
to
dd36fe8
Compare
This pull request was exported from Phabricator. Differential Revision: D35616634 |
Summary: Pull Request resolved: facebookincubator#1417 - This diff adds the support of type access and cast to generics. - It introduces 4 functions that can be called on the GenericView: - type() - kind() - castTo<T>: performs an unchecked cast and returns arg_type<T>. A safety debug time type check will happen. - tryCastTo<T>: return std::optional<returns arg_type<T>>, performs unchecked cast. return std::null opt if T does not match the type of the vector. - **Cost**: - The first time we do the cast we create the readers corresponding to that type. Then for the coming rows, the cost is a couple of instructions; checking reader is created, accessing the reader in the variant and returning the element at the row index. In some non-common cases there is additional check that the type casted to is consistent across rows. - TryCastTo is more expensive, since it does a type check as well. - In general its not expensive to use it with complex types, but avoid using it with primitives by either implementing a function specialized when input is primitive (see == function as example ). Or casting to complex types already specialized with primitive types, i.e. Array<int> Array<double> instead of Array<Any> and then casting Any to int for every element. - **What can be casted to?** This diff enabled cast to all basic types plus Array<Any> Map<Any, Any>, Row<Any>, Row<Any, Any> and Row<Any, Any,..etc> up to 5.. This allow to recursively traverse complex types. - **How to add a new casted to type?** - Any type except Generic<> it self, (Cast to self type) or Variadic<...>. - The diff adds example function HasDuplicate, which checks if an array has duplicate items. Reviewed By: kevinwilfong Differential Revision: D35616634 fbshipit-source-id: f33bba0cd5ed81c8352085cbf4a8b196f85c5a8b
This pull request was exported from Phabricator. Differential Revision: D35616634 |
dd36fe8
to
c58471e
Compare
Arty-Maly
pushed a commit
to Arty-Maly/velox
that referenced
this pull request
May 13, 2022
Summary: Pull Request resolved: facebookincubator#1417 - This diff adds the support of type access and cast to generics. - It introduces 4 functions that can be called on the GenericView: - type() - kind() - castTo<T>: performs an unchecked cast and returns arg_type<T>. A safety debug time type check will happen. - tryCastTo<T>: return std::optional<returns arg_type<T>>, performs unchecked cast. return std::null opt if T does not match the type of the vector. - **Cost**: - The first time we do the cast we create the readers corresponding to that type. Then for the coming rows, the cost is a couple of instructions; checking reader is created, accessing the reader in the variant and returning the element at the row index. In some non-common cases there is additional check that the type casted to is consistent across rows. - TryCastTo is more expensive, since it does a type check as well. - In general its not expensive to use it with complex types, but avoid using it with primitives by either implementing a function specialized when input is primitive (see == function as example ). Or casting to complex types already specialized with primitive types, i.e. Array<int> Array<double> instead of Array<Any> and then casting Any to int for every element. - **What can be casted to?** This diff enabled cast to all basic types plus Array<Any> Map<Any, Any>, Row<Any>, Row<Any, Any> and Row<Any, Any,..etc> up to 5.. This allow to recursively traverse complex types. - **How to add a new casted to type?** - Any type except Generic<> it self, (Cast to self type) or Variadic<...>. - The diff adds example function HasDuplicate, which checks if an array has duplicate items. Reviewed By: kevinwilfong Differential Revision: D35616634 fbshipit-source-id: 847af1dfc3af9b49ce32386b05bef585be955a81
shiyu-bytedance
pushed a commit
to shiyu-bytedance/velox-1
that referenced
this pull request
Aug 18, 2022
Summary: Pull Request resolved: facebookincubator#1417 - This diff adds the support of type access and cast to generics. - It introduces 4 functions that can be called on the GenericView: - type() - kind() - castTo<T>: performs an unchecked cast and returns arg_type<T>. A safety debug time type check will happen. - tryCastTo<T>: return std::optional<returns arg_type<T>>, performs unchecked cast. return std::null opt if T does not match the type of the vector. - **Cost**: - The first time we do the cast we create the readers corresponding to that type. Then for the coming rows, the cost is a couple of instructions; checking reader is created, accessing the reader in the variant and returning the element at the row index. In some non-common cases there is additional check that the type casted to is consistent across rows. - TryCastTo is more expensive, since it does a type check as well. - In general its not expensive to use it with complex types, but avoid using it with primitives by either implementing a function specialized when input is primitive (see == function as example ). Or casting to complex types already specialized with primitive types, i.e. Array<int> Array<double> instead of Array<Any> and then casting Any to int for every element. - **What can be casted to?** This diff enabled cast to all basic types plus Array<Any> Map<Any, Any>, Row<Any>, Row<Any, Any> and Row<Any, Any,..etc> up to 5.. This allow to recursively traverse complex types. - **How to add a new casted to type?** - Any type except Generic<> it self, (Cast to self type) or Variadic<...>. - The diff adds example function HasDuplicate, which checks if an array has duplicate items. Reviewed By: kevinwilfong Differential Revision: D35616634 fbshipit-source-id: 847af1dfc3af9b49ce32386b05bef585be955a81
marin-ma
pushed a commit
to marin-ma/velox-oap
that referenced
this pull request
Dec 15, 2023
…ubator#1417) Support sha1/sha2/crc32 hash functions
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
This diff adds the support of type access and cast to generics.
It introduces 4 functions that can be called on the GenericView:
check will happen.
std::null opt if T does not match the type of the vector.
Cost:
coming rows, the cost is a couple of instructions; checking reader is created, accessing the reader
in the variant and returning the element at the row index.
implementing a function specialized when input is primitive (see == function as example ). Or casting to
complex types already specialized with primitive types, i.e. Array Array instead of Array
and then casting Any to int for every element.
What can be casted to?
This diff enabled cast to all basic types plus Array Map<Any, Any>, Row, Row<Any, Any> and
Row<Any, Any,..etc> up to 5.. This allow to recursively traverse complex types.
How to add a new casted to type?
then someone can cast or tryCast to Array directly instead of casting to Array and then casting the
each inner element.
Ex: allowing the user to say Generic<T, Array, std::shared_ptr..etc> where those are things that this
generic can be casted to in addition to the basic types. (this is not done yet but future work).
The diff adds example function HasDuplicate, which checks if an array has duplicate items.
Differential Revision: D35616634