Skip to content

Commit

Permalink
Add class to print in formatted way
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonylouisbsb committed Apr 13, 2021
1 parent e244502 commit 34f2f92
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
69 changes: 69 additions & 0 deletions cpp/src/gandiva/formatting_utils.h
Original file line number Diff line number Diff line change
@@ -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 <typename ARROW_TYPE, typename Enable = void>
class GdvStringFormatter;

template<typename ARROW_TYPE>
class FloatToStringGdvMixin :
public arrow::internal::FloatToStringFormatterMixin<ARROW_TYPE>{

public:
using arrow::internal::FloatToStringFormatterMixin<ARROW_TYPE>::FloatToStringFormatterMixin;

explicit FloatToStringGdvMixin(const std::shared_ptr<arrow::DataType>& = NULLPTR)
: arrow::internal::FloatToStringFormatterMixin<ARROW_TYPE>()
{
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<arrow::FloatType> :
public FloatToStringGdvMixin<arrow::FloatType> {
public:
using FloatToStringGdvMixin::FloatToStringGdvMixin;
};

template <>
class GdvStringFormatter<arrow::DoubleType> :
public FloatToStringGdvMixin<arrow::DoubleType> {
public:
using FloatToStringGdvMixin::FloatToStringGdvMixin;
};
}
#endif //ARROW_SRC_GANDIVA_FORMATTING_UTILS_H_
2 changes: 1 addition & 1 deletion cpp/src/gandiva/gdv_function_stubs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include "gandiva/gdv_function_stubs.h"

#include <cstdlib>
#include <string>
#include <vector>

Expand All @@ -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.

Expand Down

0 comments on commit 34f2f92

Please sign in to comment.