Skip to content

Commit

Permalink
Support for timestamps
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Jerphanion <[email protected]>
  • Loading branch information
jjerphan committed Apr 23, 2024
1 parent 28056b8 commit 9c06158
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
fail-fast: false
matrix:
os:
- 13
- 14
config:
- { name: Debug }
- { name: Release }
Expand Down
30 changes: 29 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ message(STATUS "Building sparrow v${${PROJECT_NAME}_VERSION}")

OPTION(BUILD_TESTS "sparrow test suite" OFF)

include(CheckCXXSymbolExists)

if(cxx_std_20 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
set(header version)
else()
set(header ciso646)
endif()

check_cxx_symbol_exists(_LIBCPP_VERSION ${header} LIBCPP)
if(LIBCPP)
message(STATUS "Using libc++")
# Allow the use of not visible yet availabile features, such
# as some formatter for new types.
add_compile_definitions(_LIBCPP_DISABLE_AVAILABILITY)
endif()

# Linter options
# =============

Expand All @@ -55,6 +71,16 @@ endif()
# Dependencies
# ============

set(SPARROW_INTERFACE_DEPENDENCIES "" CACHE STRING "List of dependencies to be linked to the sparrow target")

# libc++ does not provide all the elements of the C++20 standard library,
# so we need to use `HowardHinnant/date`.
# See: https://libcxx.llvm.org/Status/Cxx20.html#note-p0355
if (LIBCPP)
find_package(date CONFIG REQUIRED)
list(APPEND SPARROW_INTERFACE_DEPENDENCIES date::date)
endif()

# Build
# =====

Expand All @@ -65,7 +91,7 @@ set(SPARROW_HEADERS
${SPARROW_INCLUDE_DIR}/sparrow/buffer.hpp
${SPARROW_INCLUDE_DIR}/sparrow/buffer_view.hpp
${SPARROW_INCLUDE_DIR}/sparrow/config.hpp
${SPARROW_INCLUDE_DIR}/sparrow/contracts.hpp
${SPARROW_INCLUDE_DIR}/sparrow/contracts.hpp
${SPARROW_INCLUDE_DIR}/sparrow/data_traits.hpp
${SPARROW_INCLUDE_DIR}/sparrow/data_type.hpp
${SPARROW_INCLUDE_DIR}/sparrow/dynamic_bitset.hpp
Expand All @@ -86,6 +112,8 @@ target_include_directories(sparrow INTERFACE
$<BUILD_INTERFACE:${SPARROW_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>)

target_link_libraries(sparrow INTERFACE ${SPARROW_INTERFACE_DEPENDENCIES})

# We do not use non-standard C++
set_target_properties(sparrow PROPERTIES CMAKE_CXX_EXTENSIONS OFF)
target_compile_features(sparrow INTERFACE cxx_std_20)
Expand Down
2 changes: 2 additions & 0 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ dependencies:
# Build
- cmake
- ninja
# Alternative of `std::chrono` introduced in C++20.
- howardhinnant_date
# Tests
- doctest
8 changes: 7 additions & 1 deletion include/sparrow/data_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ namespace sparrow
using default_layout = variable_size_binary_layout<value_type, std::span<byte_t>, const std::span<byte_t>>; // FIXME: this is incorrect, change when we have the right types
};

template <>
struct arrow_traits<timestamp> : common_native_types_traits<timestamp>
{
static constexpr data_type type_id = data_type::TIMESTAMP;
};

namespace predicate
{

Expand All @@ -147,4 +153,4 @@ namespace sparrow
} constexpr has_arrow_traits;
}

}
}
25 changes: 21 additions & 4 deletions include/sparrow/data_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@

#pragma once

#if __cpp_lib_chrono <= 201907L
// P0355R7 (Extending chrono to Calendars and Time Zones) has not been entirely implemented in libc++ yet.
// See: https://libcxx.llvm.org/Status/Cxx20.html#note-p0355
// For now, we use HowardHinnant/date as a replacement if we are compiling with libc++.
// TODO: remove this once libc++ has full support for P0355R7.
# include <chrono>
#else
# include <date/tz.h>
#endif
#include <climits>
#include <cstdint>
#include <optional>
Expand Down Expand Up @@ -45,6 +54,12 @@ namespace sparrow
using float64_t = std::float64_t;
#endif

#if __cpp_lib_chrono <= 201907L
using timestamp = std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>;
#else
using timestamp = date::zoned_time<std::chrono::nanoseconds>;
#endif

// We need to be sure the current target platform is setup to support correctly these types.
static_assert(sizeof(float16_t) == 2);
static_assert(sizeof(float32_t) == 4);
Expand Down Expand Up @@ -82,14 +97,15 @@ namespace sparrow
BINARY,
// Fixed-size binary. Each value occupies the same number of bytes
FIXED_SIZE_BINARY,
// Number of nanoseconds since the UNIX epoch with an optional timezone.
// See: https://arrow.apache.org/docs/python/timestamps.html#timestamps
TIMESTAMP,
};

/// C++ types value representation types matching Arrow types.
// NOTE: this needs to be in sync-order with `data_type`
using all_base_types_t = mpl::typelist<
std::nullopt_t // REVIEW: not sure about if we need to have this one? for representing NA? is this
// the right type?
,
std::nullopt_t,
bool,
std::uint8_t,
std::int8_t,
Expand All @@ -103,7 +119,8 @@ namespace sparrow
float32_t,
float64_t,
std::string,
std::vector<byte_t>
std::vector<byte_t>,
sparrow::timestamp
// TODO: add missing fundamental types here
>;

Expand Down

0 comments on commit 9c06158

Please sign in to comment.