forked from facebookincubator/velox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cast support to generic (facebookincubator#1417)
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
- Loading branch information
1 parent
87c4ba3
commit f15ae0f
Showing
4 changed files
with
729 additions
and
23 deletions.
There are no files selected for viewing
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 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
Oops, something went wrong.