Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-PLACET committed Dec 17, 2024
1 parent 7e0e8e2 commit 2841b40
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 89 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ if (USE_DATE_POLYFILL)
endif()

if(USE_LARGE_INT_PLACEHOLDERS)

message(STATUS "Using large int placeholders")
add_compile_definitions(SPARROW_USE_LARGE_INT_PLACEHOLDERS)
endif()

Expand Down
10 changes: 8 additions & 2 deletions include/sparrow/types/data_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,8 +764,14 @@ namespace std
return "Sparse union";
case RUN_ENCODED:
return "Run encoded";
case DECIMAL:
return "Decimal";
case DECIMAL32:
return "Decimal32";
case DECIMAL64:
return "Decimal64";
case DECIMAL128:
return "Decimal128";
case DECIMAL256:
return "Decimal256";
case FIXED_WIDTH_BINARY:
return "Fixed width binary";
case STRING_VIEW:
Expand Down
20 changes: 19 additions & 1 deletion include/sparrow/utils/decimal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include <sstream>
#include <string_view>

#if defined(__cpp_lib_format)
# include <format>
#endif

#include "sparrow/utils/large_int.hpp"
#include "sparrow/utils/mp_utils.hpp"

Expand Down Expand Up @@ -187,4 +191,18 @@ namespace sparrow
}
}

} // namespace sparrow
} // namespace sparrow

template <typename T>
struct std::formatter<sparrow::decimal<T>>
{
constexpr auto parse(std::format_parse_context& ctx)
{
return ctx.begin();
}

auto format(const sparrow::decimal<T>& d, std::format_context& ctx) const
{
return std::format_to(ctx.out(), "Decimal({}, {})", d.storage(), d.scale());
}
};
2 changes: 1 addition & 1 deletion include/sparrow/utils/format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ namespace sparrow
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
widths[i] = std::max(widths[i], static_cast<decltype(std::ranges::size(headers[i]) std::ranges::size(headers[i]));
widths[i] = std::max(widths[i], std::ranges::size(headers[i]));
#if defined(__GNUC__)
# pragma GCC diagnostic pop
#endif
Expand Down
113 changes: 83 additions & 30 deletions include/sparrow/utils/large_int.hpp
Original file line number Diff line number Diff line change
@@ -1,74 +1,95 @@
// Copyright 2024 Man Group Operations Limited
//
// Licensed 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 mplied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#if defined(__cpp_lib_format)
# include <format>
#endif

#ifndef SPARROW_USE_LARGE_INT_PLACEHOLDERS

// disabe warnings -Wold-style-cast sign-conversion for clang and gcc
#if defined(__clang__) || defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
#include <sparrow/details/3rdparty/large_integers/int128_t.hpp>
#include <sparrow/details/3rdparty/large_integers/int256_t.hpp>

#if defined(__clang__) || defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
# if defined(__clang__) || defined(__GNUC__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wold-style-cast"
# pragma GCC diagnostic ignored "-Wsign-conversion"
# pragma GCC diagnostic ignored "-Wshadow"
# pragma GCC diagnostic ignored "-Wsign-conversion"
# endif
# include <sparrow/details/3rdparty/large_integers/int128_t.hpp>
# include <sparrow/details/3rdparty/large_integers/int256_t.hpp>

# if defined(__clang__) || defined(__GNUC__)
# pragma GCC diagnostic pop
# endif

#endif

#include <cstdint>

namespace sparrow
{


#ifdef SPARROW_USE_LARGE_INT_PLACEHOLDERS
#ifdef SPARROW_USE_LARGE_INT_PLACEHOLDERS
constexpr bool large_int_placeholders = true;


struct int128_t
{
int128_t() = default;

std::uint64_t words[2];
bool operator == (const int128_t& other) const

bool operator==(const int128_t& other) const
{
return words[0] == other.words[0] && words[1] == other.words[1];
}
bool operator != (const int128_t& other) const

bool operator!=(const int128_t& other) const
{
return !(*this == other);
}
};

struct int256_t
{
int256_t() = default;
std::uint64_t words[4];
bool operator == (const int256_t& other) const

bool operator==(const int256_t& other) const
{
return words[0] == other.words[0] && words[1] == other.words[1] && words[2] == other.words[2] && words[3] == other.words[3];
return words[0] == other.words[0] && words[1] == other.words[1] && words[2] == other.words[2]
&& words[3] == other.words[3];
}
bool operator != (const int256_t& other) const

bool operator!=(const int256_t& other) const
{
return !(*this == other);
}
};
template<class T>
template <class T>
constexpr bool is_int_placeholder_v = std::is_same_v<T, int128_t> || std::is_same_v<T, int256_t>;

#else
template<class T>
#else

template <class T>
constexpr bool is_int_placeholder_v = false;
constexpr bool large_int_placeholders = false;
using int128_t = primesum::int128_t;
using int256_t = primesum::int256_t;

template<class T>
requires (std::is_same_v<T, int128_t> || std::is_same_v<T, int256_t>)
template <class T>
requires(std::is_same_v<T, int128_t> || std::is_same_v<T, int256_t>)
inline std::ostream& operator<<(std::ostream& stream, T n)
{
std::string str;
Expand All @@ -93,5 +114,37 @@ namespace sparrow

return stream;
}
#endif
} // namespace sparrow
#endif
} // namespace sparrow

#if defined(__cpp_lib_format) && defined(SPARROW_USE_LARGE_INT_PLACEHOLDERS)

template <>
struct std::formatter<sparrow::int128_t>
{
constexpr auto parse(std::format_parse_context& ctx)
{
return ctx.begin(); // Simple implementation
}

auto format(const sparrow::int128_t& n, std::format_context& ctx) const
{
return std::format_to(ctx.out(), "{}", n);
}
};

template <>
struct std::formatter<sparrow::int256_t>
{
constexpr auto parse(std::format_parse_context& ctx)
{
return ctx.begin(); // Simple implementation
}

auto format(const sparrow::int256_t& n, std::format_context& ctx) const
{
return std::format_to(ctx.out(), "{}", n);
}
};

#endif
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,4 @@ add_custom_target(run_tests_with_junit_report
)

set_target_properties(run_tests_with_junit_report PROPERTIES FOLDER "Tests utilities")

Loading

0 comments on commit 2841b40

Please sign in to comment.