diff --git a/cpp/src/gandiva/formatting_utils.h b/cpp/src/gandiva/formatting_utils.h new file mode 100644 index 0000000000000..cf4071b2983f3 --- /dev/null +++ b/cpp/src/gandiva/formatting_utils.h @@ -0,0 +1,69 @@ +// 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. + + +#pragma once + +#include "arrow/util/formatting.h" +#include "arrow/type.h" +#include "arrow/vendored/double-conversion/double-conversion.h" + +#ifndef ARROW_SRC_GANDIVA_FORMATTING_UTILS_H_ +#define ARROW_SRC_GANDIVA_FORMATTING_UTILS_H_ + +namespace gandiva { + +/// \brief The entry point for conversion to strings. +template +class GdvStringFormatter; + +template +class FloatToStringGdvMixin : + public arrow::internal::FloatToStringFormatterMixin{ + + public: + using arrow::internal::FloatToStringFormatterMixin::FloatToStringFormatterMixin; + + explicit FloatToStringGdvMixin(const std::shared_ptr& = NULLPTR) + : arrow::internal::FloatToStringFormatterMixin() + { + const int flags = + double_conversion::DoubleToStringConverter::EMIT_TRAILING_ZERO_AFTER_POINT | + double_conversion::DoubleToStringConverter::EMIT_TRAILING_DECIMAL_POINT; + + double_conversion::DoubleToStringConverter return_(flags, "inf", "nan", + 'E', -3, 7, 6, 1); + + this->impl_->converter_ = return_; + } +}; + +template <> +class GdvStringFormatter : + public FloatToStringGdvMixin { + public: + using FloatToStringGdvMixin::FloatToStringGdvMixin; +}; + +template <> +class GdvStringFormatter : + public FloatToStringGdvMixin { + public: + using FloatToStringGdvMixin::FloatToStringGdvMixin; +}; +} +#endif //ARROW_SRC_GANDIVA_FORMATTING_UTILS_H_ diff --git a/cpp/src/gandiva/gdv_function_stubs.cc b/cpp/src/gandiva/gdv_function_stubs.cc index 22a5bbfc90d2b..86d652cf2d35c 100644 --- a/cpp/src/gandiva/gdv_function_stubs.cc +++ b/cpp/src/gandiva/gdv_function_stubs.cc @@ -17,7 +17,6 @@ #include "gandiva/gdv_function_stubs.h" -#include #include #include @@ -31,6 +30,7 @@ #include "gandiva/precompiled/types.h" #include "gandiva/random_generator_holder.h" #include "gandiva/to_date_holder.h" +#include "gandiva/formatting_utils.h" /// Stub functions that can be accessed from LLVM or the pre-compiled library.