-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-971: [C++][Compute] IsValid, IsNull kernels #7410
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
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8295c3f
ARROW-971: [C++][Compute] IsValid, IsNull kernels
bkietz 9085048
revert Property testing
bkietz 174a53f
use CheckScalarUnary
bkietz 1d6f6c9
document RAG::ArrayOf
bkietz 71d082e
remove unused #includes
bkietz 7835000
explicit internal:: usage
bkietz 8034e7a
fix anonymous namespace
bkietz 932ecc1
switch to in-kernel allocation when zero copy is unavailable
bkietz cada19f
remove debug check
bkietz 95e2545
rename Operators for validity kernels
bkietz 6f31cd2
review comments
bkietz 5bd1057
use zero copy with buffer slices
bkietz be7a03f
Disable AsciiUpper/AsciiLower unit tests until ARROW-9122 done, add m…
wesm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #include "arrow/compute/kernels/common.h" | ||
|
|
||
| #include "arrow/util/bit_util.h" | ||
| #include "arrow/util/bitmap_ops.h" | ||
|
|
||
| namespace arrow { | ||
|
|
||
| using internal::CopyBitmap; | ||
| using internal::InvertBitmap; | ||
|
|
||
| namespace compute { | ||
| namespace { | ||
|
|
||
| struct IsValidOperator { | ||
| static void Call(KernelContext* ctx, const Scalar& in, Scalar* out) { | ||
| checked_cast<BooleanScalar*>(out)->value = in.is_valid; | ||
| } | ||
|
|
||
| static void Call(KernelContext* ctx, const ArrayData& arr, ArrayData* out) { | ||
| DCHECK_EQ(out->offset, 0); | ||
| DCHECK_LE(out->length, arr.length); | ||
| if (arr.buffers[0] != nullptr) { | ||
| out->buffers[1] = arr.offset == 0 | ||
| ? arr.buffers[0] | ||
| : SliceBuffer(arr.buffers[0], arr.offset / 8, arr.length / 8); | ||
| out->offset = arr.offset % 8; | ||
| return; | ||
| } | ||
bkietz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| KERNEL_RETURN_IF_ERROR(ctx, ctx->AllocateBitmap(out->length).Value(&out->buffers[1])); | ||
|
|
||
| if (arr.null_count == 0 || arr.buffers[0] == nullptr) { | ||
| BitUtil::SetBitsTo(out->buffers[1]->mutable_data(), out->offset, out->length, true); | ||
| return; | ||
| } | ||
|
|
||
| CopyBitmap(arr.buffers[0]->data(), arr.offset, arr.length, | ||
| out->buffers[1]->mutable_data(), out->offset); | ||
| } | ||
| }; | ||
|
|
||
| struct IsNullOperator { | ||
| static void Call(KernelContext* ctx, const Scalar& in, Scalar* out) { | ||
| checked_cast<BooleanScalar*>(out)->value = !in.is_valid; | ||
| } | ||
|
|
||
| static void Call(KernelContext* ctx, const ArrayData& arr, ArrayData* out) { | ||
| if (arr.null_count == 0 || arr.buffers[0] == nullptr) { | ||
| BitUtil::SetBitsTo(out->buffers[1]->mutable_data(), out->offset, out->length, | ||
| false); | ||
| return; | ||
| } | ||
|
|
||
| InvertBitmap(arr.buffers[0]->data(), arr.offset, arr.length, | ||
| out->buffers[1]->mutable_data(), out->offset); | ||
| } | ||
| }; | ||
|
|
||
| void MakeFunction(std::string name, std::vector<InputType> in_types, OutputType out_type, | ||
| ArrayKernelExec exec, FunctionRegistry* registry, | ||
| MemAllocation::type mem_allocation, bool can_write_into_slices) { | ||
| Arity arity{static_cast<int>(in_types.size())}; | ||
| auto func = std::make_shared<ScalarFunction>(name, arity); | ||
|
|
||
| ScalarKernel kernel(std::move(in_types), out_type, exec); | ||
| kernel.null_handling = NullHandling::OUTPUT_NOT_NULL; | ||
| kernel.can_write_into_slices = can_write_into_slices; | ||
| kernel.mem_allocation = mem_allocation; | ||
|
|
||
| DCHECK_OK(func->AddKernel(std::move(kernel))); | ||
| DCHECK_OK(registry->AddFunction(std::move(func))); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| namespace internal { | ||
|
|
||
| void RegisterScalarValidity(FunctionRegistry* registry) { | ||
| MakeFunction("is_valid", {ValueDescr::ANY}, boolean(), | ||
| codegen::SimpleUnary<IsValidOperator>, registry, | ||
| MemAllocation::NO_PREALLOCATE, /*can_write_into_slices=*/false); | ||
|
|
||
| MakeFunction("is_null", {ValueDescr::ANY}, boolean(), | ||
| codegen::SimpleUnary<IsNullOperator>, registry, MemAllocation::PREALLOCATE, | ||
| /*can_write_into_slices=*/true); | ||
| } | ||
|
|
||
| } // namespace internal | ||
| } // namespace compute | ||
| } // namespace arrow | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know off the top of my head what will be the implications of modifying the offset of the output value, but I think it should be okay, and we can always fix it later if it becomes an issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I'm not clear on what the kernel is/isn't allowed to modify in the out data. I've added
can_write_into_slices=false, so IIUC the kernel should always exclusively own the out data.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not worth thinking too hard right now because kernel pipelining (temporary elision) is not implemented yet so until that happens it would be just speculation.