Skip to content

Commit

Permalink
Lint fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Chigarev <[email protected]>
  • Loading branch information
dchigarev committed Jan 15, 2021
1 parent 9e45b7d commit fac027e
Show file tree
Hide file tree
Showing 30 changed files with 297 additions and 277 deletions.
4 changes: 2 additions & 2 deletions cpp/src/arrow/array/array_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct ScalarFromArraySlotImpl {
return Finish(a.Value(index_));
}

#define DECL_DECIMAL_VISIT(width) \
#define DECL_DECIMAL_VISIT(width) \
Status Visit(const Decimal##width##Array& a) { \
return Finish(Decimal##width(a.GetValue(index_))); \
}
Expand All @@ -80,7 +80,7 @@ struct ScalarFromArraySlotImpl {
DECL_DECIMAL_VISIT(128)
DECL_DECIMAL_VISIT(256)

#undef DECL_DECIMAL_VISIT
#undef DECL_DECIMAL_VISIT

template <typename T>
Status Visit(const BaseBinaryArray<T>& a) {
Expand Down
5 changes: 2 additions & 3 deletions cpp/src/arrow/array/array_decimal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ namespace arrow {

using internal::checked_cast;


template<uint32_t width>
template <uint32_t width>
BaseDecimalArray<width>::BaseDecimalArray(const std::shared_ptr<ArrayData>& data)
: FixedSizeBinaryArray(data) {
ARROW_CHECK_EQ(data->type->id(), DecimalTypeTraits<width>::Id);
}

template<uint32_t width>
template <uint32_t width>
std::string BaseDecimalArray<width>::FormatValue(int64_t i) const {
const auto& type_ = checked_cast<const TypeClass&>(*type());
const ValueType value(GetValue(i));
Expand Down
5 changes: 2 additions & 3 deletions cpp/src/arrow/array/array_decimal.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
#include <string>

#include "arrow/array/array_binary.h"
#include "arrow/util/decimal_type_traits.h"
#include "arrow/array/data.h"
#include "arrow/type.h"
#include "arrow/util/decimal_type_traits.h"
#include "arrow/util/visibility.h"

namespace arrow {

/// Template Array class for decimal data
template<uint32_t width>
template <uint32_t width>
class ARROW_EXPORT BaseDecimalArray : public FixedSizeBinaryArray {
public:
using TypeClass = typename DecimalTypeTraits<width>::TypeClass;
Expand All @@ -47,5 +47,4 @@ class ARROW_EXPORT BaseDecimalArray : public FixedSizeBinaryArray {
// Backward compatibility
using DecimalArray = Decimal128Array;


} // namespace arrow
21 changes: 12 additions & 9 deletions cpp/src/arrow/array/array_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2408,17 +2408,19 @@ class DecimalTest : public ::testing::TestWithParam<int> {
}

void InitNoNullsTest(int32_t precision) {
std::vector<DecimalValue> draw = {DecimalValue(1), DecimalValue(-2), DecimalValue(2389),
DecimalValue(4), DecimalValue(-12348)};
std::vector<DecimalValue> draw = {DecimalValue(1), DecimalValue(-2),
DecimalValue(2389), DecimalValue(4),
DecimalValue(-12348)};
std::vector<uint8_t> valid_bytes = {true, true, true, true, true};
this->TestCreate(precision, draw, valid_bytes, 0);
this->TestCreate(precision, draw, valid_bytes, 2);
}

void InitWithNullsTest(int32_t precision, std::string big_value, std::string big_negate_value) {
void InitWithNullsTest(int32_t precision, std::string big_value,
std::string big_negate_value) {
std::vector<DecimalValue> draw = {DecimalValue(1), DecimalValue(2), DecimalValue(-1),
DecimalValue(4), DecimalValue(-1), DecimalValue(1),
DecimalValue(2)};
DecimalValue(4), DecimalValue(-1), DecimalValue(1),
DecimalValue(2)};
DecimalValue big;
ASSERT_OK_AND_ASSIGN(big, DecimalValue::FromString(big_value));
draw.push_back(big);
Expand Down Expand Up @@ -2542,10 +2544,11 @@ TEST_P(Decimal256Test, NoNulls) {

TEST_P(Decimal256Test, WithNulls) {
int32_t precision = GetParam();
this->InitWithNullsTest(precision, "578960446186580977117854925043439539266."
"34992332820282019728792003956564819967",
"-578960446186580977117854925043439539266."
"34992332820282019728792003956564819968");
this->InitWithNullsTest(precision,
"578960446186580977117854925043439539266."
"34992332820282019728792003956564819967",
"-578960446186580977117854925043439539266."
"34992332820282019728792003956564819968");
}

INSTANTIATE_TEST_SUITE_P(Decimal256Test, Decimal256Test,
Expand Down
12 changes: 6 additions & 6 deletions cpp/src/arrow/array/builder_decimal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,32 @@ class MemoryPool;
// ----------------------------------------------------------------------
// BaseDecimalBuilder

template<uint32_t width>
template <uint32_t width>
BaseDecimalBuilder<width>::BaseDecimalBuilder(const std::shared_ptr<DataType>& type,
MemoryPool* pool)
MemoryPool* pool)
: FixedSizeBinaryBuilder(type, pool),
decimal_type_(internal::checked_pointer_cast<TypeClass>(type)) {}

template<uint32_t width>
template <uint32_t width>
Status BaseDecimalBuilder<width>::Append(ValueType value) {
RETURN_NOT_OK(FixedSizeBinaryBuilder::Reserve(1));
UnsafeAppend(value);
return Status::OK();
}

template<uint32_t width>
template <uint32_t width>
void BaseDecimalBuilder<width>::UnsafeAppend(ValueType value) {
value.ToBytes(GetMutableValue(length()));
byte_builder_.UnsafeAdvance((width >> 3));
UnsafeAppendToBitmap(true);
}

template<uint32_t width>
template <uint32_t width>
void BaseDecimalBuilder<width>::UnsafeAppend(util::string_view value) {
FixedSizeBinaryBuilder::UnsafeAppend(value);
}

template<uint32_t width>
template <uint32_t width>
Status BaseDecimalBuilder<width>::FinishInternal(std::shared_ptr<ArrayData>* out) {
std::shared_ptr<Buffer> data;
RETURN_NOT_OK(byte_builder_.Finish(&data));
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/arrow/array/builder_decimal.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
#include "arrow/array/builder_base.h"
#include "arrow/array/builder_binary.h"
#include "arrow/array/data.h"
#include "arrow/util/decimal_type_traits.h"
#include "arrow/status.h"
#include "arrow/type.h"
#include "arrow/util/decimal_type_traits.h"
#include "arrow/util/visibility.h"

namespace arrow {

template<uint32_t width>
template <uint32_t width>
class ARROW_EXPORT BaseDecimalBuilder : public FixedSizeBinaryBuilder {
public:
public:
using TypeClass = typename DecimalTypeTraits<width>::TypeClass;
using ArrayType = typename DecimalTypeTraits<width>::ArrayType;
using ValueType = typename DecimalTypeTraits<width>::ValueType;
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/array/validate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct ValidateArrayImpl {
return Status::OK();
}

template<uint32_t width>
template <uint32_t width>
Status Visit(const BaseDecimalArray<width>& array) {
if (array.length() > 0 && array.values() == nullptr) {
return Status::Invalid("values is null");
Expand Down
8 changes: 5 additions & 3 deletions cpp/src/arrow/ipc/json_simple.cc
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,11 @@ class DecimalConverter final
const DecimalSubtype* decimal_type_;
};

#define DECL_DECIMAL_CONVERTER(width) \
template <typename BuilderType = typename TypeTraits<Decimal##width##Type>::BuilderType> \
using Decimal##width##Converter = DecimalConverter<Decimal##width##Type, Decimal##width, BuilderType>;
#define DECL_DECIMAL_CONVERTER(width) \
template <typename BuilderType = \
typename TypeTraits<Decimal##width##Type>::BuilderType> \
using Decimal##width##Converter = \
DecimalConverter<Decimal##width##Type, Decimal##width, BuilderType>;

DECL_DECIMAL_CONVERTER(16)
DECL_DECIMAL_CONVERTER(32)
Expand Down
7 changes: 4 additions & 3 deletions cpp/src/arrow/ipc/json_simple_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,9 @@ TEST(TestFixedSizeBinary, Dictionary) {

template <typename T>
class TestDecimal : public testing::Test {};
using DecimalTypes = ::testing::Types<DecimalTypeTraits<16>, DecimalTypeTraits<32>, DecimalTypeTraits<64>, DecimalTypeTraits<128>, DecimalTypeTraits<256>>;
using DecimalTypes =
::testing::Types<DecimalTypeTraits<16>, DecimalTypeTraits<32>, DecimalTypeTraits<64>,
DecimalTypeTraits<128>, DecimalTypeTraits<256>>;

TYPED_TEST_SUITE(TestDecimal, DecimalTypes);

Expand Down Expand Up @@ -559,8 +561,7 @@ TYPED_TEST(TestDecimal, Errors) {
TYPED_TEST(TestDecimal, Dictionary) {
using TypeClass = typename TypeParam::TypeClass;
auto type = std::make_shared<TypeClass>(5, 2);
AssertJSONDictArray(int32(), type,
R"(["123.45", "-78.90", "-78.90", null, "123.45"])",
AssertJSONDictArray(int32(), type, R"(["123.45", "-78.90", "-78.90", null, "123.45"])",
/*indices=*/"[0, 1, 1, null, 0]",
/*values=*/R"(["123.45", "-78.90"])");
}
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/arrow/pretty_print_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ TEST_F(TestPrettyPrint, DecimalTypes) {
int32_t p = 5;
int32_t s = 4;

for (auto type : {decimal16(p, s), decimal32(p, s), decimal64(p, s), decimal128(p, s), decimal256(p, s)}) {
for (auto type : {decimal16(p, s), decimal32(p, s), decimal64(p, s), decimal128(p, s),
decimal256(p, s)}) {
auto array = ArrayFromJSON(type, "[\"1.4567\", \"3.2765\", null]");

static const char* ex = "[\n 1.4567,\n 3.2765,\n null\n]";
Expand Down
7 changes: 5 additions & 2 deletions cpp/src/arrow/python/arrow_to_pandas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,9 @@ struct ObjectWriterVisitor {
}

template <typename Type>
enable_if_t<(is_base_binary_type<Type>::value || is_fixed_size_binary_type<Type>::value) && !is_decimal_type<Type>::value,
enable_if_t<(is_base_binary_type<Type>::value ||
is_fixed_size_binary_type<Type>::value) &&
!is_decimal_type<Type>::value,
Status>
Visit(const Type& type) {
auto WrapValue = [](const util::string_view& view, PyObject** out) {
Expand Down Expand Up @@ -1106,7 +1108,8 @@ struct ObjectWriterVisitor {
PyObject* decimal_constructor = Decimal.obj();

for (int c = 0; c < data.num_chunks(); c++) {
const auto& arr = checked_cast<const arrow::BaseDecimalArray<width>&>(*data.chunk(c));
const auto& arr =
checked_cast<const arrow::BaseDecimalArray<width>&>(*data.chunk(c));

for (int64_t i = 0; i < arr.length(); ++i) {
if (arr.IsNull(i)) {
Expand Down
9 changes: 3 additions & 6 deletions cpp/src/arrow/python/decimal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ Status DecimalFromPythonDecimal(PyObject* python_decimal, const DecimalType& arr
return InternalDecimalFromPythonDecimal(python_decimal, arrow_type, out);
}

Status DecimalFromPyObject(PyObject* obj, const DecimalType& arrow_type,
Decimal16* out) {
Status DecimalFromPyObject(PyObject* obj, const DecimalType& arrow_type, Decimal16* out) {
return InternalDecimalFromPyObject(obj, arrow_type, out);
}

Expand All @@ -181,8 +180,7 @@ Status DecimalFromPythonDecimal(PyObject* python_decimal, const DecimalType& arr
return InternalDecimalFromPythonDecimal(python_decimal, arrow_type, out);
}

Status DecimalFromPyObject(PyObject* obj, const DecimalType& arrow_type,
Decimal32* out) {
Status DecimalFromPyObject(PyObject* obj, const DecimalType& arrow_type, Decimal32* out) {
return InternalDecimalFromPyObject(obj, arrow_type, out);
}

Expand All @@ -191,8 +189,7 @@ Status DecimalFromPythonDecimal(PyObject* python_decimal, const DecimalType& arr
return InternalDecimalFromPythonDecimal(python_decimal, arrow_type, out);
}

Status DecimalFromPyObject(PyObject* obj, const DecimalType& arrow_type,
Decimal64* out) {
Status DecimalFromPyObject(PyObject* obj, const DecimalType& arrow_type, Decimal64* out) {
return InternalDecimalFromPyObject(obj, arrow_type, out);
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/python/decimal.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace arrow {

template<uint32_t width>
template <uint32_t width>
class DecimalAnyWidth;

using Decimal16 = DecimalAnyWidth<16>;
Expand Down
24 changes: 13 additions & 11 deletions cpp/src/arrow/python/python_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,11 @@ TEST_F(DecimalTest, FromPythonDecimalRescaleNotTruncateable) {
// We fail when truncating values that would lose data if cast to a decimal type with
// lower scale
DecimalTestFromPythonDecimalRescale<Decimal16>(::arrow::decimal16(5, 2),
this->CreatePythonDecimal("1.001"), {});
this->CreatePythonDecimal("1.001"), {});
DecimalTestFromPythonDecimalRescale<Decimal32>(::arrow::decimal32(10, 2),
this->CreatePythonDecimal("1.001"), {});
this->CreatePythonDecimal("1.001"), {});
DecimalTestFromPythonDecimalRescale<Decimal64>(::arrow::decimal64(10, 2),
this->CreatePythonDecimal("1.001"), {});
this->CreatePythonDecimal("1.001"), {});
DecimalTestFromPythonDecimalRescale<Decimal128>(::arrow::decimal128(10, 2),
this->CreatePythonDecimal("1.001"), {});
DecimalTestFromPythonDecimalRescale<Decimal256>(::arrow::decimal256(10, 2),
Expand All @@ -374,12 +374,12 @@ TEST_F(DecimalTest, FromPythonDecimalRescaleNotTruncateable) {
TEST_F(DecimalTest, FromPythonDecimalRescaleTruncateable) {
// We allow truncation of values that do not lose precision when dividing by 10 * the
// difference between the scales, e.g., 1.000 -> 1.00
DecimalTestFromPythonDecimalRescale<Decimal16>(
::arrow::decimal16(5, 2), this->CreatePythonDecimal("1.000"), 100);
DecimalTestFromPythonDecimalRescale<Decimal32>(
::arrow::decimal32(10, 2), this->CreatePythonDecimal("1.000"), 100);
DecimalTestFromPythonDecimalRescale<Decimal64>(
::arrow::decimal64(10, 2), this->CreatePythonDecimal("1.000"), 100);
DecimalTestFromPythonDecimalRescale<Decimal16>(::arrow::decimal16(5, 2),
this->CreatePythonDecimal("1.000"), 100);
DecimalTestFromPythonDecimalRescale<Decimal32>(::arrow::decimal32(10, 2),
this->CreatePythonDecimal("1.000"), 100);
DecimalTestFromPythonDecimalRescale<Decimal64>(::arrow::decimal64(10, 2),
this->CreatePythonDecimal("1.000"), 100);
DecimalTestFromPythonDecimalRescale<Decimal128>(
::arrow::decimal128(10, 2), this->CreatePythonDecimal("1.000"), 100);
DecimalTestFromPythonDecimalRescale<Decimal256>(
Expand All @@ -399,9 +399,11 @@ TEST_F(DecimalTest, FromPythonNegativeDecimalRescale) {
::arrow::decimal256(10, 9), this->CreatePythonDecimal("-1.000"), -1000000000);
}

template<typename T>
template <typename T>
class DecimalTestConversion : public testing::Test {};
using DecimalTypes = ::testing::Types<DecimalTypeTraits<16>, DecimalTypeTraits<32>, DecimalTypeTraits<64>, DecimalTypeTraits<128>, DecimalTypeTraits<256>>;
using DecimalTypes =
::testing::Types<DecimalTypeTraits<16>, DecimalTypeTraits<32>, DecimalTypeTraits<64>,
DecimalTypeTraits<128>, DecimalTypeTraits<256>>;

TYPED_TEST_SUITE(DecimalTestConversion, DecimalTypes);

Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/scalar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ struct ScalarHashImpl {
return StdHash(s.value.days) & StdHash(s.value.days);
}

template <uint32_t width>
typename std::enable_if<width <= 64, Status>::type Visit(const BaseDecimalScalar<width>& s) {
template <uint32_t width, typename = typename std::enable_if<width <= 64, void>::type>
Status Visit(const BaseDecimalScalar<width>& s) {
return StdHash(s.value.Value());
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ struct ARROW_EXPORT DurationScalar : public TemporalScalar<DurationType> {
using TemporalScalar<DurationType>::TemporalScalar;
};

template<uint32_t width>
template <uint32_t width>
struct BaseDecimalScalar : public Scalar {
using Scalar::Scalar;
using TypeClass = typename DecimalTypeTraits<width>::TypeClass;
Expand Down
7 changes: 4 additions & 3 deletions cpp/src/arrow/scalar_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,11 @@ TYPED_TEST(TestRealScalar, StructOf) { this->TestStructOf(); }

TYPED_TEST(TestRealScalar, ListOf) { this->TestListOf(); }


template<typename T>
template <typename T>
class TestDecimalScalar : public testing::Test {};
using DecimalTypes = ::testing::Types<DecimalTypeTraits<16>, DecimalTypeTraits<32>, DecimalTypeTraits<64>, DecimalTypeTraits<128>, DecimalTypeTraits<256>>;
using DecimalTypes =
::testing::Types<DecimalTypeTraits<16>, DecimalTypeTraits<32>, DecimalTypeTraits<64>,
DecimalTypeTraits<128>, DecimalTypeTraits<256>>;

TYPED_TEST_SUITE(TestDecimalScalar, DecimalTypes);

Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/testing/json_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ class ArrayWriter {
}
}

template<uint32_t width>
template <uint32_t width>
void WriteDataValues(const BaseDecimalArray<width>& arr) {
static const char null_string[] = "0";
for (int64_t i = 0; i < arr.length(); ++i) {
Expand Down Expand Up @@ -851,7 +851,7 @@ Status GetDecimal(const RjObject& json_type, std::shared_ptr<DataType>* type) {
break;
default:
return Status::Invalid("Only 128 bit and 256 Decimals are supported. Received",
bit_width);
bit_width);
}

return Status::OK();
Expand Down
Loading

0 comments on commit fac027e

Please sign in to comment.