Skip to content
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

ARROW-9128: [C++] Implement string space trimming kernels: trim, ltrim, and rtrim #8621

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions cpp/src/arrow/compute/api_scalar.h
Expand Up @@ -92,6 +92,13 @@ struct ARROW_EXPORT StrptimeOptions : public FunctionOptions {
TimeUnit::type unit;
};

struct ARROW_EXPORT TrimOptions : public FunctionOptions {
explicit TrimOptions(std::string characters) : characters(std::move(characters)) {}

/// The individual characters that can be trimmed from the string.
std::string characters;
};

enum CompareOperator : int8_t {
EQUAL,
NOT_EQUAL,
Expand Down
29 changes: 29 additions & 0 deletions cpp/src/arrow/compute/kernels/codegen_internal.h
Expand Up @@ -126,6 +126,35 @@ struct OptionsWrapper : public KernelState {
OptionsType options;
};

/// KernelState adapter for when the state is an instance constructed with the
/// KernelContext and the FunctionOptions as argument
template <typename StateType, typename OptionsType>
struct KernelStateFromFunctionOptions : public KernelState {
explicit KernelStateFromFunctionOptions(KernelContext* ctx, OptionsType state)
: state(StateType(ctx, std::move(state))) {}

static std::unique_ptr<KernelState> Init(KernelContext* ctx,
const KernelInitArgs& args) {
if (auto options = static_cast<const OptionsType*>(args.options)) {
return ::arrow::internal::make_unique<KernelStateFromFunctionOptions>(ctx,
*options);
}

ctx->SetStatus(
Status::Invalid("Attempted to initialize KernelState from null FunctionOptions"));
return NULLPTR;
}

static const StateType& Get(const KernelState& state) {
return ::arrow::internal::checked_cast<const KernelStateFromFunctionOptions&>(state)
.state;
}

static const StateType& Get(KernelContext* ctx) { return Get(*ctx->state()); }

StateType state;
};

// ----------------------------------------------------------------------
// Input and output value type definitions

Expand Down