Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4.3k
GH-39049: [C++] Use Cast() instead of CastTo() for Dictionary Scalar in test#39362
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -36,14 +36,22 @@ Status CastToDictionary(KernelContext* ctx, const ExecSpan& batch, ExecResult* o | ||
| const CastOptions& options = CastState::Get(ctx); | ||
| const auto& out_type = checked_cast<const DictionaryType&>(*out->type()); | ||
| std::shared_ptr<ArrayData> in_array = batch[0].array.ToArrayData(); | ||
| // if out type is same as in type, return input | ||
| if (out_type.Equals(*batch[0].type())) { | ||
| /// XXX: This is the wrong place to do a zero-copy optimization | ||
| out->value = batch[0].array.ToArrayData(); | ||
| out->value = in_array; | ||
| return Status::OK(); | ||
| } | ||
| std::shared_ptr<ArrayData> in_array = batch[0].array.ToArrayData(); | ||
| // If the input type is STRING, it is first encoded as a dictionary to facilitate | ||
| // processing. This approach allows the subsequent code to uniformly handle STRING | ||
| // inputs as if they were originally provided in dictionary format. Encoding as a | ||
| // dictionary helps in reusing the same logic for dictionary operations. | ||
| if (batch[0].type()->id() == Type::STRING) { | ||
| in_array = DictionaryEncode(in_array)->array(); | ||
| } | ||
| const auto& in_type = checked_cast<const DictionaryType&>(*in_array->type); | ||
| ArrayData* out_array = out->array_data().get(); | ||
| @@ -77,17 +85,21 @@ Status CastToDictionary(KernelContext* ctx, const ExecSpan& batch, ExecResult* o | ||
| return Status::OK(); | ||
| } | ||
| std::vector<std::shared_ptr<CastFunction>> GetDictionaryCasts() { | ||
| auto func = std::make_shared<CastFunction>("cast_dictionary", Type::DICTIONARY); | ||
| AddCommonCasts(Type::DICTIONARY, kOutputTargetType, func.get()); | ||
| ScalarKernel kernel({InputType(Type::DICTIONARY)}, kOutputTargetType, CastToDictionary); | ||
| template <typename SrcType> | ||
| void AddDictionaryCast(CastFunction* func) { | ||
| ScalarKernel kernel({InputType(SrcType::type_id)}, kOutputTargetType, CastToDictionary); | ||
| kernel.null_handling = NullHandling::COMPUTED_NO_PREALLOCATE; | ||
| kernel.mem_allocation = MemAllocation::NO_PREALLOCATE; | ||
| DCHECK_OK(func->AddKernel(SrcType::type_id, std::move(kernel))); | ||
| } | ||
| DCHECK_OK(func->AddKernel(Type::DICTIONARY, std::move(kernel))); | ||
| std::vector<std::shared_ptr<CastFunction>> GetDictionaryCasts() { | ||
| auto cast_dict = std::make_shared<CastFunction>("cast_dictionary", Type::DICTIONARY); | ||
| AddCommonCasts(Type::DICTIONARY, kOutputTargetType, cast_dict.get()); | ||
| AddDictionaryCast<DictionaryType>(cast_dict.get()); | ||
| AddDictionaryCast<StringType>(cast_dict.get()); | ||
llama90 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| return {func}; | ||
| return {cast_dict}; | ||
| } | ||
| } // namespace internal | ||
This file contains hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.