Skip to content

Commit

Permalink
ARROW-4274: Misc cleanups in header files
Browse files Browse the repository at this point in the history
  • Loading branch information
Pindikura Ravindra committed Jan 23, 2019
1 parent 18050f8 commit 49d7933
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 44 deletions.
49 changes: 28 additions & 21 deletions cpp/src/arrow/util/decimal.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
// specific language governing permissions and limitations
// under the License.

#ifndef ARROW_DECIMAL_H
#define ARROW_DECIMAL_H
#pragma once

#include <array>
#include <cstdint>
Expand All @@ -42,7 +41,7 @@ namespace arrow {
/// The implementation is split into two parts :
///
/// 1. DecimalBasic128
/// - can be safely compiled to IR without references to libstdcpp.
/// - can be safely compiled to IR without references to libstdc++.
/// 2. Decimal128
/// - has additional functionality on top of DecimalBasic128 to deal with
/// strings and streams.
Expand Down Expand Up @@ -70,42 +69,51 @@ class ARROW_EXPORT Decimal128 : public DecimalBasic128 {
/// little endian byte order.
explicit Decimal128(const uint8_t* bytes) : DecimalBasic128(bytes) {}

/// Divide this number by right and return the result. This operation is
/// not destructive.
/// The answer rounds to zero. Signs work like:
/// 21 / 5 -> 4, 1
/// -21 / 5 -> -4, -1
/// 21 / -5 -> -4, 1
/// -21 / -5 -> 4, -1
/// \param divisor the number to divide by
/// \param remainder the remainder after the division
Status Divide(const Decimal128& divisor, Decimal128* result,
Decimal128* remainder) const {
auto dstatus = DecimalBasic128::Divide(divisor, result, remainder);
return ToArrowStatus(dstatus);
}

/// \brief Convert Decimal128 from one scale to another
Status Rescale(int32_t original_scale, int32_t new_scale, Decimal128* out) const {
auto dstatus = DecimalBasic128::Rescale(original_scale, new_scale, out);
return ToArrowStatus(dstatus);
}

/// \brief Convert from a big endian byte representation. The length must be
/// between 1 and 16
/// \return error status if the length is an invalid value
static Status FromBigEndian(const uint8_t* data, int32_t length, Decimal128* out);

/// \brief Cast this value to an int64_t.
explicit operator int64_t() const;

/// \brief Convert the Decimal128 value to a base 10 decimal string with the given
/// scale.
std::string ToString(int32_t scale) const;

/// \brief Convert the value to an integer string
std::string ToIntegerString() const;

static Status FromString(const util::string_view& s, Decimal128* out,
int32_t* precision = NULLPTR, int32_t* scale = NULLPTR);
/// \brief Cast this value to an int64_t.
explicit operator int64_t() const;

/// \brief Convert a decimal string to an Decimal128 value, optionally including
/// precision and scale if they're passed in and not null.
static Status FromString(const util::string_view& s, Decimal128* out,
int32_t* precision = NULLPTR, int32_t* scale = NULLPTR);
static Status FromString(const std::string& s, Decimal128* out,
int32_t* precision = NULLPTR, int32_t* scale = NULLPTR);
static Status FromString(const char* s, Decimal128* out, int32_t* precision = NULLPTR,
int32_t* scale = NULLPTR);

/// \brief Convert from a big endian byte representation. The length must be
/// between 1 and 16
/// \return error status if the length is an invalid value
static Status FromBigEndian(const uint8_t* data, int32_t length, Decimal128* out);

/// \brief Convert Decimal128 from one scale to another
Status Rescale(int32_t original_scale, int32_t new_scale, Decimal128* out) const {
auto dstatus = DecimalBasic128::Rescale(original_scale, new_scale, out);
return ToArrowStatus(dstatus);
}

/// \brief Convert to a signed integer
template <typename T, typename = internal::EnableIfIsOneOf<T, int32_t, int64_t>>
Status ToInteger(T* out) const {
Expand All @@ -121,9 +129,8 @@ class ARROW_EXPORT Decimal128 : public DecimalBasic128 {
}

private:
/// Converts internal error code to Status
Status ToArrowStatus(DecimalStatus dstatus) const;
};

} // namespace arrow

#endif // ARROW_DECIMAL_H
5 changes: 1 addition & 4 deletions cpp/src/arrow/util/decimal_basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
// specific language governing permissions and limitations
// under the License.

#ifndef ARROW_DECIMAL_BASIC_H
#define ARROW_DECIMAL_BASIC_H
#pragma once

#include <array>
#include <cstdint>
Expand Down Expand Up @@ -162,5 +161,3 @@ ARROW_EXPORT DecimalBasic128 operator%(const DecimalBasic128& left,
const DecimalBasic128& right);

} // namespace arrow

#endif // ARROW_DECIMAL_BASIC_H
5 changes: 1 addition & 4 deletions cpp/src/gandiva/decimal_basic_scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
// specific language governing permissions and limitations
// under the License.

#ifndef DECIMAL_BASIC_SCALAR_H
#define DECIMAL_BASIC_SCALAR_H
#pragma once

#include <cstdint>
#include "arrow/util/decimal_basic.h"
Expand Down Expand Up @@ -56,5 +55,3 @@ inline bool operator==(const DecimalBasicScalar128& left,
}

} // namespace gandiva

#endif // DECIMAL_BASIC_SCALAR_H
7 changes: 2 additions & 5 deletions cpp/src/gandiva/decimal_scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
// "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.
// under the License

#ifndef DECIMAL_SCALAR_H
#define DECIMAL_SCALAR_H
#pragma once

#include <cstdint>
#include <iostream>
Expand Down Expand Up @@ -62,5 +61,3 @@ class DecimalScalar128 : public DecimalBasicScalar128 {
};

} // namespace gandiva

#endif // DECIMAL_SCALAR_H
6 changes: 4 additions & 2 deletions cpp/src/gandiva/precompiled/decimal_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
namespace gandiva {
namespace decimalops {

static DecimalBasic128 CheckAndIncreaseScale(DecimalBasic128 in, int32_t delta) {
using arrow::DecimalBasic128;

static DecimalBasic128 CheckAndIncreaseScale(const DecimalBasic128& in, int32_t delta) {
return (delta <= 0) ? in : in.IncreaseScaleBy(delta);
}

static DecimalBasic128 CheckAndReduceScale(DecimalBasic128 in, int32_t delta) {
static DecimalBasic128 CheckAndReduceScale(const DecimalBasic128& in, int32_t delta) {
return (delta <= 0) ? in : in.ReduceScaleBy(delta);
}

Expand Down
11 changes: 3 additions & 8 deletions cpp/src/gandiva/precompiled/decimal_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,20 @@
// specific language governing permissions and limitations
// under the License.

#ifndef DECIMAL_SQL_H
#define DECIMAL_SQL_H
#pragma once

#include <cstdint>
#include <string>
#include "gandiva/decimal_basic_scalar.h"

using DecimalBasic128 = arrow::DecimalBasic128;

namespace gandiva {
namespace decimalops {

/// Return the sum of 'x' and 'y'.
/// out_precision and out_scale are passed along for efficiency, they must match
/// the rules in DecimalTypeSql::GetResultType.
DecimalBasic128 Add(const DecimalBasicScalar128& x, const DecimalBasicScalar128& y,
int32_t out_precision, int32_t out_scale);
arrow::DecimalBasic128 Add(const DecimalBasicScalar128& x, const DecimalBasicScalar128& y,
int32_t out_precision, int32_t out_scale);

} // namespace decimalops
} // namespace gandiva

#endif // DECIMAL_SQL_H

0 comments on commit 49d7933

Please sign in to comment.