[MCOL-1389] EXTRACT(WEEK FROM CDATE) returned 1 based week number, instead of 0 based Created: 2018-05-04  Updated: 2022-11-05  Resolved: 2022-11-05

Status: Closed
Project: MariaDB ColumnStore
Component/s: N/A
Affects Version/s: 1.1.4
Fix Version/s: Icebox, 1.4.5

Type: Bug Priority: Major
Reporter: Daniel Lee (Inactive) Assignee: Unassigned
Resolution: Won't Do Votes: 0
Labels: None

Issue Links:
Relates
relates to MCOL-1397 MariaDB session variables should be p... Closed

 Description   

Build tested: 1.1.4-1

------------------------------------+

CDATE EXTRACT(WEEK FROM CDATE)

------------------------------------+

2018-05-04 18
2018-05-05 18
2018-05-06 19
2018-05-07 19
2018-05-14 20
2018-05-14 20
2018-05-21 21
2018-05-28 22
2018-12-31 53
2018-01-01 1
2018-01-08 2

------------------------------------+
11 rows in set (0.01 sec)



 Comments   
Comment by Andrew Hutchings (Inactive) [ 2018-05-04 ]

Documentation bug. See code:

// Returns a week index conforming to the MySQL WEEK() function.  Note
// that modeflags is not the MySQL mode - it is a bitmask of the abvoe
// 3 flags.  The utility function convert_mysql_mode_to_modeflags should
// be applied to the MySQL mode before calling this function (or the
// flags may be used directly).  The optional argument is for callers
// that need to know the year that the week actually corresponds to -
// see MySQL documentation for how the year returned can be different
// than the year of the input date

Comment by David Hall (Inactive) [ 2018-05-07 ]

From PostGreSQL

The number of the week of the year that the day is in. By definition (ISO 8601), the first week of a year contains January 4 of that year. (The ISO-8601 week starts on Monday.) In other words, the first Thursday of a year is in week 1 of that year. (for timestamp values only)

Because of this, it is possible for early January dates to be part of the 52nd or 53rd week of the previous year. For example, 2005-01-01 is part of the 53rd week of year 2004, and 2006-01-01 is part of the 52nd week of year 2005.

From Oracle

WEEK (1 - 53) Returns the rank of the week in the year, where the first week starts on the first day of the year.

From these, I conclude that EXTRACT(WEEK..) should return a 1 based number.

Comment by Daniel Lee (Inactive) [ 2018-05-07 ]

I was comparing the MariaDB server and assumed MariaDB is correct. Does that mean a bug in the server? or we are just going with different standard.

I even compared results for days in May and they are off by 1.

Comment by David Hall (Inactive) [ 2018-05-07 ]

Seems it's a bit more complicated. According to https://mariadb.com/kb/en/library/week/, this is configurable via system variable default-week-format. We don't currently bring system variables down to functions. We may want to consider doing that.

Comment by Andrew Hutchings (Inactive) [ 2018-05-08 ]

There are two separate problems here:

1. We need to document what is in my first comment (this bug)
2. We should push down MariaDB's session variables into ExeMgr and PrimProc so that we can use the variable for this, then the behaviour will be the same as MariaDB. This should be a feature request. I'll file this shortly.

Comment by Andrew Hutchings (Inactive) [ 2018-06-15 ]

Actually this isn't a documentation bug. For WEEK() the plugin takes the MariaDB system variable and makes this a parameter. It doesn't do this for EXTRACT() with WEEK.

Comment by Todd Stoffel (Inactive) [ 2022-11-05 ]

Item is out of date. Closing due to inactivity. If you feel this was done in error please open a new ticket.

Generated at Thu Feb 08 02:28:23 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.