duckdb 0.3.2-dev668.0 → 0.3.2-dev685.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 +1 -1
- package/src/duckdb.cpp +327 -61
- package/src/duckdb.hpp +7 -4
package/package.json
CHANGED
package/src/duckdb.cpp
CHANGED
|
@@ -8540,6 +8540,8 @@ string PhysicalOperatorToString(PhysicalOperatorType type) {
|
|
|
8540
8540
|
return "TOP_N";
|
|
8541
8541
|
case PhysicalOperatorType::WINDOW:
|
|
8542
8542
|
return "WINDOW";
|
|
8543
|
+
case PhysicalOperatorType::STREAMING_WINDOW:
|
|
8544
|
+
return "STREAMING_WINDOW";
|
|
8543
8545
|
case PhysicalOperatorType::UNNEST:
|
|
8544
8546
|
return "UNNEST";
|
|
8545
8547
|
case PhysicalOperatorType::SIMPLE_AGGREGATE:
|
|
@@ -35802,6 +35804,15 @@ dtime_t Interval::Add(dtime_t left, interval_t right, date_t &date) {
|
|
|
35802
35804
|
return left;
|
|
35803
35805
|
}
|
|
35804
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
|
+
|
|
35805
35816
|
} // namespace duckdb
|
|
35806
35817
|
|
|
35807
35818
|
|
|
@@ -52691,6 +52702,149 @@ string PhysicalSimpleAggregate::ParamsToString() const {
|
|
|
52691
52702
|
|
|
52692
52703
|
|
|
52693
52704
|
|
|
52705
|
+
namespace duckdb {
|
|
52706
|
+
|
|
52707
|
+
//! PhysicalStreamingWindow implements streaming window functions (i.e. with an empty OVER clause)
|
|
52708
|
+
class PhysicalStreamingWindow : public PhysicalOperator {
|
|
52709
|
+
public:
|
|
52710
|
+
PhysicalStreamingWindow(vector<LogicalType> types, vector<unique_ptr<Expression>> select_list,
|
|
52711
|
+
idx_t estimated_cardinality,
|
|
52712
|
+
PhysicalOperatorType type = PhysicalOperatorType::STREAMING_WINDOW);
|
|
52713
|
+
|
|
52714
|
+
//! The projection list of the WINDOW statement
|
|
52715
|
+
vector<unique_ptr<Expression>> select_list;
|
|
52716
|
+
|
|
52717
|
+
public:
|
|
52718
|
+
unique_ptr<OperatorState> GetOperatorState(ClientContext &context) const override;
|
|
52719
|
+
|
|
52720
|
+
OperatorResultType Execute(ExecutionContext &context, DataChunk &input, DataChunk &chunk,
|
|
52721
|
+
OperatorState &state) const override;
|
|
52722
|
+
|
|
52723
|
+
string ParamsToString() const override;
|
|
52724
|
+
};
|
|
52725
|
+
|
|
52726
|
+
} // namespace duckdb
|
|
52727
|
+
|
|
52728
|
+
|
|
52729
|
+
|
|
52730
|
+
|
|
52731
|
+
|
|
52732
|
+
|
|
52733
|
+
|
|
52734
|
+
namespace duckdb {
|
|
52735
|
+
|
|
52736
|
+
PhysicalStreamingWindow::PhysicalStreamingWindow(vector<LogicalType> types, vector<unique_ptr<Expression>> select_list,
|
|
52737
|
+
idx_t estimated_cardinality, PhysicalOperatorType type)
|
|
52738
|
+
: PhysicalOperator(type, move(types), estimated_cardinality), select_list(move(select_list)) {
|
|
52739
|
+
}
|
|
52740
|
+
|
|
52741
|
+
class StreamingWindowState : public OperatorState {
|
|
52742
|
+
public:
|
|
52743
|
+
StreamingWindowState() : initialized(false), row_number(1) {
|
|
52744
|
+
}
|
|
52745
|
+
|
|
52746
|
+
void Initialize(DataChunk &input, const vector<unique_ptr<Expression>> &expressions) {
|
|
52747
|
+
for (idx_t expr_idx = 0; expr_idx < expressions.size(); expr_idx++) {
|
|
52748
|
+
auto &expr = *expressions[expr_idx];
|
|
52749
|
+
switch (expr.GetExpressionType()) {
|
|
52750
|
+
case ExpressionType::WINDOW_FIRST_VALUE: {
|
|
52751
|
+
auto &wexpr = (BoundWindowExpression &)expr;
|
|
52752
|
+
auto &ref = (BoundReferenceExpression &)*wexpr.children[0];
|
|
52753
|
+
const_vectors.push_back(make_unique<Vector>(input.data[ref.index].GetValue(0)));
|
|
52754
|
+
break;
|
|
52755
|
+
}
|
|
52756
|
+
case ExpressionType::WINDOW_PERCENT_RANK: {
|
|
52757
|
+
const_vectors.push_back(make_unique<Vector>(Value((double)0)));
|
|
52758
|
+
break;
|
|
52759
|
+
}
|
|
52760
|
+
case ExpressionType::WINDOW_RANK:
|
|
52761
|
+
case ExpressionType::WINDOW_RANK_DENSE: {
|
|
52762
|
+
const_vectors.push_back(make_unique<Vector>(Value((int64_t)1)));
|
|
52763
|
+
break;
|
|
52764
|
+
}
|
|
52765
|
+
default:
|
|
52766
|
+
const_vectors.push_back(nullptr);
|
|
52767
|
+
}
|
|
52768
|
+
}
|
|
52769
|
+
initialized = true;
|
|
52770
|
+
}
|
|
52771
|
+
|
|
52772
|
+
public:
|
|
52773
|
+
bool initialized;
|
|
52774
|
+
int64_t row_number;
|
|
52775
|
+
vector<unique_ptr<Vector>> const_vectors;
|
|
52776
|
+
};
|
|
52777
|
+
|
|
52778
|
+
unique_ptr<OperatorState> PhysicalStreamingWindow::GetOperatorState(ClientContext &context) const {
|
|
52779
|
+
return make_unique<StreamingWindowState>();
|
|
52780
|
+
}
|
|
52781
|
+
|
|
52782
|
+
OperatorResultType PhysicalStreamingWindow::Execute(ExecutionContext &context, DataChunk &input, DataChunk &chunk,
|
|
52783
|
+
OperatorState &state_p) const {
|
|
52784
|
+
auto &state = (StreamingWindowState &)state_p;
|
|
52785
|
+
if (!state.initialized) {
|
|
52786
|
+
state.Initialize(input, select_list);
|
|
52787
|
+
}
|
|
52788
|
+
// Put payload columns in place
|
|
52789
|
+
for (idx_t col_idx = 0; col_idx < input.data.size(); col_idx++) {
|
|
52790
|
+
chunk.data[col_idx].Reference(input.data[col_idx]);
|
|
52791
|
+
}
|
|
52792
|
+
// Compute window function
|
|
52793
|
+
const idx_t count = input.size();
|
|
52794
|
+
for (idx_t expr_idx = 0; expr_idx < select_list.size(); expr_idx++) {
|
|
52795
|
+
idx_t col_idx = input.data.size() + expr_idx;
|
|
52796
|
+
auto &expr = *select_list[expr_idx];
|
|
52797
|
+
switch (expr.GetExpressionType()) {
|
|
52798
|
+
case ExpressionType::WINDOW_FIRST_VALUE:
|
|
52799
|
+
case ExpressionType::WINDOW_PERCENT_RANK:
|
|
52800
|
+
case ExpressionType::WINDOW_RANK:
|
|
52801
|
+
case ExpressionType::WINDOW_RANK_DENSE: {
|
|
52802
|
+
// Reference constant vector
|
|
52803
|
+
chunk.data[col_idx].Reference(*state.const_vectors[expr_idx]);
|
|
52804
|
+
break;
|
|
52805
|
+
}
|
|
52806
|
+
case ExpressionType::WINDOW_ROW_NUMBER: {
|
|
52807
|
+
// Set row numbers
|
|
52808
|
+
auto rdata = FlatVector::GetData<int64_t>(chunk.data[col_idx]);
|
|
52809
|
+
for (idx_t i = 0; i < count; i++) {
|
|
52810
|
+
rdata[i] = state.row_number + i;
|
|
52811
|
+
}
|
|
52812
|
+
break;
|
|
52813
|
+
}
|
|
52814
|
+
default:
|
|
52815
|
+
throw NotImplementedException("%s for StreamingWindow", ExpressionTypeToString(expr.GetExpressionType()));
|
|
52816
|
+
}
|
|
52817
|
+
}
|
|
52818
|
+
state.row_number += count;
|
|
52819
|
+
chunk.SetCardinality(count);
|
|
52820
|
+
return OperatorResultType::NEED_MORE_INPUT;
|
|
52821
|
+
}
|
|
52822
|
+
|
|
52823
|
+
string PhysicalStreamingWindow::ParamsToString() const {
|
|
52824
|
+
string result;
|
|
52825
|
+
for (idx_t i = 0; i < select_list.size(); i++) {
|
|
52826
|
+
if (i > 0) {
|
|
52827
|
+
result += "\n";
|
|
52828
|
+
}
|
|
52829
|
+
result += select_list[i]->GetName();
|
|
52830
|
+
}
|
|
52831
|
+
return result;
|
|
52832
|
+
}
|
|
52833
|
+
|
|
52834
|
+
} // namespace duckdb
|
|
52835
|
+
//===----------------------------------------------------------------------===//
|
|
52836
|
+
// DuckDB
|
|
52837
|
+
//
|
|
52838
|
+
// duckdb/execution/operator/aggregate/physical_window.hpp
|
|
52839
|
+
//
|
|
52840
|
+
//
|
|
52841
|
+
//===----------------------------------------------------------------------===//
|
|
52842
|
+
|
|
52843
|
+
|
|
52844
|
+
|
|
52845
|
+
|
|
52846
|
+
|
|
52847
|
+
|
|
52694
52848
|
|
|
52695
52849
|
namespace duckdb {
|
|
52696
52850
|
|
|
@@ -68409,6 +68563,9 @@ unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalUpdate &op
|
|
|
68409
68563
|
|
|
68410
68564
|
|
|
68411
68565
|
|
|
68566
|
+
|
|
68567
|
+
|
|
68568
|
+
|
|
68412
68569
|
//===----------------------------------------------------------------------===//
|
|
68413
68570
|
// DuckDB
|
|
68414
68571
|
//
|
|
@@ -68442,12 +68599,28 @@ protected:
|
|
|
68442
68599
|
} // namespace duckdb
|
|
68443
68600
|
|
|
68444
68601
|
|
|
68445
|
-
|
|
68446
|
-
|
|
68447
68602
|
#include <numeric>
|
|
68448
68603
|
|
|
68449
68604
|
namespace duckdb {
|
|
68450
68605
|
|
|
68606
|
+
static bool IsStreamingWindow(unique_ptr<Expression> &expr) {
|
|
68607
|
+
auto wexpr = reinterpret_cast<BoundWindowExpression *>(expr.get());
|
|
68608
|
+
if (!wexpr->partitions.empty() || !wexpr->orders.empty() || wexpr->ignore_nulls) {
|
|
68609
|
+
return false;
|
|
68610
|
+
}
|
|
68611
|
+
switch (wexpr->type) {
|
|
68612
|
+
// TODO: add more expression types here?
|
|
68613
|
+
case ExpressionType::WINDOW_FIRST_VALUE:
|
|
68614
|
+
case ExpressionType::WINDOW_PERCENT_RANK:
|
|
68615
|
+
case ExpressionType::WINDOW_RANK:
|
|
68616
|
+
case ExpressionType::WINDOW_RANK_DENSE:
|
|
68617
|
+
case ExpressionType::WINDOW_ROW_NUMBER:
|
|
68618
|
+
return true;
|
|
68619
|
+
default:
|
|
68620
|
+
return false;
|
|
68621
|
+
}
|
|
68622
|
+
}
|
|
68623
|
+
|
|
68451
68624
|
unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalWindow &op) {
|
|
68452
68625
|
D_ASSERT(op.children.size() == 1);
|
|
68453
68626
|
|
|
@@ -68463,11 +68636,23 @@ unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalWindow &op
|
|
|
68463
68636
|
const auto output_idx = types.size() - op.expressions.size();
|
|
68464
68637
|
types.resize(output_idx);
|
|
68465
68638
|
|
|
68639
|
+
// Identify streaming windows
|
|
68640
|
+
vector<idx_t> blocking_windows;
|
|
68641
|
+
vector<idx_t> streaming_windows;
|
|
68642
|
+
for (idx_t expr_idx = 0; expr_idx < op.expressions.size(); expr_idx++) {
|
|
68643
|
+
if (IsStreamingWindow(op.expressions[expr_idx])) {
|
|
68644
|
+
streaming_windows.push_back(expr_idx);
|
|
68645
|
+
} else {
|
|
68646
|
+
blocking_windows.push_back(expr_idx);
|
|
68647
|
+
}
|
|
68648
|
+
}
|
|
68649
|
+
|
|
68466
68650
|
// Process the window functions by sharing the partition/order definitions
|
|
68467
68651
|
vector<idx_t> evaluation_order;
|
|
68468
|
-
|
|
68469
|
-
|
|
68470
|
-
|
|
68652
|
+
while (!blocking_windows.empty() || !streaming_windows.empty()) {
|
|
68653
|
+
const bool process_streaming = blocking_windows.empty();
|
|
68654
|
+
auto &remaining = process_streaming ? streaming_windows : blocking_windows;
|
|
68655
|
+
|
|
68471
68656
|
// Find all functions that share the partitioning of the first remaining expression
|
|
68472
68657
|
const auto over_idx = remaining[0];
|
|
68473
68658
|
auto over_expr = reinterpret_cast<BoundWindowExpression *>(op.expressions[over_idx].get());
|
|
@@ -68493,7 +68678,12 @@ unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalWindow &op
|
|
|
68493
68678
|
}
|
|
68494
68679
|
|
|
68495
68680
|
// Chain the new window operator on top of the plan
|
|
68496
|
-
|
|
68681
|
+
unique_ptr<PhysicalOperator> window;
|
|
68682
|
+
if (process_streaming) {
|
|
68683
|
+
window = make_unique<PhysicalStreamingWindow>(types, move(select_list), op.estimated_cardinality);
|
|
68684
|
+
} else {
|
|
68685
|
+
window = make_unique<PhysicalWindow>(types, move(select_list), op.estimated_cardinality);
|
|
68686
|
+
}
|
|
68497
68687
|
window->children.push_back(move(plan));
|
|
68498
68688
|
plan = move(window);
|
|
68499
68689
|
|
|
@@ -83341,6 +83531,95 @@ void ListValueFun::RegisterFunction(BuiltinFunctions &set) {
|
|
|
83341
83531
|
|
|
83342
83532
|
namespace duckdb {
|
|
83343
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>
|
|
83344
83623
|
class RangeInfoStruct {
|
|
83345
83624
|
public:
|
|
83346
83625
|
explicit RangeInfoStruct(DataChunk &args_p) : args(args_p) {
|
|
@@ -83372,64 +83651,46 @@ public:
|
|
|
83372
83651
|
return true;
|
|
83373
83652
|
}
|
|
83374
83653
|
|
|
83375
|
-
|
|
83654
|
+
typename OP::TYPE StartListValue(idx_t row_idx) {
|
|
83376
83655
|
if (args.ColumnCount() == 1) {
|
|
83377
|
-
return
|
|
83656
|
+
return OP::DefaultStart();
|
|
83378
83657
|
} else {
|
|
83379
|
-
auto data = (
|
|
83658
|
+
auto data = (typename OP::TYPE *)vdata[0].data;
|
|
83380
83659
|
auto idx = vdata[0].sel->get_index(row_idx);
|
|
83381
83660
|
return data[idx];
|
|
83382
83661
|
}
|
|
83383
83662
|
}
|
|
83384
83663
|
|
|
83385
|
-
|
|
83664
|
+
typename OP::TYPE EndListValue(idx_t row_idx) {
|
|
83386
83665
|
idx_t vdata_idx = args.ColumnCount() == 1 ? 0 : 1;
|
|
83387
|
-
auto data = (
|
|
83666
|
+
auto data = (typename OP::TYPE *)vdata[vdata_idx].data;
|
|
83388
83667
|
auto idx = vdata[vdata_idx].sel->get_index(row_idx);
|
|
83389
83668
|
return data[idx];
|
|
83390
83669
|
}
|
|
83391
83670
|
|
|
83392
|
-
|
|
83671
|
+
typename OP::INCREMENT_TYPE ListIncrementValue(idx_t row_idx) {
|
|
83393
83672
|
if (args.ColumnCount() < 3) {
|
|
83394
|
-
return
|
|
83673
|
+
return OP::DefaultIncrement();
|
|
83395
83674
|
} else {
|
|
83396
|
-
auto data = (
|
|
83675
|
+
auto data = (typename OP::INCREMENT_TYPE *)vdata[2].data;
|
|
83397
83676
|
auto idx = vdata[2].sel->get_index(row_idx);
|
|
83398
83677
|
return data[idx];
|
|
83399
83678
|
}
|
|
83400
83679
|
}
|
|
83401
83680
|
|
|
83402
|
-
void GetListValues(idx_t row_idx,
|
|
83681
|
+
void GetListValues(idx_t row_idx, typename OP::TYPE &start_value, typename OP::TYPE &end_value,
|
|
83682
|
+
typename OP::INCREMENT_TYPE &increment_value) {
|
|
83403
83683
|
start_value = StartListValue(row_idx);
|
|
83404
83684
|
end_value = EndListValue(row_idx);
|
|
83405
83685
|
increment_value = ListIncrementValue(row_idx);
|
|
83406
83686
|
}
|
|
83407
83687
|
|
|
83408
|
-
uint64_t ListLength(idx_t row_idx
|
|
83409
|
-
|
|
83410
|
-
|
|
83411
|
-
|
|
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;
|
|
83412
83692
|
GetListValues(row_idx, start_value, end_value, increment_value);
|
|
83413
|
-
|
|
83414
|
-
return 0;
|
|
83415
|
-
}
|
|
83416
|
-
if (start_value > end_value && increment_value > 0) {
|
|
83417
|
-
return 0;
|
|
83418
|
-
}
|
|
83419
|
-
if (start_value < end_value && increment_value < 0) {
|
|
83420
|
-
return 0;
|
|
83421
|
-
}
|
|
83422
|
-
int64_t total_diff = AbsValue(end_value - start_value);
|
|
83423
|
-
int64_t increment = AbsValue(increment_value);
|
|
83424
|
-
int64_t total_values = total_diff / increment;
|
|
83425
|
-
if (total_diff % increment == 0) {
|
|
83426
|
-
if (inclusive_bound) {
|
|
83427
|
-
total_values++;
|
|
83428
|
-
}
|
|
83429
|
-
} else {
|
|
83430
|
-
total_values++;
|
|
83431
|
-
}
|
|
83432
|
-
return total_values;
|
|
83693
|
+
return OP::ListLength(start_value, end_value, increment_value, INCLUSIVE_BOUND);
|
|
83433
83694
|
}
|
|
83434
83695
|
|
|
83435
83696
|
private:
|
|
@@ -83437,11 +83698,11 @@ private:
|
|
|
83437
83698
|
VectorData vdata[3];
|
|
83438
83699
|
};
|
|
83439
83700
|
|
|
83440
|
-
template <bool INCLUSIVE_BOUND>
|
|
83701
|
+
template <class OP, bool INCLUSIVE_BOUND>
|
|
83441
83702
|
static void ListRangeFunction(DataChunk &args, ExpressionState &state, Vector &result) {
|
|
83442
83703
|
D_ASSERT(result.GetType().id() == LogicalTypeId::LIST);
|
|
83443
83704
|
|
|
83444
|
-
RangeInfoStruct info(args);
|
|
83705
|
+
RangeInfoStruct<OP, INCLUSIVE_BOUND> info(args);
|
|
83445
83706
|
idx_t args_size = 1;
|
|
83446
83707
|
auto result_type = VectorType::CONSTANT_VECTOR;
|
|
83447
83708
|
for (idx_t i = 0; i < args.ColumnCount(); i++) {
|
|
@@ -83461,23 +83722,23 @@ static void ListRangeFunction(DataChunk &args, ExpressionState &state, Vector &r
|
|
|
83461
83722
|
list_data[i].length = 0;
|
|
83462
83723
|
} else {
|
|
83463
83724
|
list_data[i].offset = total_size;
|
|
83464
|
-
list_data[i].length = info.ListLength(i
|
|
83725
|
+
list_data[i].length = info.ListLength(i);
|
|
83465
83726
|
total_size += list_data[i].length;
|
|
83466
83727
|
}
|
|
83467
83728
|
}
|
|
83468
83729
|
|
|
83469
83730
|
// now construct the child vector of the list
|
|
83470
83731
|
ListVector::Reserve(result, total_size);
|
|
83471
|
-
auto range_data = FlatVector::GetData<
|
|
83732
|
+
auto range_data = FlatVector::GetData<typename OP::TYPE>(ListVector::GetEntry(result));
|
|
83472
83733
|
idx_t total_idx = 0;
|
|
83473
83734
|
for (idx_t i = 0; i < args_size; i++) {
|
|
83474
|
-
|
|
83475
|
-
|
|
83735
|
+
typename OP::TYPE start_value = info.StartListValue(i);
|
|
83736
|
+
typename OP::INCREMENT_TYPE increment = info.ListIncrementValue(i);
|
|
83476
83737
|
|
|
83477
|
-
|
|
83738
|
+
typename OP::TYPE range_value = start_value;
|
|
83478
83739
|
for (idx_t range_idx = 0; range_idx < list_data[i].length; range_idx++) {
|
|
83479
83740
|
range_data[total_idx++] = range_value;
|
|
83480
|
-
range_value
|
|
83741
|
+
OP::Increment(range_value, increment);
|
|
83481
83742
|
}
|
|
83482
83743
|
}
|
|
83483
83744
|
|
|
@@ -83490,21 +83751,31 @@ static void ListRangeFunction(DataChunk &args, ExpressionState &state, Vector &r
|
|
|
83490
83751
|
void ListRangeFun::RegisterFunction(BuiltinFunctions &set) {
|
|
83491
83752
|
// the arguments and return types are actually set in the binder function
|
|
83492
83753
|
ScalarFunctionSet range_set("range");
|
|
83493
|
-
range_set.AddFunction(
|
|
83494
|
-
|
|
83754
|
+
range_set.AddFunction(ScalarFunction({LogicalType::BIGINT}, LogicalType::LIST(LogicalType::BIGINT),
|
|
83755
|
+
ListRangeFunction<NumericRangeInfo, false>));
|
|
83495
83756
|
range_set.AddFunction(ScalarFunction({LogicalType::BIGINT, LogicalType::BIGINT},
|
|
83496
|
-
LogicalType::LIST(LogicalType::BIGINT),
|
|
83757
|
+
LogicalType::LIST(LogicalType::BIGINT),
|
|
83758
|
+
ListRangeFunction<NumericRangeInfo, false>));
|
|
83497
83759
|
range_set.AddFunction(ScalarFunction({LogicalType::BIGINT, LogicalType::BIGINT, LogicalType::BIGINT},
|
|
83498
|
-
LogicalType::LIST(LogicalType::BIGINT),
|
|
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>));
|
|
83499
83765
|
set.AddFunction(range_set);
|
|
83500
83766
|
|
|
83501
83767
|
ScalarFunctionSet generate_series("generate_series");
|
|
83502
|
-
generate_series.AddFunction(
|
|
83503
|
-
|
|
83768
|
+
generate_series.AddFunction(ScalarFunction({LogicalType::BIGINT}, LogicalType::LIST(LogicalType::BIGINT),
|
|
83769
|
+
ListRangeFunction<NumericRangeInfo, true>));
|
|
83504
83770
|
generate_series.AddFunction(ScalarFunction({LogicalType::BIGINT, LogicalType::BIGINT},
|
|
83505
|
-
LogicalType::LIST(LogicalType::BIGINT),
|
|
83771
|
+
LogicalType::LIST(LogicalType::BIGINT),
|
|
83772
|
+
ListRangeFunction<NumericRangeInfo, true>));
|
|
83506
83773
|
generate_series.AddFunction(ScalarFunction({LogicalType::BIGINT, LogicalType::BIGINT, LogicalType::BIGINT},
|
|
83507
|
-
LogicalType::LIST(LogicalType::BIGINT),
|
|
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>));
|
|
83508
83779
|
set.AddFunction(generate_series);
|
|
83509
83780
|
}
|
|
83510
83781
|
|
|
@@ -85066,12 +85337,7 @@ date_t AddOperator::Operation(interval_t left, date_t right) {
|
|
|
85066
85337
|
|
|
85067
85338
|
template <>
|
|
85068
85339
|
timestamp_t AddOperator::Operation(timestamp_t left, interval_t right) {
|
|
85069
|
-
|
|
85070
|
-
dtime_t time;
|
|
85071
|
-
Timestamp::Convert(left, date, time);
|
|
85072
|
-
auto new_date = Interval::Add(date, right);
|
|
85073
|
-
auto new_time = Interval::Add(time, right, new_date);
|
|
85074
|
-
return Timestamp::FromDatetime(new_date, new_time);
|
|
85340
|
+
return Interval::Add(left, right);
|
|
85075
85341
|
}
|
|
85076
85342
|
|
|
85077
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 "
|
|
14
|
-
#define DUCKDB_VERSION "0.3.2-
|
|
13
|
+
#define DUCKDB_SOURCE_ID "3e3b464ce"
|
|
14
|
+
#define DUCKDB_VERSION "0.3.2-dev685"
|
|
15
15
|
//===----------------------------------------------------------------------===//
|
|
16
16
|
// DuckDB
|
|
17
17
|
//
|
|
@@ -5382,11 +5382,11 @@ public:
|
|
|
5382
5382
|
}
|
|
5383
5383
|
|
|
5384
5384
|
//! Returns the type of the expression
|
|
5385
|
-
ExpressionType GetExpressionType() {
|
|
5385
|
+
ExpressionType GetExpressionType() const {
|
|
5386
5386
|
return type;
|
|
5387
5387
|
}
|
|
5388
5388
|
//! Returns the class of the expression
|
|
5389
|
-
ExpressionClass GetExpressionClass() {
|
|
5389
|
+
ExpressionClass GetExpressionClass() const {
|
|
5390
5390
|
return expression_class;
|
|
5391
5391
|
}
|
|
5392
5392
|
|
|
@@ -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);
|
|
@@ -9187,6 +9189,7 @@ enum class PhysicalOperatorType : uint8_t {
|
|
|
9187
9189
|
COPY_TO_FILE,
|
|
9188
9190
|
RESERVOIR_SAMPLE,
|
|
9189
9191
|
STREAMING_SAMPLE,
|
|
9192
|
+
STREAMING_WINDOW,
|
|
9190
9193
|
// -----------------------------
|
|
9191
9194
|
// Scans
|
|
9192
9195
|
// -----------------------------
|