edponce commented on a change in pull request #11023:
URL: https://github.com/apache/arrow/pull/11023#discussion_r739607083
##########
File path: cpp/src/arrow/compute/kernels/scalar_string.cc
##########
@@ -537,6 +536,341 @@ struct FixedSizeBinaryTransformExecWithState
}
};
+template <typename Type1, typename Type2>
+struct StringBinaryTransformBase {
+ using ViewType2 = typename GetViewType<Type2>::T;
+ using ArrayType1 = typename TypeTraits<Type1>::ArrayType;
+ using ArrayType2 = typename TypeTraits<Type2>::ArrayType;
+
+ virtual ~StringBinaryTransformBase() = default;
+
+ virtual Status PreExec(KernelContext* ctx, const ExecBatch& batch, Datum*
out) {
+ return Status::OK();
+ }
+
+ virtual Status InvalidStatus() {
+ return Status::Invalid("Invalid UTF8 sequence in input");
+ }
+
+ // Return the maximum total size of the output in codeunits (i.e. bytes)
+ // given input characteristics for different input shapes.
+ //
+ // Scalar-Scalar
+ virtual int64_t MaxCodeunits(const int64_t input1_ncodeunits, const
ViewType2) {
+ return input1_ncodeunits;
+ }
+
+ // Scalar-Array
+ virtual int64_t MaxCodeunits(const int64_t input1_ncodeunits, const
ArrayType2&) {
+ return input1_ncodeunits;
+ }
+
+ // Array-Scalar
+ virtual int64_t MaxCodeunits(const ArrayType1& input1, const ViewType2) {
+ return input1.total_values_length();
+ }
+
+ // Array-Array
+ virtual int64_t MaxCodeunits(const ArrayType1& input1, const ArrayType2&) {
+ return input1.total_values_length();
+ }
+
+ // Not all combinations of input shapes are meaningful to string binary
+ // transforms, so these flags serve as control toggles for enabling/disabling
+ // the corresponding ones. These flags should be set in the PreExec() method.
+ //
+ // This is an example of a StringTransform that disables argument shapes with
+ // mixed scalar/array.
+ //
+ // template <typename Type1, typename Type2>
+ // struct MyStringTransform : public StringBinaryTransformBase<Type1, Type2>
{
+ // Status PreExec(KernelContext* ctx, const ExecBatch& batch, Datum* out)
override {
+ // EnableScalarArray = false;
+ // EnableArrayScalar = false;
+ // return StringBinaryTransformBase::PreExec(ctx, batch, out);
+ // }
+ // ...
+ // };
+ bool EnableScalarScalar = true;
+ bool EnableScalarArray = true;
+ bool EnableArrayScalar = true;
+ bool EnableArrayArray = true;
+
+ // Tracks status of transform in StringBinaryTransformExecBase.
+ // The purpose of this transform status is to provide a means to
report/detect
+ // errors in functions that do not provide a mechanism to return a Status
+ // value but can still detect errors. This status is checked automatically
+ // after MaxCodeunits() and Transform() operations.
+ Status st = Status::OK();
+};
+
+/// Kernel exec generator for binary (two parameters) string transforms.
+/// The first parameter is expected to always be a Binary/StringType while the
+/// second parameter is generic. Types of template parameter StringTransform
+/// need to define a transform method with the following signature:
+///
+/// int64_t Transform(const uint8_t* input, const int64_t
input_string_ncodeunits,
+/// const ViewType2 value2, uint8_t* output);
Review comment:
I extended the description to be more informative on the function
parameters and return value.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]