Skip to content

Commit

Permalink
Use OptionalAccessor
Browse files Browse the repository at this point in the history
  • Loading branch information
PHILO-HE committed Aug 9, 2024
1 parent 8fd1d31 commit 6ab4abf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 30 deletions.
14 changes: 5 additions & 9 deletions velox/expression/SimpleFunctionAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,33 +220,29 @@ class SimpleFunctionAdapter : public VectorFunction {
const std::vector<TypePtr>& inputTypes,
const core::QueryConfig& config,
const std::vector<VectorPtr>& packed,
const ConstantArg<Values>*... values) const {
const OptionalAccessor<Values>*... values) const {
if constexpr (POSITION == FUNC::num_args) {
return (*fn_).initialize(inputTypes, config, values...);
} else {
if (packed.at(POSITION) != nullptr) {
SelectivityVector rows(1);
DecodedVector decodedVector(*packed.at(POSITION), rows);
auto oneReader = VectorReader<arg_at<POSITION>>(&decodedVector);
if (oneReader.containsNull(0)) {
unpackInitialize<POSITION + 1>(
inputTypes, config, packed, values..., &ConstantArg());
} else {
unpackInitialize<POSITION + 1>(
auto accessor = OptionalAccessor(&oneReader, 0);
unpackInitialize<POSITION + 1>(
inputTypes,
config,
packed,
values...,
&ConstantArg(oneReader[0]));
}
&accessor);
} else {
using temp_type = exec_arg_at<POSITION>;
unpackInitialize<POSITION + 1>(
inputTypes,
config,
packed,
values...,
(const ConstantArg<temp_type>*)nullptr);
(const OptionalAccessor<temp_type>*)nullptr);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions velox/functions/Macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#pragma once

#include "velox/core/Metaprogramming.h"
#include "velox/expression/ComplexViewTypes.h"
#include "velox/type/SimpleFunctionApi.h"
#include "velox/type/Type.h"

Expand All @@ -36,6 +37,10 @@
using opt_out_type = std::optional< \
typename __Velox_ExecParams::template resolver<TArgs>::out_type>; \
\
template <typename TArgs> \
using accessor_arg_type = facebook::velox::exec::OptionalAccessor< \
typename __Velox_ExecParams::template resolver<TArgs>::in_type>; \
\
DECLARE_CONDITIONAL_TYPE_NAME( \
null_free_in_type_resolver, null_free_in_type, in_type); \
template <typename TArgs> \
Expand Down
21 changes: 0 additions & 21 deletions velox/type/SimpleFunctionApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,27 +235,6 @@ struct ConstantChecker {
isConstantType<TArgs>::value...};
};

template <typename T>
struct ConstantArg {
public:
ConstantArg() {}

ConstantArg(T* value) : value_(value) {}

T* value() {
VELOX_USER_CHECK_NOT_NULL(value_, "NULL input for constant argument");
return value_;
}

// Null Constant.
bool isNull() {
return value_ == nullptr;
}

private:
T* value_ = nullptr;
};

/// CppToType templates for types introduced above.

template <>
Expand Down

0 comments on commit 6ab4abf

Please sign in to comment.