Skip to content

Commit 6b04fa5

Browse files
feat(clp-s::timestamp_parser): Add initial partial implementation of timestamp parsing utility. (#1385)
Co-authored-by: Lin Zhihao <[email protected]>
1 parent 8071934 commit 6b04fa5

File tree

9 files changed

+691
-0
lines changed

9 files changed

+691
-0
lines changed

components/core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ set(SOURCE_FILES_clp_s_unitTest
406406
src/clp_s/TimestampDictionaryWriter.hpp
407407
src/clp_s/TimestampEntry.cpp
408408
src/clp_s/TimestampEntry.hpp
409+
src/clp_s/timestamp_parser/test/test_TimestampParser.cpp
409410
src/clp_s/Utils.cpp
410411
src/clp_s/Utils.hpp
411412
src/clp_s/ZstdCompressor.cpp
@@ -750,6 +751,7 @@ if(CLP_BUILD_TESTING)
750751
clp_s::search::ast
751752
clp_s::search::kql
752753
clp_s::search::sql
754+
clp_s::timestamp_parser
753755
clp_s::timestamp_pattern
754756
date::date
755757
fmt::fmt

components/core/cmake/Options/options.cmake

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ option(
8383
ON
8484
)
8585

86+
option(
87+
CLP_BUILD_CLP_S_TIMESTAMP_PARSER
88+
"Build clp_s::timestamp_parser"
89+
ON
90+
)
91+
8692
option(
8793
CLP_BUILD_CLP_S_TIMESTAMPPATTERN
8894
"Build clp_s::timestamp_pattern."
@@ -160,6 +166,7 @@ function(validate_clp_tests_dependencies)
160166
CLP_BUILD_CLP_S_SEARCH_KQL
161167
CLP_BUILD_CLP_S_SEARCH_SQL
162168
CLP_BUILD_CLP_S_TIMESTAMPPATTERN
169+
CLP_BUILD_CLP_S_TIMESTAMP_PARSER
163170
)
164171
endfunction()
165172

@@ -360,6 +367,19 @@ function(set_clp_s_search_sql_dependencies)
360367
)
361368
endfunction()
362369

370+
function(validate_clp_s_timestamp_parser_dependencies)
371+
validate_clp_dependencies_for_target(CLP_BUILD_CLP_S_TIMESTAMP_PARSER
372+
CLP_BUILD_CLP_STRING_UTILS
373+
)
374+
endfunction()
375+
376+
function(set_clp_s_timestamp_parser_dependencies)
377+
set_clp_need_flags(
378+
CLP_NEED_DATE
379+
CLP_NEED_YSTDLIB
380+
)
381+
endfunction()
382+
363383
function(validate_clp_s_timestamppattern_dependencies)
364384
validate_clp_dependencies_for_target(CLP_BUILD_CLP_S_TIMESTAMPPATTERN
365385
CLP_BUILD_CLP_STRING_UTILS
@@ -444,6 +464,11 @@ function(validate_and_setup_all_clp_dependency_flags)
444464
set_clp_s_search_sql_dependencies()
445465
endif()
446466

467+
if (CLP_BUILD_CLP_S_TIMESTAMP_PARSER)
468+
validate_clp_s_timestamp_parser_dependencies()
469+
set_clp_s_timestamp_parser_dependencies()
470+
endif()
471+
447472
if (CLP_BUILD_CLP_S_TIMESTAMPPATTERN)
448473
validate_clp_s_timestamppattern_dependencies()
449474
set_clp_s_timestamppattern_dependencies()

components/core/src/clp_s/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
add_subdirectory(indexer)
22
add_subdirectory(log_converter)
33
add_subdirectory(search)
4+
add_subdirectory(timestamp_parser)
45

56
set(
67
CLP_S_CLP_SOURCES
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
set(
2+
CLP_S_TIMESTAMP_PARSER_SOURCES
3+
../Defs.hpp
4+
TimestampParser.cpp
5+
TimestampParser.hpp
6+
ErrorCode.cpp
7+
ErrorCode.hpp
8+
)
9+
10+
if(CLP_BUILD_CLP_S_TIMESTAMP_PARSER)
11+
add_library(
12+
clp_s_timestamp_parser
13+
${CLP_S_TIMESTAMP_PARSER_SOURCES}
14+
)
15+
add_library(clp_s::timestamp_parser ALIAS clp_s_timestamp_parser)
16+
target_compile_features(clp_s_timestamp_parser PRIVATE cxx_std_20)
17+
target_include_directories(clp_s_timestamp_parser PUBLIC ../../)
18+
target_link_libraries(
19+
clp_s_timestamp_parser
20+
PRIVATE
21+
clp::string_utils
22+
date::date
23+
ystdlib::error_handling
24+
)
25+
endif()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "ErrorCode.hpp"
2+
3+
#include <string>
4+
5+
#include <ystdlib/error_handling/ErrorCode.hpp>
6+
7+
namespace {
8+
using clp_s::timestamp_parser::ErrorCodeEnum;
9+
using ErrorCategory = ystdlib::error_handling::ErrorCategory<ErrorCodeEnum>;
10+
} // namespace
11+
12+
template <>
13+
auto ErrorCategory::name() const noexcept -> char const* {
14+
return "clp_s::timestamp_parser::ErrorCode";
15+
}
16+
17+
template <>
18+
auto ErrorCategory::message(ErrorCodeEnum error_enum) const -> std::string {
19+
switch (error_enum) {
20+
case ErrorCodeEnum::InvalidTimestampPattern:
21+
return "Encountered timestamp pattern with invalid syntax.";
22+
case ErrorCodeEnum::IncompatibleTimestampPattern:
23+
return "Timestamp pattern does not match the format of the given timestamp.";
24+
case ErrorCodeEnum::InvalidDate:
25+
return "Timestamp was parsed successfully, but did not yield a valid date.";
26+
case ErrorCodeEnum::FormatSpecifierNotImplemented:
27+
return "Encountered unimplemented format specifier in timestamp pattern.";
28+
default:
29+
return "Unknown error code enum.";
30+
}
31+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef CLP_S_TIMESTAMP_PARSER_ERRORCODE_HPP
2+
#define CLP_S_TIMESTAMP_PARSER_ERRORCODE_HPP
3+
4+
#include <cstdint>
5+
6+
#include <ystdlib/error_handling/ErrorCode.hpp>
7+
8+
namespace clp_s::timestamp_parser {
9+
enum class ErrorCodeEnum : uint8_t {
10+
InvalidTimestampPattern = 1,
11+
IncompatibleTimestampPattern,
12+
InvalidDate,
13+
FormatSpecifierNotImplemented
14+
};
15+
16+
using ErrorCode = ystdlib::error_handling::ErrorCode<ErrorCodeEnum>;
17+
} // namespace clp_s::timestamp_parser
18+
19+
YSTDLIB_ERROR_HANDLING_MARK_AS_ERROR_CODE_ENUM(clp_s::timestamp_parser::ErrorCodeEnum);
20+
21+
#endif // CLP_S_TIMESTAMP_PARSER_ERRORCODE_HPP

0 commit comments

Comments
 (0)