Skip to content

Commit 03c8e8f

Browse files
committed
move
1 parent 40b8ddb commit 03c8e8f

File tree

5 files changed

+121
-68
lines changed

5 files changed

+121
-68
lines changed

src/iceberg/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ set(ICEBERG_SOURCES
5050
arrow_c_data_guard_internal.cc
5151
util/murmurhash3_internal.cc
5252
util/timepoint.cc
53-
util/gzip_internal.cc)
53+
util/gzip_internal.cc
54+
util/literal_format.cc)
5455

5556
set(ICEBERG_STATIC_BUILD_INTERFACE_LIBS)
5657
set(ICEBERG_SHARED_BUILD_INTERFACE_LIBS)

src/iceberg/expression/literal.cc

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,12 @@
1919

2020
#include "iceberg/expression/literal.h"
2121

22-
#include <chrono>
23-
#include <cmath>
2422
#include <concepts>
2523
#include <cstring>
26-
#include <iomanip>
27-
#include <sstream>
2824

2925
#include "iceberg/exception.h"
3026
#include "iceberg/util/endian.h"
27+
#include "iceberg/util/literal_format.h"
3128
#include "iceberg/util/macros.h"
3229

3330
namespace iceberg {
@@ -629,54 +626,4 @@ Result<Literal> LiteralSerializer::FromBytes(std::span<const uint8_t> data,
629626
std::unreachable();
630627
}
631628

632-
// Literal formatting member functions
633-
634-
std::string Literal::FormatDate(int32_t days_since_epoch) const {
635-
// Convert days since Unix epoch to date
636-
auto time_point =
637-
std::chrono::system_clock::time_point{} + std::chrono::days{days_since_epoch};
638-
auto date = std::chrono::floor<std::chrono::days>(time_point);
639-
auto ymd = std::chrono::year_month_day{date};
640-
641-
std::ostringstream oss;
642-
oss << static_cast<int>(ymd.year()) << "-" << std::setfill('0') << std::setw(2)
643-
<< static_cast<unsigned>(ymd.month()) << "-" << std::setfill('0') << std::setw(2)
644-
<< static_cast<unsigned>(ymd.day());
645-
return oss.str();
646-
}
647-
648-
std::string Literal::FormatTime(int64_t microseconds_since_midnight) const {
649-
auto hours = microseconds_since_midnight / (1000000LL * 3600);
650-
auto minutes = (microseconds_since_midnight % (1000000LL * 3600)) / (1000000LL * 60);
651-
auto seconds = (microseconds_since_midnight % (1000000LL * 60)) / 1000000LL;
652-
auto micros = microseconds_since_midnight % 1000000LL;
653-
654-
std::ostringstream oss;
655-
oss << std::setfill('0') << std::setw(2) << hours << ":" << std::setfill('0')
656-
<< std::setw(2) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds
657-
<< "." << std::setfill('0') << std::setw(6) << micros;
658-
return oss.str();
659-
}
660-
661-
std::string Literal::FormatTimestamp(int64_t microseconds_since_epoch) const {
662-
auto time_point = std::chrono::system_clock::time_point{} +
663-
std::chrono::microseconds{microseconds_since_epoch};
664-
auto date = std::chrono::floor<std::chrono::days>(time_point);
665-
auto time_of_day = time_point - date;
666-
auto micros_of_day =
667-
std::chrono::duration_cast<std::chrono::microseconds>(time_of_day).count();
668-
669-
auto ymd = std::chrono::year_month_day{date};
670-
671-
std::ostringstream oss;
672-
oss << static_cast<int>(ymd.year()) << "-" << std::setfill('0') << std::setw(2)
673-
<< static_cast<unsigned>(ymd.month()) << "-" << std::setfill('0') << std::setw(2)
674-
<< static_cast<unsigned>(ymd.day()) << "T" << FormatTime(micros_of_day);
675-
return oss.str();
676-
}
677-
678-
std::string Literal::FormatTimestampTz(int64_t microseconds_since_epoch) const {
679-
return FormatTimestamp(microseconds_since_epoch) + "+00:00";
680-
}
681-
682629
} // namespace iceberg

src/iceberg/expression/literal.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,6 @@ class ICEBERG_EXPORT Literal {
146146
friend class LiteralCaster;
147147
friend class LiteralSerializer;
148148

149-
/// \brief Format a date value as a string.
150-
std::string FormatDate(int32_t days_since_epoch) const;
151-
152-
/// \brief Format a time value as a string.
153-
std::string FormatTime(int64_t microseconds_since_midnight) const;
154-
155-
/// \brief Format a timestamp value as a string.
156-
std::string FormatTimestamp(int64_t microseconds_since_epoch) const;
157-
158-
/// \brief Format a timestamp with timezone value as a string.
159-
std::string FormatTimestampTz(int64_t microseconds_since_epoch) const;
160-
161-
private:
162149
Value value_;
163150
std::shared_ptr<PrimitiveType> type_;
164151
};

src/iceberg/util/literal_format.cc

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#include "literal_format.h"
21+
22+
#include <chrono>
23+
#include <cstring>
24+
#include <iomanip>
25+
26+
namespace iceberg {
27+
28+
std::string FormatDate(int32_t days_since_epoch) {
29+
// Convert days since Unix epoch to date
30+
auto time_point =
31+
std::chrono::system_clock::time_point{} + std::chrono::days{days_since_epoch};
32+
auto date = std::chrono::floor<std::chrono::days>(time_point);
33+
auto ymd = std::chrono::year_month_day{date};
34+
35+
std::ostringstream oss;
36+
oss << static_cast<int>(ymd.year()) << "-" << std::setfill('0') << std::setw(2)
37+
<< static_cast<unsigned>(ymd.month()) << "-" << std::setfill('0') << std::setw(2)
38+
<< static_cast<unsigned>(ymd.day());
39+
return oss.str();
40+
}
41+
42+
std::string FormatTime(int64_t microseconds_since_midnight) {
43+
auto hours = microseconds_since_midnight / (1000000LL * 3600);
44+
auto minutes = (microseconds_since_midnight % (1000000LL * 3600)) / (1000000LL * 60);
45+
auto seconds = (microseconds_since_midnight % (1000000LL * 60)) / 1000000LL;
46+
auto micros = microseconds_since_midnight % 1000000LL;
47+
48+
std::ostringstream oss;
49+
oss << std::setfill('0') << std::setw(2) << hours << ":" << std::setfill('0')
50+
<< std::setw(2) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds
51+
<< "." << std::setfill('0') << std::setw(6) << micros;
52+
return oss.str();
53+
}
54+
55+
std::string FormatTimestamp(int64_t microseconds_since_epoch) {
56+
auto time_point = std::chrono::system_clock::time_point{} +
57+
std::chrono::microseconds{microseconds_since_epoch};
58+
auto date = std::chrono::floor<std::chrono::days>(time_point);
59+
auto time_of_day = time_point - date;
60+
auto micros_of_day =
61+
std::chrono::duration_cast<std::chrono::microseconds>(time_of_day).count();
62+
63+
auto ymd = std::chrono::year_month_day{date};
64+
65+
std::ostringstream oss;
66+
oss << static_cast<int>(ymd.year()) << "-" << std::setfill('0') << std::setw(2)
67+
<< static_cast<unsigned>(ymd.month()) << "-" << std::setfill('0') << std::setw(2)
68+
<< static_cast<unsigned>(ymd.day()) << "T" << FormatTime(micros_of_day);
69+
return oss.str();
70+
}
71+
72+
std::string FormatTimestampTz(int64_t microseconds_since_epoch) {
73+
return FormatTimestamp(microseconds_since_epoch) + "+00:00";
74+
}
75+
76+
} // namespace iceberg

src/iceberg/util/literal_format.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#pragma once
21+
22+
#include <string>
23+
24+
#include "iceberg/iceberg_export.h"
25+
26+
/// \file iceberg/
27+
28+
namespace iceberg {
29+
30+
/// \brief Format a date value as a string.
31+
ICEBERG_EXPORT std::string FormatDate(int32_t days_since_epoch);
32+
33+
/// \brief Format a time value as a string.
34+
ICEBERG_EXPORT std::string FormatTime(int64_t microseconds_since_midnight);
35+
36+
/// \brief Format a timestamp value as a string.
37+
ICEBERG_EXPORT std::string FormatTimestamp(int64_t microseconds_since_epoch);
38+
39+
/// \brief Format a timestamp with timezone value as a string.
40+
ICEBERG_EXPORT std::string FormatTimestampTz(int64_t microseconds_since_epoch);
41+
42+
} // namespace iceberg

0 commit comments

Comments
 (0)