@@ -121,33 +121,6 @@ class DateTimeFunctionsTest : public functions::test::FunctionBaseTest {
121
121
}
122
122
};
123
123
124
- std::optional<Timestamp> dateParse (
125
- const std::optional<std::string>& input,
126
- const std::optional<std::string>& format) {
127
- auto resultVector = evaluate (
128
- " date_parse(c0, c1)" ,
129
- makeRowVector (
130
- {makeNullableFlatVector<std::string>({input}),
131
- makeNullableFlatVector<std::string>({format})}));
132
- EXPECT_EQ (1 , resultVector->size ());
133
-
134
- if (resultVector->isNullAt (0 )) {
135
- return std::nullopt;
136
- }
137
- return resultVector->as <SimpleVector<Timestamp>>()->valueAt (0 );
138
- }
139
-
140
- std::optional<std::string> dateFormat (
141
- std::optional<Timestamp> timestamp,
142
- const std::string& format) {
143
- auto resultVector = evaluate (
144
- " date_format(c0, c1)" ,
145
- makeRowVector (
146
- {makeNullableFlatVector<Timestamp>({timestamp}),
147
- makeNullableFlatVector<std::string>({format})}));
148
- return resultVector->as <SimpleVector<StringView>>()->valueAt (0 );
149
- }
150
-
151
124
template <typename T>
152
125
std::optional<T> evaluateWithTimestampWithTimezone (
153
126
const std::string& expression,
@@ -3311,14 +3284,14 @@ TEST_F(DateTimeFunctionsTest, formatDateTimeTimezone) {
3311
3284
}
3312
3285
3313
3286
TEST_F (DateTimeFunctionsTest, dateFormat) {
3314
- const auto dateFormatOnce = [&](std::optional<Timestamp> timestamp,
3315
- const std::string& formatString) {
3316
- return evaluateOnce<std::string>(
3317
- fmt::format (" date_format(c0, '{}')" , formatString), timestamp);
3287
+ const auto dateFormat = [&](std::optional<Timestamp> timestamp,
3288
+ std::optional<std::string> format) {
3289
+ return evaluateOnce<std::string>(" date_format(c0, c1)" , timestamp, format);
3318
3290
};
3319
3291
3320
3292
// Check null behaviors
3321
- EXPECT_EQ (std::nullopt, dateFormatOnce (std::nullopt, " %Y" ));
3293
+ EXPECT_EQ (std::nullopt, dateFormat (std::nullopt, " %Y" ));
3294
+ EXPECT_EQ (std::nullopt, dateFormat (Timestamp (0 , 0 ), std::nullopt));
3322
3295
3323
3296
// Normal cases
3324
3297
EXPECT_EQ (" 1970-01-01" , dateFormat (parseTimestamp (" 1970-01-01" ), " %Y-%m-%d" ));
@@ -3766,10 +3739,12 @@ TEST_F(DateTimeFunctionsTest, fromIso8601Timestamp) {
3766
3739
}
3767
3740
3768
3741
TEST_F (DateTimeFunctionsTest, dateParseMonthOfYearText) {
3769
- auto parseAndFormat = [&](const std::string& input) {
3770
- return dateFormat (dateParse (input, " %M_%Y" ), " %Y-%m" );
3742
+ auto parseAndFormat = [&](std::optional<std::string> input) {
3743
+ return evaluateOnce<std::string>(
3744
+ " date_format(date_parse(c0, '%M_%Y'), '%Y-%m')" , input);
3771
3745
};
3772
3746
3747
+ EXPECT_EQ (parseAndFormat (std::nullopt), std::nullopt);
3773
3748
EXPECT_EQ (parseAndFormat (" jan_2024" ), " 2024-01" );
3774
3749
EXPECT_EQ (parseAndFormat (" JAN_2024" ), " 2024-01" );
3775
3750
EXPECT_EQ (parseAndFormat (" january_2024" ), " 2024-01" );
@@ -3830,6 +3805,11 @@ TEST_F(DateTimeFunctionsTest, dateParseMonthOfYearText) {
3830
3805
}
3831
3806
3832
3807
TEST_F (DateTimeFunctionsTest, dateParse) {
3808
+ const auto dateParse = [&](std::optional<std::string> input,
3809
+ std::optional<std::string> format) {
3810
+ return evaluateOnce<Timestamp>(" date_parse(c0, c1)" , input, format);
3811
+ };
3812
+
3833
3813
// Check null behavior.
3834
3814
EXPECT_EQ (std::nullopt, dateParse (" 1970-01-01" , std::nullopt));
3835
3815
EXPECT_EQ (std::nullopt, dateParse (std::nullopt, " YYYY-MM-dd" ));
0 commit comments