duckdb 0.3.2-dev679.0 → 0.3.2-dev696.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-dev679.0",
4
+ "version": "0.3.2-dev696.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -35804,6 +35804,15 @@ dtime_t Interval::Add(dtime_t left, interval_t right, date_t &date) {
35804
35804
  return left;
35805
35805
  }
35806
35806
 
35807
+ timestamp_t Interval::Add(timestamp_t left, interval_t right) {
35808
+ date_t date;
35809
+ dtime_t time;
35810
+ Timestamp::Convert(left, date, time);
35811
+ auto new_date = Interval::Add(date, right);
35812
+ auto new_time = Interval::Add(time, right, new_date);
35813
+ return Timestamp::FromDatetime(new_date, new_time);
35814
+ }
35815
+
35807
35816
  } // namespace duckdb
35808
35817
 
35809
35818
 
@@ -83522,6 +83531,95 @@ void ListValueFun::RegisterFunction(BuiltinFunctions &set) {
83522
83531
 
83523
83532
  namespace duckdb {
83524
83533
 
83534
+ struct NumericRangeInfo {
83535
+ using TYPE = int64_t;
83536
+ using INCREMENT_TYPE = int64_t;
83537
+
83538
+ static int64_t DefaultStart() {
83539
+ return 0;
83540
+ }
83541
+ static int64_t DefaultIncrement() {
83542
+ return 1;
83543
+ }
83544
+
83545
+ static uint64_t ListLength(int64_t start_value, int64_t end_value, int64_t increment_value, bool inclusive_bound) {
83546
+ if (increment_value == 0) {
83547
+ return 0;
83548
+ }
83549
+ if (start_value > end_value && increment_value > 0) {
83550
+ return 0;
83551
+ }
83552
+ if (start_value < end_value && increment_value < 0) {
83553
+ return 0;
83554
+ }
83555
+ int64_t total_diff = AbsValue(end_value - start_value);
83556
+ int64_t increment = AbsValue(increment_value);
83557
+ int64_t total_values = total_diff / increment;
83558
+ if (total_diff % increment == 0) {
83559
+ if (inclusive_bound) {
83560
+ total_values++;
83561
+ }
83562
+ } else {
83563
+ total_values++;
83564
+ }
83565
+ return total_values;
83566
+ }
83567
+
83568
+ static void Increment(int64_t &input, int64_t increment) {
83569
+ input += increment;
83570
+ }
83571
+ };
83572
+ struct TimestampRangeInfo {
83573
+ using TYPE = timestamp_t;
83574
+ using INCREMENT_TYPE = interval_t;
83575
+
83576
+ static timestamp_t DefaultStart() {
83577
+ throw InternalException("Default start not implemented for timestamp range");
83578
+ }
83579
+ static interval_t DefaultIncrement() {
83580
+ throw InternalException("Default increment not implemented for timestamp range");
83581
+ }
83582
+ static uint64_t ListLength(timestamp_t start_value, timestamp_t end_value, interval_t increment_value,
83583
+ bool inclusive_bound) {
83584
+ bool is_positive = increment_value.months > 0 || increment_value.days > 0 || increment_value.micros > 0;
83585
+ bool is_negative = increment_value.months < 0 || increment_value.days < 0 || increment_value.micros < 0;
83586
+ if (!is_negative && !is_positive) {
83587
+ // interval is 0: no result
83588
+ return 0;
83589
+ }
83590
+ if (is_negative && is_positive) {
83591
+ // we don't allow a mix of
83592
+ throw InvalidInputException("Interval with mix of negative/positive entries not supported");
83593
+ }
83594
+ if (start_value > end_value && is_positive) {
83595
+ return 0;
83596
+ }
83597
+ if (start_value < end_value && is_negative) {
83598
+ return 0;
83599
+ }
83600
+ int64_t total_values = 0;
83601
+ if (is_negative) {
83602
+ // negative interval, start_value is going down
83603
+ while (inclusive_bound ? start_value >= end_value : start_value > end_value) {
83604
+ start_value = Interval::Add(start_value, increment_value);
83605
+ total_values++;
83606
+ }
83607
+ } else {
83608
+ // positive interval, start_value is going up
83609
+ while (inclusive_bound ? start_value <= end_value : start_value < end_value) {
83610
+ start_value = Interval::Add(start_value, increment_value);
83611
+ total_values++;
83612
+ }
83613
+ }
83614
+ return total_values;
83615
+ }
83616
+
83617
+ static void Increment(timestamp_t &input, interval_t increment) {
83618
+ input = Interval::Add(input, increment);
83619
+ }
83620
+ };
83621
+
83622
+ template <class OP, bool INCLUSIVE_BOUND>
83525
83623
  class RangeInfoStruct {
83526
83624
  public:
83527
83625
  explicit RangeInfoStruct(DataChunk &args_p) : args(args_p) {
@@ -83553,64 +83651,46 @@ public:
83553
83651
  return true;
83554
83652
  }
83555
83653
 
83556
- int64_t StartListValue(idx_t row_idx) {
83654
+ typename OP::TYPE StartListValue(idx_t row_idx) {
83557
83655
  if (args.ColumnCount() == 1) {
83558
- return 0;
83656
+ return OP::DefaultStart();
83559
83657
  } else {
83560
- auto data = (int64_t *)vdata[0].data;
83658
+ auto data = (typename OP::TYPE *)vdata[0].data;
83561
83659
  auto idx = vdata[0].sel->get_index(row_idx);
83562
83660
  return data[idx];
83563
83661
  }
83564
83662
  }
83565
83663
 
83566
- int64_t EndListValue(idx_t row_idx) {
83664
+ typename OP::TYPE EndListValue(idx_t row_idx) {
83567
83665
  idx_t vdata_idx = args.ColumnCount() == 1 ? 0 : 1;
83568
- auto data = (int64_t *)vdata[vdata_idx].data;
83666
+ auto data = (typename OP::TYPE *)vdata[vdata_idx].data;
83569
83667
  auto idx = vdata[vdata_idx].sel->get_index(row_idx);
83570
83668
  return data[idx];
83571
83669
  }
83572
83670
 
83573
- int64_t ListIncrementValue(idx_t row_idx) {
83671
+ typename OP::INCREMENT_TYPE ListIncrementValue(idx_t row_idx) {
83574
83672
  if (args.ColumnCount() < 3) {
83575
- return 1;
83673
+ return OP::DefaultIncrement();
83576
83674
  } else {
83577
- auto data = (int64_t *)vdata[2].data;
83675
+ auto data = (typename OP::INCREMENT_TYPE *)vdata[2].data;
83578
83676
  auto idx = vdata[2].sel->get_index(row_idx);
83579
83677
  return data[idx];
83580
83678
  }
83581
83679
  }
83582
83680
 
83583
- void GetListValues(idx_t row_idx, int64_t &start_value, int64_t &end_value, int64_t &increment_value) {
83681
+ void GetListValues(idx_t row_idx, typename OP::TYPE &start_value, typename OP::TYPE &end_value,
83682
+ typename OP::INCREMENT_TYPE &increment_value) {
83584
83683
  start_value = StartListValue(row_idx);
83585
83684
  end_value = EndListValue(row_idx);
83586
83685
  increment_value = ListIncrementValue(row_idx);
83587
83686
  }
83588
83687
 
83589
- uint64_t ListLength(idx_t row_idx, bool inclusive_bound) {
83590
- int64_t start_value;
83591
- int64_t end_value;
83592
- int64_t increment_value;
83688
+ uint64_t ListLength(idx_t row_idx) {
83689
+ typename OP::TYPE start_value;
83690
+ typename OP::TYPE end_value;
83691
+ typename OP::INCREMENT_TYPE increment_value;
83593
83692
  GetListValues(row_idx, start_value, end_value, increment_value);
83594
- if (increment_value == 0) {
83595
- return 0;
83596
- }
83597
- if (start_value > end_value && increment_value > 0) {
83598
- return 0;
83599
- }
83600
- if (start_value < end_value && increment_value < 0) {
83601
- return 0;
83602
- }
83603
- int64_t total_diff = AbsValue(end_value - start_value);
83604
- int64_t increment = AbsValue(increment_value);
83605
- int64_t total_values = total_diff / increment;
83606
- if (total_diff % increment == 0) {
83607
- if (inclusive_bound) {
83608
- total_values++;
83609
- }
83610
- } else {
83611
- total_values++;
83612
- }
83613
- return total_values;
83693
+ return OP::ListLength(start_value, end_value, increment_value, INCLUSIVE_BOUND);
83614
83694
  }
83615
83695
 
83616
83696
  private:
@@ -83618,11 +83698,11 @@ private:
83618
83698
  VectorData vdata[3];
83619
83699
  };
83620
83700
 
83621
- template <bool INCLUSIVE_BOUND>
83701
+ template <class OP, bool INCLUSIVE_BOUND>
83622
83702
  static void ListRangeFunction(DataChunk &args, ExpressionState &state, Vector &result) {
83623
83703
  D_ASSERT(result.GetType().id() == LogicalTypeId::LIST);
83624
83704
 
83625
- RangeInfoStruct info(args);
83705
+ RangeInfoStruct<OP, INCLUSIVE_BOUND> info(args);
83626
83706
  idx_t args_size = 1;
83627
83707
  auto result_type = VectorType::CONSTANT_VECTOR;
83628
83708
  for (idx_t i = 0; i < args.ColumnCount(); i++) {
@@ -83642,23 +83722,23 @@ static void ListRangeFunction(DataChunk &args, ExpressionState &state, Vector &r
83642
83722
  list_data[i].length = 0;
83643
83723
  } else {
83644
83724
  list_data[i].offset = total_size;
83645
- list_data[i].length = info.ListLength(i, INCLUSIVE_BOUND);
83725
+ list_data[i].length = info.ListLength(i);
83646
83726
  total_size += list_data[i].length;
83647
83727
  }
83648
83728
  }
83649
83729
 
83650
83730
  // now construct the child vector of the list
83651
83731
  ListVector::Reserve(result, total_size);
83652
- auto range_data = FlatVector::GetData<int64_t>(ListVector::GetEntry(result));
83732
+ auto range_data = FlatVector::GetData<typename OP::TYPE>(ListVector::GetEntry(result));
83653
83733
  idx_t total_idx = 0;
83654
83734
  for (idx_t i = 0; i < args_size; i++) {
83655
- int64_t start_value = info.StartListValue(i);
83656
- int64_t increment = info.ListIncrementValue(i);
83735
+ typename OP::TYPE start_value = info.StartListValue(i);
83736
+ typename OP::INCREMENT_TYPE increment = info.ListIncrementValue(i);
83657
83737
 
83658
- int64_t range_value = start_value;
83738
+ typename OP::TYPE range_value = start_value;
83659
83739
  for (idx_t range_idx = 0; range_idx < list_data[i].length; range_idx++) {
83660
83740
  range_data[total_idx++] = range_value;
83661
- range_value += increment;
83741
+ OP::Increment(range_value, increment);
83662
83742
  }
83663
83743
  }
83664
83744
 
@@ -83671,21 +83751,31 @@ static void ListRangeFunction(DataChunk &args, ExpressionState &state, Vector &r
83671
83751
  void ListRangeFun::RegisterFunction(BuiltinFunctions &set) {
83672
83752
  // the arguments and return types are actually set in the binder function
83673
83753
  ScalarFunctionSet range_set("range");
83674
- range_set.AddFunction(
83675
- ScalarFunction({LogicalType::BIGINT}, LogicalType::LIST(LogicalType::BIGINT), ListRangeFunction<false>));
83754
+ range_set.AddFunction(ScalarFunction({LogicalType::BIGINT}, LogicalType::LIST(LogicalType::BIGINT),
83755
+ ListRangeFunction<NumericRangeInfo, false>));
83676
83756
  range_set.AddFunction(ScalarFunction({LogicalType::BIGINT, LogicalType::BIGINT},
83677
- LogicalType::LIST(LogicalType::BIGINT), ListRangeFunction<false>));
83757
+ LogicalType::LIST(LogicalType::BIGINT),
83758
+ ListRangeFunction<NumericRangeInfo, false>));
83678
83759
  range_set.AddFunction(ScalarFunction({LogicalType::BIGINT, LogicalType::BIGINT, LogicalType::BIGINT},
83679
- LogicalType::LIST(LogicalType::BIGINT), ListRangeFunction<false>));
83760
+ LogicalType::LIST(LogicalType::BIGINT),
83761
+ ListRangeFunction<NumericRangeInfo, false>));
83762
+ range_set.AddFunction(ScalarFunction({LogicalType::TIMESTAMP, LogicalType::TIMESTAMP, LogicalType::INTERVAL},
83763
+ LogicalType::LIST(LogicalType::TIMESTAMP),
83764
+ ListRangeFunction<TimestampRangeInfo, false>));
83680
83765
  set.AddFunction(range_set);
83681
83766
 
83682
83767
  ScalarFunctionSet generate_series("generate_series");
83683
- generate_series.AddFunction(
83684
- ScalarFunction({LogicalType::BIGINT}, LogicalType::LIST(LogicalType::BIGINT), ListRangeFunction<true>));
83768
+ generate_series.AddFunction(ScalarFunction({LogicalType::BIGINT}, LogicalType::LIST(LogicalType::BIGINT),
83769
+ ListRangeFunction<NumericRangeInfo, true>));
83685
83770
  generate_series.AddFunction(ScalarFunction({LogicalType::BIGINT, LogicalType::BIGINT},
83686
- LogicalType::LIST(LogicalType::BIGINT), ListRangeFunction<true>));
83771
+ LogicalType::LIST(LogicalType::BIGINT),
83772
+ ListRangeFunction<NumericRangeInfo, true>));
83687
83773
  generate_series.AddFunction(ScalarFunction({LogicalType::BIGINT, LogicalType::BIGINT, LogicalType::BIGINT},
83688
- LogicalType::LIST(LogicalType::BIGINT), ListRangeFunction<true>));
83774
+ LogicalType::LIST(LogicalType::BIGINT),
83775
+ ListRangeFunction<NumericRangeInfo, true>));
83776
+ generate_series.AddFunction(ScalarFunction({LogicalType::TIMESTAMP, LogicalType::TIMESTAMP, LogicalType::INTERVAL},
83777
+ LogicalType::LIST(LogicalType::TIMESTAMP),
83778
+ ListRangeFunction<TimestampRangeInfo, true>));
83689
83779
  set.AddFunction(generate_series);
83690
83780
  }
83691
83781
 
@@ -85247,12 +85337,7 @@ date_t AddOperator::Operation(interval_t left, date_t right) {
85247
85337
 
85248
85338
  template <>
85249
85339
  timestamp_t AddOperator::Operation(timestamp_t left, interval_t right) {
85250
- date_t date;
85251
- dtime_t time;
85252
- Timestamp::Convert(left, date, time);
85253
- auto new_date = Interval::Add(date, right);
85254
- auto new_time = Interval::Add(time, right, new_date);
85255
- return Timestamp::FromDatetime(new_date, new_time);
85340
+ return Interval::Add(left, right);
85256
85341
  }
85257
85342
 
85258
85343
  template <>
package/src/duckdb.hpp CHANGED
@@ -10,8 +10,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
10
10
 
11
11
  #pragma once
12
12
  #define DUCKDB_AMALGAMATION 1
13
- #define DUCKDB_SOURCE_ID "000fbffa3"
14
- #define DUCKDB_VERSION "0.3.2-dev679"
13
+ #define DUCKDB_SOURCE_ID "a679c6b8b"
14
+ #define DUCKDB_VERSION "0.3.2-dev696"
15
15
  //===----------------------------------------------------------------------===//
16
16
  // DuckDB
17
17
  //
@@ -6076,6 +6076,8 @@ public:
6076
6076
 
6077
6077
  //! Add an interval to a date
6078
6078
  static date_t Add(date_t left, interval_t right);
6079
+ //! Add an interval to a timestamp
6080
+ static timestamp_t Add(timestamp_t left, interval_t right);
6079
6081
  //! Add an interval to a time. In case the time overflows or underflows, modify the date by the overflow.
6080
6082
  //! For example if we go from 23:00 to 02:00, we add a day to the date
6081
6083
  static dtime_t Add(dtime_t left, interval_t right, date_t &date);