duckdb 0.3.2-dev1133.0 → 0.3.2-dev1141.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "duckdb",
3
3
  "main": "./lib/duckdb.js",
4
- "version": "0.3.2-dev1133.0",
4
+ "version": "0.3.2-dev1141.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -30993,29 +30993,44 @@ int32_t Date::ExtractISODayOfTheWeek(date_t date) {
30993
30993
  }
30994
30994
  }
30995
30995
 
30996
- static int32_t GetISOWeek(int32_t year, int32_t month, int32_t day) {
30996
+ static int32_t GetISOYearWeek(int32_t &year, int32_t month, int32_t day) {
30997
30997
  auto day_of_the_year =
30998
30998
  (Date::IsLeapYear(year) ? Date::CUMULATIVE_LEAP_DAYS[month] : Date::CUMULATIVE_DAYS[month]) + day;
30999
30999
  // get the first day of the first week of the year
31000
31000
  // the first week is the week that has the 4th of January in it
31001
- auto day_of_the_fourth = Date::ExtractISODayOfTheWeek(Date::FromDate(year, 1, 4));
31001
+ const auto weekday_of_the_fourth = Date::ExtractISODayOfTheWeek(Date::FromDate(year, 1, 4));
31002
31002
  // if fourth is monday, then fourth is the first day
31003
31003
  // if fourth is tuesday, third is the first day
31004
31004
  // if fourth is wednesday, second is the first day
31005
- // if fourth is thursday - sunday, first is the first day
31006
- auto first_day_of_the_first_week = day_of_the_fourth >= 4 ? 0 : 5 - day_of_the_fourth;
31007
- if (day_of_the_year < first_day_of_the_first_week) {
31008
- // day is part of last year
31009
- return GetISOWeek(year - 1, 12, day);
31005
+ // if fourth is thursday, first is the first day
31006
+ // if fourth is friday - sunday, day is in the previous year
31007
+ // (day is 0-based, weekday is 1-based)
31008
+ const auto first_day_of_the_first_isoweek = 4 - weekday_of_the_fourth;
31009
+ if (day_of_the_year < first_day_of_the_first_isoweek) {
31010
+ // day is part of last year (13th month)
31011
+ --year;
31012
+ return GetISOYearWeek(year, 12, day);
31010
31013
  } else {
31011
- return ((day_of_the_year - first_day_of_the_first_week) / 7) + 1;
31014
+ return ((day_of_the_year - first_day_of_the_first_isoweek) / 7) + 1;
31012
31015
  }
31013
31016
  }
31014
31017
 
31015
- int32_t Date::ExtractISOWeekNumber(date_t date) {
31016
- int32_t year, month, day;
31018
+ void Date::ExtractISOYearWeek(date_t date, int32_t &year, int32_t &week) {
31019
+ int32_t month, day;
31017
31020
  Date::Convert(date, year, month, day);
31018
- return GetISOWeek(year, month - 1, day - 1);
31021
+ week = GetISOYearWeek(year, month - 1, day - 1);
31022
+ }
31023
+
31024
+ int32_t Date::ExtractISOWeekNumber(date_t date) {
31025
+ int32_t year, week;
31026
+ ExtractISOYearWeek(date, year, week);
31027
+ return week;
31028
+ }
31029
+
31030
+ int32_t Date::ExtractISOYearNumber(date_t date) {
31031
+ int32_t year, week;
31032
+ ExtractISOYearWeek(date, year, week);
31033
+ return year;
31019
31034
  }
31020
31035
 
31021
31036
  int32_t Date::ExtractWeekNumberRegular(date_t date, bool monday_first) {
@@ -32110,6 +32125,7 @@ enum class DatePartSpecifier : uint8_t {
32110
32125
  DOW,
32111
32126
  ISODOW,
32112
32127
  WEEK,
32128
+ ISOYEAR,
32113
32129
  QUARTER,
32114
32130
  DOY,
32115
32131
  YEARWEEK,
@@ -75244,6 +75260,13 @@ struct DateDiff {
75244
75260
  }
75245
75261
  };
75246
75262
 
75263
+ struct ISOYearOperator {
75264
+ template <class TA, class TB, class TR>
75265
+ static inline TR Operation(TA startdate, TB enddate) {
75266
+ return Date::ExtractISOYearNumber(enddate) - Date::ExtractISOYearNumber(startdate);
75267
+ }
75268
+ };
75269
+
75247
75270
  struct MicrosecondsOperator {
75248
75271
  template <class TA, class TB, class TR>
75249
75272
  static inline TR Operation(TA startdate, TB enddate) {
@@ -75329,6 +75352,12 @@ int64_t DateDiff::WeekOperator::Operation(timestamp_t startdate, timestamp_t end
75329
75352
  return WeekOperator::Operation<date_t, date_t, int64_t>(Timestamp::GetDate(startdate), Timestamp::GetDate(enddate));
75330
75353
  }
75331
75354
 
75355
+ template <>
75356
+ int64_t DateDiff::ISOYearOperator::Operation(timestamp_t startdate, timestamp_t enddate) {
75357
+ return ISOYearOperator::Operation<date_t, date_t, int64_t>(Timestamp::GetDate(startdate),
75358
+ Timestamp::GetDate(enddate));
75359
+ }
75360
+
75332
75361
  template <>
75333
75362
  int64_t DateDiff::MicrosecondsOperator::Operation(timestamp_t startdate, timestamp_t enddate) {
75334
75363
  return Timestamp::GetEpochMicroSeconds(enddate) - Timestamp::GetEpochMicroSeconds(startdate);
@@ -75397,6 +75426,11 @@ int64_t DateDiff::WeekOperator::Operation(dtime_t startdate, dtime_t enddate) {
75397
75426
  throw NotImplementedException("\"time\" units \"week\" not recognized");
75398
75427
  }
75399
75428
 
75429
+ template <>
75430
+ int64_t DateDiff::ISOYearOperator::Operation(dtime_t startdate, dtime_t enddate) {
75431
+ throw NotImplementedException("\"time\" units \"isoyear\" not recognized");
75432
+ }
75433
+
75400
75434
  template <>
75401
75435
  int64_t DateDiff::MicrosecondsOperator::Operation(dtime_t startdate, dtime_t enddate) {
75402
75436
  return enddate.micros - startdate.micros;
@@ -75445,6 +75479,8 @@ static int64_t DifferenceDates(DatePartSpecifier type, TA startdate, TB enddate)
75445
75479
  case DatePartSpecifier::WEEK:
75446
75480
  case DatePartSpecifier::YEARWEEK:
75447
75481
  return DateDiff::WeekOperator::template Operation<TA, TB, TR>(startdate, enddate);
75482
+ case DatePartSpecifier::ISOYEAR:
75483
+ return DateDiff::ISOYearOperator::template Operation<TA, TB, TR>(startdate, enddate);
75448
75484
  case DatePartSpecifier::MICROSECONDS:
75449
75485
  return DateDiff::MicrosecondsOperator::template Operation<TA, TB, TR>(startdate, enddate);
75450
75486
  case DatePartSpecifier::MILLISECONDS:
@@ -75499,6 +75535,9 @@ static void DateDiffBinaryExecutor(DatePartSpecifier type, Vector &left, Vector
75499
75535
  case DatePartSpecifier::YEARWEEK:
75500
75536
  BinaryExecutor::ExecuteStandard<TA, TB, TR, DateDiff::WeekOperator>(left, right, result, count);
75501
75537
  break;
75538
+ case DatePartSpecifier::ISOYEAR:
75539
+ BinaryExecutor::ExecuteStandard<TA, TB, TR, DateDiff::ISOYearOperator>(left, right, result, count);
75540
+ break;
75502
75541
  case DatePartSpecifier::MICROSECONDS:
75503
75542
  BinaryExecutor::ExecuteStandard<TA, TB, TR, DateDiff::MicrosecondsOperator>(left, right, result, count);
75504
75543
  break;
@@ -75607,7 +75646,7 @@ bool TryGetDatePartSpecifier(const string &specifier_p, DatePartSpecifier &resul
75607
75646
  // isodow (Monday = 1, Sunday = 7)
75608
75647
  result = DatePartSpecifier::ISODOW;
75609
75648
  } else if (specifier == "week" || specifier == "weeks" || specifier == "w" || specifier == "weekofyear") {
75610
- // week number
75649
+ // ISO week number
75611
75650
  result = DatePartSpecifier::WEEK;
75612
75651
  } else if (specifier == "doy" || specifier == "dayofyear") {
75613
75652
  // day of the year (1-365/366)
@@ -75616,8 +75655,11 @@ bool TryGetDatePartSpecifier(const string &specifier_p, DatePartSpecifier &resul
75616
75655
  // quarter of the year (1-4)
75617
75656
  result = DatePartSpecifier::QUARTER;
75618
75657
  } else if (specifier == "yearweek") {
75619
- // Combined year and week YYYYWW
75658
+ // Combined isoyear and isoweek YYYYWW
75620
75659
  result = DatePartSpecifier::YEARWEEK;
75660
+ } else if (specifier == "isoyear") {
75661
+ // ISO year (first week of the year may be in previous year)
75662
+ result = DatePartSpecifier::ISOYEAR;
75621
75663
  } else if (specifier == "era") {
75622
75664
  result = DatePartSpecifier::ERA;
75623
75665
  } else if (specifier == "timezone") {
@@ -75656,6 +75698,7 @@ DatePartSpecifier GetDateTypePartSpecifier(const string &specifier, LogicalType
75656
75698
  case DatePartSpecifier::MILLENNIUM:
75657
75699
  case DatePartSpecifier::DOW:
75658
75700
  case DatePartSpecifier::ISODOW:
75701
+ case DatePartSpecifier::ISOYEAR:
75659
75702
  case DatePartSpecifier::WEEK:
75660
75703
  case DatePartSpecifier::QUARTER:
75661
75704
  case DatePartSpecifier::DOY:
@@ -75958,6 +76001,20 @@ struct DatePart {
75958
76001
  }
75959
76002
  };
75960
76003
 
76004
+ struct ISOYearOperator {
76005
+ template <class TA, class TR>
76006
+ static inline TR Operation(TA input) {
76007
+ return Date::ExtractISOYearNumber(input);
76008
+ }
76009
+
76010
+ template <class T>
76011
+ static unique_ptr<BaseStatistics> PropagateStatistics(ClientContext &context, BoundFunctionExpression &expr,
76012
+ FunctionData *bind_data,
76013
+ vector<unique_ptr<BaseStatistics>> &child_stats) {
76014
+ return PropagateDatePartStatistics<T, ISOYearOperator>(child_stats);
76015
+ }
76016
+ };
76017
+
75961
76018
  struct YearWeekOperator {
75962
76019
  template <class TR>
75963
76020
  static inline TR YearWeekFromParts(TR yyyy, TR ww) {
@@ -75966,7 +76023,9 @@ struct DatePart {
75966
76023
 
75967
76024
  template <class TA, class TR>
75968
76025
  static inline TR Operation(TA input) {
75969
- return YearWeekFromParts(YearOperator::Operation<TA, TR>(input), WeekOperator::Operation<TA, TR>(input));
76026
+ int32_t yyyy, ww;
76027
+ Date::ExtractISOYearWeek(input, yyyy, ww);
76028
+ return YearWeekFromParts(yyyy, ww);
75970
76029
  }
75971
76030
 
75972
76031
  template <class T>
@@ -76109,7 +76168,8 @@ struct DatePart {
76109
76168
  DOY = 1 << 2,
76110
76169
  EPOCH = 1 << 3,
76111
76170
  TIME = 1 << 4,
76112
- ZONE = 1 << 5
76171
+ ZONE = 1 << 5,
76172
+ ISO = 1 << 6
76113
76173
  };
76114
76174
 
76115
76175
  static part_mask_t GetMask(const part_codes_t &part_codes) {
@@ -76127,12 +76187,12 @@ struct DatePart {
76127
76187
  mask |= YMD;
76128
76188
  break;
76129
76189
  case DatePartSpecifier::YEARWEEK:
76130
- mask |= YMD;
76131
- mask |= DOW;
76190
+ case DatePartSpecifier::WEEK:
76191
+ case DatePartSpecifier::ISOYEAR:
76192
+ mask |= ISO;
76132
76193
  break;
76133
76194
  case DatePartSpecifier::DOW:
76134
76195
  case DatePartSpecifier::ISODOW:
76135
- case DatePartSpecifier::WEEK:
76136
76196
  mask |= DOW;
76137
76197
  break;
76138
76198
  case DatePartSpecifier::DOY:
@@ -76199,22 +76259,29 @@ struct DatePart {
76199
76259
  }
76200
76260
 
76201
76261
  // Week calculations
76202
- int32_t isodow = 0;
76203
- int32_t ww = 0;
76204
76262
  if (mask & DOW) {
76205
- isodow = Date::ExtractISODayOfTheWeek(input);
76206
- ww = Date::ExtractISOWeekNumber(input);
76263
+ auto isodow = Date::ExtractISODayOfTheWeek(input);
76207
76264
  if ((part_data = HasPartValue(part_values, DatePartSpecifier::DOW))) {
76208
76265
  part_data[idx] = DayOfWeekOperator::DayOfWeekFromISO(isodow);
76209
76266
  }
76210
76267
  if ((part_data = HasPartValue(part_values, DatePartSpecifier::ISODOW))) {
76211
76268
  part_data[idx] = isodow;
76212
76269
  }
76270
+ }
76271
+
76272
+ // ISO calculations
76273
+ if (mask & ISO) {
76274
+ int32_t ww = 0;
76275
+ int32_t iyyy = 0;
76276
+ Date::ExtractISOYearWeek(input, iyyy, ww);
76213
76277
  if ((part_data = HasPartValue(part_values, DatePartSpecifier::WEEK))) {
76214
76278
  part_data[idx] = ww;
76215
76279
  }
76280
+ if ((part_data = HasPartValue(part_values, DatePartSpecifier::ISOYEAR))) {
76281
+ part_data[idx] = iyyy;
76282
+ }
76216
76283
  if ((part_data = HasPartValue(part_values, DatePartSpecifier::YEARWEEK))) {
76217
- part_data[idx] = YearWeekOperator::YearWeekFromParts(yyyy, ww);
76284
+ part_data[idx] = YearWeekOperator::YearWeekFromParts(iyyy, ww);
76218
76285
  }
76219
76286
  }
76220
76287
 
@@ -76382,6 +76449,33 @@ int64_t DatePart::WeekOperator::Operation(dtime_t input) {
76382
76449
  throw NotImplementedException("\"time\" units \"week\" not recognized");
76383
76450
  }
76384
76451
 
76452
+ template <>
76453
+ int64_t DatePart::ISOYearOperator::Operation(timestamp_t input) {
76454
+ return ISOYearOperator::Operation<date_t, int64_t>(Timestamp::GetDate(input));
76455
+ }
76456
+
76457
+ template <>
76458
+ int64_t DatePart::ISOYearOperator::Operation(interval_t input) {
76459
+ throw NotImplementedException("interval units \"isoyear\" not recognized");
76460
+ }
76461
+
76462
+ template <>
76463
+ int64_t DatePart::ISOYearOperator::Operation(dtime_t input) {
76464
+ throw NotImplementedException("\"time\" units \"isoyear\" not recognized");
76465
+ }
76466
+
76467
+ template <>
76468
+ int64_t DatePart::YearWeekOperator::Operation(timestamp_t input) {
76469
+ return YearWeekOperator::Operation<date_t, int64_t>(Timestamp::GetDate(input));
76470
+ }
76471
+
76472
+ template <>
76473
+ int64_t DatePart::YearWeekOperator::Operation(interval_t input) {
76474
+ const auto yyyy = YearOperator::Operation<interval_t, int64_t>(input);
76475
+ const auto ww = WeekOperator::Operation<interval_t, int64_t>(input);
76476
+ return YearWeekOperator::YearWeekFromParts<int64_t>(yyyy, ww);
76477
+ }
76478
+
76385
76479
  template <>
76386
76480
  int64_t DatePart::YearWeekOperator::Operation(dtime_t input) {
76387
76481
  throw NotImplementedException("\"time\" units \"yearweek\" not recognized");
@@ -76677,6 +76771,8 @@ static int64_t ExtractElement(DatePartSpecifier type, T element) {
76677
76771
  return DatePart::DayOfYearOperator::template Operation<T, int64_t>(element);
76678
76772
  case DatePartSpecifier::WEEK:
76679
76773
  return DatePart::WeekOperator::template Operation<T, int64_t>(element);
76774
+ case DatePartSpecifier::ISOYEAR:
76775
+ return DatePart::ISOYearOperator::template Operation<T, int64_t>(element);
76680
76776
  case DatePartSpecifier::YEARWEEK:
76681
76777
  return DatePart::YearWeekOperator::template Operation<T, int64_t>(element);
76682
76778
  case DatePartSpecifier::EPOCH:
@@ -76969,6 +77065,7 @@ void DatePartFun::RegisterFunction(BuiltinFunctions &set) {
76969
77065
  AddDatePartOperator<DatePart::ISODayOfWeekOperator>(set, "isodow");
76970
77066
  AddDatePartOperator<DatePart::DayOfYearOperator>(set, "dayofyear");
76971
77067
  AddDatePartOperator<DatePart::WeekOperator>(set, "week");
77068
+ AddDatePartOperator<DatePart::ISOYearOperator>(set, "isoyear");
76972
77069
  AddDatePartOperator<DatePart::EraOperator>(set, "era");
76973
77070
  AddDatePartOperator<DatePart::TimezoneOperator>(set, "timezone");
76974
77071
  AddDatePartOperator<DatePart::TimezoneHourOperator>(set, "timezone_hour");
@@ -77091,6 +77188,7 @@ struct DateSub {
77091
77188
  return MonthOperator::Operation<TA, TB, TR>(start_ts, end_ts) / Interval::MONTHS_PER_QUARTER;
77092
77189
  }
77093
77190
  };
77191
+
77094
77192
  struct YearOperator {
77095
77193
  template <class TA, class TB, class TR>
77096
77194
  static inline TR Operation(TA start_ts, TB end_ts) {
@@ -77337,6 +77435,7 @@ template <typename TA, typename TB, typename TR>
77337
77435
  static int64_t SubtractDateParts(DatePartSpecifier type, TA startdate, TB enddate) {
77338
77436
  switch (type) {
77339
77437
  case DatePartSpecifier::YEAR:
77438
+ case DatePartSpecifier::ISOYEAR:
77340
77439
  return DateSub::YearOperator::template Operation<TA, TB, TR>(startdate, enddate);
77341
77440
  case DatePartSpecifier::MONTH:
77342
77441
  return DateSub::MonthOperator::template Operation<TA, TB, TR>(startdate, enddate);
@@ -77383,6 +77482,7 @@ template <typename TA, typename TB, typename TR>
77383
77482
  static void DateSubBinaryExecutor(DatePartSpecifier type, Vector &left, Vector &right, Vector &result, idx_t count) {
77384
77483
  switch (type) {
77385
77484
  case DatePartSpecifier::YEAR:
77485
+ case DatePartSpecifier::ISOYEAR:
77386
77486
  BinaryExecutor::ExecuteStandard<TA, TB, TR, DateSub::YearOperator>(left, right, result, count);
77387
77487
  break;
77388
77488
  case DatePartSpecifier::MONTH:
@@ -77543,6 +77643,16 @@ struct DateTrunc {
77543
77643
  }
77544
77644
  };
77545
77645
 
77646
+ struct ISOYearOperator {
77647
+ template <class TA, class TR>
77648
+ static inline TR Operation(TA input) {
77649
+ date_t date = Date::GetMondayOfCurrentWeek(input);
77650
+ date.days -= (Date::ExtractISOWeekNumber(date) - 1) * Interval::DAYS_PER_WEEK;
77651
+
77652
+ return Timestamp::FromDatetime(date, dtime_t(0));
77653
+ }
77654
+ };
77655
+
77546
77656
  struct DayOperator {
77547
77657
  template <class TA, class TR>
77548
77658
  static inline TR Operation(TA input) {
@@ -77644,6 +77754,11 @@ timestamp_t DateTrunc::WeekOperator::Operation(date_t input) {
77644
77754
  return WeekOperator::Operation<timestamp_t, timestamp_t>(Timestamp::FromDatetime(input, dtime_t(0)));
77645
77755
  }
77646
77756
 
77757
+ template <>
77758
+ timestamp_t DateTrunc::ISOYearOperator::Operation(timestamp_t input) {
77759
+ return ISOYearOperator::Operation<date_t, timestamp_t>(Timestamp::GetDate(input));
77760
+ }
77761
+
77647
77762
  template <>
77648
77763
  timestamp_t DateTrunc::DayOperator::Operation(date_t input) {
77649
77764
  return Timestamp::FromDatetime(input, dtime_t(0));
@@ -77692,6 +77807,8 @@ static TR TruncateElement(DatePartSpecifier type, TA element) {
77692
77807
  case DatePartSpecifier::WEEK:
77693
77808
  case DatePartSpecifier::YEARWEEK:
77694
77809
  return DateTrunc::WeekOperator::Operation<TA, TR>(element);
77810
+ case DatePartSpecifier::ISOYEAR:
77811
+ return DateTrunc::ISOYearOperator::Operation<TA, TR>(element);
77695
77812
  case DatePartSpecifier::DAY:
77696
77813
  case DatePartSpecifier::DOW:
77697
77814
  case DatePartSpecifier::ISODOW:
@@ -77745,6 +77862,9 @@ static void DateTruncUnaryExecutor(DatePartSpecifier type, Vector &left, Vector
77745
77862
  case DatePartSpecifier::YEARWEEK:
77746
77863
  UnaryExecutor::Execute<TA, TR, DateTrunc::WeekOperator>(left, result, count);
77747
77864
  break;
77865
+ case DatePartSpecifier::ISOYEAR:
77866
+ UnaryExecutor::Execute<TA, TR, DateTrunc::ISOYearOperator>(left, result, count);
77867
+ break;
77748
77868
  case DatePartSpecifier::DAY:
77749
77869
  case DatePartSpecifier::DOW:
77750
77870
  case DatePartSpecifier::ISODOW:
package/src/duckdb.hpp CHANGED
@@ -11,8 +11,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
11
11
  #pragma once
12
12
  #define DUCKDB_AMALGAMATION 1
13
13
  #define DUCKDB_AMALGAMATION_EXTENDED 1
14
- #define DUCKDB_SOURCE_ID "6e1155e14"
15
- #define DUCKDB_VERSION "v0.3.2-dev1133"
14
+ #define DUCKDB_SOURCE_ID "37e046ec0"
15
+ #define DUCKDB_VERSION "v0.3.2-dev1141"
16
16
  //===----------------------------------------------------------------------===//
17
17
  // DuckDB
18
18
  //
@@ -12826,7 +12826,9 @@ public:
12826
12826
  //! contains January 4 of that year.
12827
12827
  //! In the ISO week-numbering system, it is possible for early-January dates
12828
12828
  //! to be part of the 52nd or 53rd week of the previous year.
12829
+ DUCKDB_API static void ExtractISOYearWeek(date_t date, int32_t &year, int32_t &week);
12829
12830
  DUCKDB_API static int32_t ExtractISOWeekNumber(date_t date);
12831
+ DUCKDB_API static int32_t ExtractISOYearNumber(date_t date);
12830
12832
  //! Extract the week number as Python handles it.
12831
12833
  //! Either Monday or Sunday is the first day of the week,
12832
12834
  //! and any date before the first Monday/Sunday returns week 0