Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to set Monday as first day of week #623

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions QueryEngine/Execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ bool g_enable_smem_non_grouped_agg{
// non-grouped aggregates
bool g_is_test_env{false}; // operating under a unit test environment. Currently only
// limits the allocation for the output buffer arena
bool g_monday_first_weekday{false};

size_t g_approx_quantile_buffer{1000};
size_t g_approx_quantile_centroids{300};
Expand Down
2 changes: 1 addition & 1 deletion QueryEngine/ExtractFromTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ extern "C" ALWAYS_INLINE DEVICE int64_t extract_nanosecond(const int64_t lcltime
// First day of epoch is Thursday, so + 4 to have Sunday=0.
extern "C" ALWAYS_INLINE DEVICE int64_t extract_dow(const int64_t lcltime) {
int64_t const days_past_epoch = floor_div(lcltime, kSecsPerDay);
return unsigned_mod(days_past_epoch + 4, kDaysPerWeek);
return unsigned_mod(days_past_epoch + 4 - g_monday_first_weekday, kDaysPerWeek);
}

extern "C" ALWAYS_INLINE DEVICE int64_t extract_quarterday(const int64_t lcltime) {
Expand Down
25 changes: 25 additions & 0 deletions Tests/ExecuteTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4903,6 +4903,31 @@ TEST(Select, Time) {
"test WHERE (m >= TIMESTAMP(3) '1970-01-01 "
"00:00:00.000') GROUP BY key0 ORDER BY key0 LIMIT 1;",
dt)));

// test first weekday option
bool prev_monday_first_weekday = g_monday_first_weekday;
g_monday_first_weekday = true;
// Monday
ASSERT_EQ(0,
v<int64_t>(run_simple_agg("SELECT EXTRACT(DOW FROM CAST('2008-03-03 "
"20:00:11' AS TIMESTAMP)) FROM test limit 1;",
dt)));
// Wednesday
ASSERT_EQ(2,
v<int64_t>(run_simple_agg("SELECT EXTRACT(DOW FROM CAST('2021-01-27 "
"20:15:12' AS TIMESTAMP)) FROM test limit 1;",
dt)));
// Saturday
ASSERT_EQ(5,
v<int64_t>(run_simple_agg("SELECT EXTRACT(DOW FROM CAST('2020-11-14 "
"14:47:12' AS TIMESTAMP)) FROM test limit 1;",
dt)));
// Sunday
ASSERT_EQ(6,
v<int64_t>(run_simple_agg("SELECT EXTRACT(DOW FROM CAST('2020-09-27 "
"21:30:12' AS TIMESTAMP)) FROM test limit 1;",
dt)));
g_monday_first_weekday = prev_monday_first_weekday;
}
}

Expand Down
5 changes: 5 additions & 0 deletions ThriftHandler/CommandLineOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ void CommandLineOptions::fillOptions() {
->default_value(g_null_div_by_zero)
->implicit_value(true),
"Return null on division by zero instead of throwing an exception.");
help_desc.add_options()("monday-first-weekday",
po::value<bool>(&g_monday_first_weekday)
->default_value(g_monday_first_weekday)
->implicit_value(true),
"Set Monday as first day of week instead of Sunday");
help_desc.add_options()(
"num-reader-threads",
po::value<size_t>(&num_reader_threads)->default_value(num_reader_threads),
Expand Down
1 change: 1 addition & 0 deletions ThriftHandler/CommandLineOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ extern size_t g_gpu_smem_threshold;
extern bool g_enable_smem_non_grouped_agg;
extern bool g_enable_smem_grouped_non_count_agg;
extern bool g_use_estimator_result_cache;
extern bool g_monday_first_weekday;

extern int64_t g_omni_kafka_seek;
extern size_t g_leaf_count;
Expand Down