duckdb 0.3.2-dev668.0 → 0.3.2-dev679.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 +187 -6
- package/src/duckdb.hpp +5 -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:
|
|
@@ -52691,6 +52693,149 @@ string PhysicalSimpleAggregate::ParamsToString() const {
|
|
|
52691
52693
|
|
|
52692
52694
|
|
|
52693
52695
|
|
|
52696
|
+
namespace duckdb {
|
|
52697
|
+
|
|
52698
|
+
//! PhysicalStreamingWindow implements streaming window functions (i.e. with an empty OVER clause)
|
|
52699
|
+
class PhysicalStreamingWindow : public PhysicalOperator {
|
|
52700
|
+
public:
|
|
52701
|
+
PhysicalStreamingWindow(vector<LogicalType> types, vector<unique_ptr<Expression>> select_list,
|
|
52702
|
+
idx_t estimated_cardinality,
|
|
52703
|
+
PhysicalOperatorType type = PhysicalOperatorType::STREAMING_WINDOW);
|
|
52704
|
+
|
|
52705
|
+
//! The projection list of the WINDOW statement
|
|
52706
|
+
vector<unique_ptr<Expression>> select_list;
|
|
52707
|
+
|
|
52708
|
+
public:
|
|
52709
|
+
unique_ptr<OperatorState> GetOperatorState(ClientContext &context) const override;
|
|
52710
|
+
|
|
52711
|
+
OperatorResultType Execute(ExecutionContext &context, DataChunk &input, DataChunk &chunk,
|
|
52712
|
+
OperatorState &state) const override;
|
|
52713
|
+
|
|
52714
|
+
string ParamsToString() const override;
|
|
52715
|
+
};
|
|
52716
|
+
|
|
52717
|
+
} // namespace duckdb
|
|
52718
|
+
|
|
52719
|
+
|
|
52720
|
+
|
|
52721
|
+
|
|
52722
|
+
|
|
52723
|
+
|
|
52724
|
+
|
|
52725
|
+
namespace duckdb {
|
|
52726
|
+
|
|
52727
|
+
PhysicalStreamingWindow::PhysicalStreamingWindow(vector<LogicalType> types, vector<unique_ptr<Expression>> select_list,
|
|
52728
|
+
idx_t estimated_cardinality, PhysicalOperatorType type)
|
|
52729
|
+
: PhysicalOperator(type, move(types), estimated_cardinality), select_list(move(select_list)) {
|
|
52730
|
+
}
|
|
52731
|
+
|
|
52732
|
+
class StreamingWindowState : public OperatorState {
|
|
52733
|
+
public:
|
|
52734
|
+
StreamingWindowState() : initialized(false), row_number(1) {
|
|
52735
|
+
}
|
|
52736
|
+
|
|
52737
|
+
void Initialize(DataChunk &input, const vector<unique_ptr<Expression>> &expressions) {
|
|
52738
|
+
for (idx_t expr_idx = 0; expr_idx < expressions.size(); expr_idx++) {
|
|
52739
|
+
auto &expr = *expressions[expr_idx];
|
|
52740
|
+
switch (expr.GetExpressionType()) {
|
|
52741
|
+
case ExpressionType::WINDOW_FIRST_VALUE: {
|
|
52742
|
+
auto &wexpr = (BoundWindowExpression &)expr;
|
|
52743
|
+
auto &ref = (BoundReferenceExpression &)*wexpr.children[0];
|
|
52744
|
+
const_vectors.push_back(make_unique<Vector>(input.data[ref.index].GetValue(0)));
|
|
52745
|
+
break;
|
|
52746
|
+
}
|
|
52747
|
+
case ExpressionType::WINDOW_PERCENT_RANK: {
|
|
52748
|
+
const_vectors.push_back(make_unique<Vector>(Value((double)0)));
|
|
52749
|
+
break;
|
|
52750
|
+
}
|
|
52751
|
+
case ExpressionType::WINDOW_RANK:
|
|
52752
|
+
case ExpressionType::WINDOW_RANK_DENSE: {
|
|
52753
|
+
const_vectors.push_back(make_unique<Vector>(Value((int64_t)1)));
|
|
52754
|
+
break;
|
|
52755
|
+
}
|
|
52756
|
+
default:
|
|
52757
|
+
const_vectors.push_back(nullptr);
|
|
52758
|
+
}
|
|
52759
|
+
}
|
|
52760
|
+
initialized = true;
|
|
52761
|
+
}
|
|
52762
|
+
|
|
52763
|
+
public:
|
|
52764
|
+
bool initialized;
|
|
52765
|
+
int64_t row_number;
|
|
52766
|
+
vector<unique_ptr<Vector>> const_vectors;
|
|
52767
|
+
};
|
|
52768
|
+
|
|
52769
|
+
unique_ptr<OperatorState> PhysicalStreamingWindow::GetOperatorState(ClientContext &context) const {
|
|
52770
|
+
return make_unique<StreamingWindowState>();
|
|
52771
|
+
}
|
|
52772
|
+
|
|
52773
|
+
OperatorResultType PhysicalStreamingWindow::Execute(ExecutionContext &context, DataChunk &input, DataChunk &chunk,
|
|
52774
|
+
OperatorState &state_p) const {
|
|
52775
|
+
auto &state = (StreamingWindowState &)state_p;
|
|
52776
|
+
if (!state.initialized) {
|
|
52777
|
+
state.Initialize(input, select_list);
|
|
52778
|
+
}
|
|
52779
|
+
// Put payload columns in place
|
|
52780
|
+
for (idx_t col_idx = 0; col_idx < input.data.size(); col_idx++) {
|
|
52781
|
+
chunk.data[col_idx].Reference(input.data[col_idx]);
|
|
52782
|
+
}
|
|
52783
|
+
// Compute window function
|
|
52784
|
+
const idx_t count = input.size();
|
|
52785
|
+
for (idx_t expr_idx = 0; expr_idx < select_list.size(); expr_idx++) {
|
|
52786
|
+
idx_t col_idx = input.data.size() + expr_idx;
|
|
52787
|
+
auto &expr = *select_list[expr_idx];
|
|
52788
|
+
switch (expr.GetExpressionType()) {
|
|
52789
|
+
case ExpressionType::WINDOW_FIRST_VALUE:
|
|
52790
|
+
case ExpressionType::WINDOW_PERCENT_RANK:
|
|
52791
|
+
case ExpressionType::WINDOW_RANK:
|
|
52792
|
+
case ExpressionType::WINDOW_RANK_DENSE: {
|
|
52793
|
+
// Reference constant vector
|
|
52794
|
+
chunk.data[col_idx].Reference(*state.const_vectors[expr_idx]);
|
|
52795
|
+
break;
|
|
52796
|
+
}
|
|
52797
|
+
case ExpressionType::WINDOW_ROW_NUMBER: {
|
|
52798
|
+
// Set row numbers
|
|
52799
|
+
auto rdata = FlatVector::GetData<int64_t>(chunk.data[col_idx]);
|
|
52800
|
+
for (idx_t i = 0; i < count; i++) {
|
|
52801
|
+
rdata[i] = state.row_number + i;
|
|
52802
|
+
}
|
|
52803
|
+
break;
|
|
52804
|
+
}
|
|
52805
|
+
default:
|
|
52806
|
+
throw NotImplementedException("%s for StreamingWindow", ExpressionTypeToString(expr.GetExpressionType()));
|
|
52807
|
+
}
|
|
52808
|
+
}
|
|
52809
|
+
state.row_number += count;
|
|
52810
|
+
chunk.SetCardinality(count);
|
|
52811
|
+
return OperatorResultType::NEED_MORE_INPUT;
|
|
52812
|
+
}
|
|
52813
|
+
|
|
52814
|
+
string PhysicalStreamingWindow::ParamsToString() const {
|
|
52815
|
+
string result;
|
|
52816
|
+
for (idx_t i = 0; i < select_list.size(); i++) {
|
|
52817
|
+
if (i > 0) {
|
|
52818
|
+
result += "\n";
|
|
52819
|
+
}
|
|
52820
|
+
result += select_list[i]->GetName();
|
|
52821
|
+
}
|
|
52822
|
+
return result;
|
|
52823
|
+
}
|
|
52824
|
+
|
|
52825
|
+
} // namespace duckdb
|
|
52826
|
+
//===----------------------------------------------------------------------===//
|
|
52827
|
+
// DuckDB
|
|
52828
|
+
//
|
|
52829
|
+
// duckdb/execution/operator/aggregate/physical_window.hpp
|
|
52830
|
+
//
|
|
52831
|
+
//
|
|
52832
|
+
//===----------------------------------------------------------------------===//
|
|
52833
|
+
|
|
52834
|
+
|
|
52835
|
+
|
|
52836
|
+
|
|
52837
|
+
|
|
52838
|
+
|
|
52694
52839
|
|
|
52695
52840
|
namespace duckdb {
|
|
52696
52841
|
|
|
@@ -68409,6 +68554,9 @@ unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalUpdate &op
|
|
|
68409
68554
|
|
|
68410
68555
|
|
|
68411
68556
|
|
|
68557
|
+
|
|
68558
|
+
|
|
68559
|
+
|
|
68412
68560
|
//===----------------------------------------------------------------------===//
|
|
68413
68561
|
// DuckDB
|
|
68414
68562
|
//
|
|
@@ -68442,12 +68590,28 @@ protected:
|
|
|
68442
68590
|
} // namespace duckdb
|
|
68443
68591
|
|
|
68444
68592
|
|
|
68445
|
-
|
|
68446
|
-
|
|
68447
68593
|
#include <numeric>
|
|
68448
68594
|
|
|
68449
68595
|
namespace duckdb {
|
|
68450
68596
|
|
|
68597
|
+
static bool IsStreamingWindow(unique_ptr<Expression> &expr) {
|
|
68598
|
+
auto wexpr = reinterpret_cast<BoundWindowExpression *>(expr.get());
|
|
68599
|
+
if (!wexpr->partitions.empty() || !wexpr->orders.empty() || wexpr->ignore_nulls) {
|
|
68600
|
+
return false;
|
|
68601
|
+
}
|
|
68602
|
+
switch (wexpr->type) {
|
|
68603
|
+
// TODO: add more expression types here?
|
|
68604
|
+
case ExpressionType::WINDOW_FIRST_VALUE:
|
|
68605
|
+
case ExpressionType::WINDOW_PERCENT_RANK:
|
|
68606
|
+
case ExpressionType::WINDOW_RANK:
|
|
68607
|
+
case ExpressionType::WINDOW_RANK_DENSE:
|
|
68608
|
+
case ExpressionType::WINDOW_ROW_NUMBER:
|
|
68609
|
+
return true;
|
|
68610
|
+
default:
|
|
68611
|
+
return false;
|
|
68612
|
+
}
|
|
68613
|
+
}
|
|
68614
|
+
|
|
68451
68615
|
unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalWindow &op) {
|
|
68452
68616
|
D_ASSERT(op.children.size() == 1);
|
|
68453
68617
|
|
|
@@ -68463,11 +68627,23 @@ unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalWindow &op
|
|
|
68463
68627
|
const auto output_idx = types.size() - op.expressions.size();
|
|
68464
68628
|
types.resize(output_idx);
|
|
68465
68629
|
|
|
68630
|
+
// Identify streaming windows
|
|
68631
|
+
vector<idx_t> blocking_windows;
|
|
68632
|
+
vector<idx_t> streaming_windows;
|
|
68633
|
+
for (idx_t expr_idx = 0; expr_idx < op.expressions.size(); expr_idx++) {
|
|
68634
|
+
if (IsStreamingWindow(op.expressions[expr_idx])) {
|
|
68635
|
+
streaming_windows.push_back(expr_idx);
|
|
68636
|
+
} else {
|
|
68637
|
+
blocking_windows.push_back(expr_idx);
|
|
68638
|
+
}
|
|
68639
|
+
}
|
|
68640
|
+
|
|
68466
68641
|
// Process the window functions by sharing the partition/order definitions
|
|
68467
68642
|
vector<idx_t> evaluation_order;
|
|
68468
|
-
|
|
68469
|
-
|
|
68470
|
-
|
|
68643
|
+
while (!blocking_windows.empty() || !streaming_windows.empty()) {
|
|
68644
|
+
const bool process_streaming = blocking_windows.empty();
|
|
68645
|
+
auto &remaining = process_streaming ? streaming_windows : blocking_windows;
|
|
68646
|
+
|
|
68471
68647
|
// Find all functions that share the partitioning of the first remaining expression
|
|
68472
68648
|
const auto over_idx = remaining[0];
|
|
68473
68649
|
auto over_expr = reinterpret_cast<BoundWindowExpression *>(op.expressions[over_idx].get());
|
|
@@ -68493,7 +68669,12 @@ unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalWindow &op
|
|
|
68493
68669
|
}
|
|
68494
68670
|
|
|
68495
68671
|
// Chain the new window operator on top of the plan
|
|
68496
|
-
|
|
68672
|
+
unique_ptr<PhysicalOperator> window;
|
|
68673
|
+
if (process_streaming) {
|
|
68674
|
+
window = make_unique<PhysicalStreamingWindow>(types, move(select_list), op.estimated_cardinality);
|
|
68675
|
+
} else {
|
|
68676
|
+
window = make_unique<PhysicalWindow>(types, move(select_list), op.estimated_cardinality);
|
|
68677
|
+
}
|
|
68497
68678
|
window->children.push_back(move(plan));
|
|
68498
68679
|
plan = move(window);
|
|
68499
68680
|
|
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 "000fbffa3"
|
|
14
|
+
#define DUCKDB_VERSION "0.3.2-dev679"
|
|
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
|
|
|
@@ -9187,6 +9187,7 @@ enum class PhysicalOperatorType : uint8_t {
|
|
|
9187
9187
|
COPY_TO_FILE,
|
|
9188
9188
|
RESERVOIR_SAMPLE,
|
|
9189
9189
|
STREAMING_SAMPLE,
|
|
9190
|
+
STREAMING_WINDOW,
|
|
9190
9191
|
// -----------------------------
|
|
9191
9192
|
// Scans
|
|
9192
9193
|
// -----------------------------
|