duckdb 0.4.1-dev452.0 → 0.4.1-dev464.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 +249 -240
- package/src/duckdb.hpp +3 -3
- package/src/parquet-amalgamation.cpp +37317 -37063
- package/src/parquet-amalgamation.hpp +15 -0
package/package.json
CHANGED
package/src/duckdb.cpp
CHANGED
|
@@ -7600,8 +7600,8 @@ string PhysicalOperatorToString(PhysicalOperatorType type) {
|
|
|
7600
7600
|
return "STREAMING_WINDOW";
|
|
7601
7601
|
case PhysicalOperatorType::UNNEST:
|
|
7602
7602
|
return "UNNEST";
|
|
7603
|
-
case PhysicalOperatorType::
|
|
7604
|
-
return "
|
|
7603
|
+
case PhysicalOperatorType::UNGROUPED_AGGREGATE:
|
|
7604
|
+
return "UNGROUPED_AGGREGATE";
|
|
7605
7605
|
case PhysicalOperatorType::HASH_GROUP_BY:
|
|
7606
7606
|
return "HASH_GROUP_BY";
|
|
7607
7607
|
case PhysicalOperatorType::PERFECT_HASH_GROUP_BY:
|
|
@@ -58596,7 +58596,7 @@ string PhysicalPerfectHashAggregate::ParamsToString() const {
|
|
|
58596
58596
|
//===----------------------------------------------------------------------===//
|
|
58597
58597
|
// DuckDB
|
|
58598
58598
|
//
|
|
58599
|
-
// duckdb/execution/operator/aggregate/
|
|
58599
|
+
// duckdb/execution/operator/aggregate/physical_window.hpp
|
|
58600
58600
|
//
|
|
58601
58601
|
//
|
|
58602
58602
|
//===----------------------------------------------------------------------===//
|
|
@@ -58608,12 +58608,202 @@ string PhysicalPerfectHashAggregate::ParamsToString() const {
|
|
|
58608
58608
|
|
|
58609
58609
|
namespace duckdb {
|
|
58610
58610
|
|
|
58611
|
-
//!
|
|
58611
|
+
//! PhysicalStreamingWindow implements streaming window functions (i.e. with an empty OVER clause)
|
|
58612
|
+
class PhysicalStreamingWindow : public PhysicalOperator {
|
|
58613
|
+
public:
|
|
58614
|
+
PhysicalStreamingWindow(vector<LogicalType> types, vector<unique_ptr<Expression>> select_list,
|
|
58615
|
+
idx_t estimated_cardinality,
|
|
58616
|
+
PhysicalOperatorType type = PhysicalOperatorType::STREAMING_WINDOW);
|
|
58617
|
+
|
|
58618
|
+
//! The projection list of the WINDOW statement
|
|
58619
|
+
vector<unique_ptr<Expression>> select_list;
|
|
58620
|
+
|
|
58621
|
+
public:
|
|
58622
|
+
unique_ptr<GlobalOperatorState> GetGlobalOperatorState(ClientContext &context) const override;
|
|
58623
|
+
unique_ptr<OperatorState> GetOperatorState(ExecutionContext &context) const override;
|
|
58624
|
+
|
|
58625
|
+
OperatorResultType Execute(ExecutionContext &context, DataChunk &input, DataChunk &chunk,
|
|
58626
|
+
GlobalOperatorState &gstate, OperatorState &state) const override;
|
|
58627
|
+
|
|
58628
|
+
string ParamsToString() const override;
|
|
58629
|
+
};
|
|
58630
|
+
|
|
58631
|
+
} // namespace duckdb
|
|
58632
|
+
|
|
58633
|
+
|
|
58634
|
+
|
|
58635
|
+
//===----------------------------------------------------------------------===//
|
|
58636
|
+
// DuckDB
|
|
58637
|
+
//
|
|
58638
|
+
// duckdb/parallel/thread_context.hpp
|
|
58639
|
+
//
|
|
58640
|
+
//
|
|
58641
|
+
//===----------------------------------------------------------------------===//
|
|
58642
|
+
|
|
58643
|
+
|
|
58644
|
+
|
|
58645
|
+
|
|
58646
|
+
|
|
58647
|
+
namespace duckdb {
|
|
58648
|
+
class ClientContext;
|
|
58649
|
+
|
|
58650
|
+
//! The ThreadContext holds thread-local info for parallel usage
|
|
58651
|
+
class ThreadContext {
|
|
58652
|
+
public:
|
|
58653
|
+
explicit ThreadContext(ClientContext &context);
|
|
58654
|
+
|
|
58655
|
+
//! The operator profiler for the individual thread context
|
|
58656
|
+
OperatorProfiler profiler;
|
|
58657
|
+
};
|
|
58658
|
+
|
|
58659
|
+
} // namespace duckdb
|
|
58660
|
+
|
|
58661
|
+
|
|
58662
|
+
|
|
58663
|
+
|
|
58664
|
+
namespace duckdb {
|
|
58665
|
+
|
|
58666
|
+
PhysicalStreamingWindow::PhysicalStreamingWindow(vector<LogicalType> types, vector<unique_ptr<Expression>> select_list,
|
|
58667
|
+
idx_t estimated_cardinality, PhysicalOperatorType type)
|
|
58668
|
+
: PhysicalOperator(type, move(types), estimated_cardinality), select_list(move(select_list)) {
|
|
58669
|
+
}
|
|
58670
|
+
|
|
58671
|
+
class StreamingWindowGlobalState : public GlobalOperatorState {
|
|
58672
|
+
public:
|
|
58673
|
+
StreamingWindowGlobalState() : row_number(1) {
|
|
58674
|
+
}
|
|
58675
|
+
|
|
58676
|
+
//! The next row number.
|
|
58677
|
+
std::atomic<int64_t> row_number;
|
|
58678
|
+
};
|
|
58679
|
+
|
|
58680
|
+
class StreamingWindowState : public OperatorState {
|
|
58681
|
+
public:
|
|
58682
|
+
StreamingWindowState() : initialized(false) {
|
|
58683
|
+
}
|
|
58684
|
+
|
|
58685
|
+
void Initialize(Allocator &allocator, DataChunk &input, const vector<unique_ptr<Expression>> &expressions) {
|
|
58686
|
+
for (idx_t expr_idx = 0; expr_idx < expressions.size(); expr_idx++) {
|
|
58687
|
+
auto &expr = *expressions[expr_idx];
|
|
58688
|
+
switch (expr.GetExpressionType()) {
|
|
58689
|
+
case ExpressionType::WINDOW_FIRST_VALUE: {
|
|
58690
|
+
auto &wexpr = (BoundWindowExpression &)expr;
|
|
58691
|
+
|
|
58692
|
+
// Just execute the expression once
|
|
58693
|
+
ExpressionExecutor executor(allocator);
|
|
58694
|
+
executor.AddExpression(*wexpr.children[0]);
|
|
58695
|
+
DataChunk result;
|
|
58696
|
+
result.Initialize(allocator, {wexpr.children[0]->return_type});
|
|
58697
|
+
executor.Execute(input, result);
|
|
58698
|
+
|
|
58699
|
+
const_vectors.push_back(make_unique<Vector>(result.GetValue(0, 0)));
|
|
58700
|
+
break;
|
|
58701
|
+
}
|
|
58702
|
+
case ExpressionType::WINDOW_PERCENT_RANK: {
|
|
58703
|
+
const_vectors.push_back(make_unique<Vector>(Value((double)0)));
|
|
58704
|
+
break;
|
|
58705
|
+
}
|
|
58706
|
+
case ExpressionType::WINDOW_RANK:
|
|
58707
|
+
case ExpressionType::WINDOW_RANK_DENSE: {
|
|
58708
|
+
const_vectors.push_back(make_unique<Vector>(Value((int64_t)1)));
|
|
58709
|
+
break;
|
|
58710
|
+
}
|
|
58711
|
+
default:
|
|
58712
|
+
const_vectors.push_back(nullptr);
|
|
58713
|
+
}
|
|
58714
|
+
}
|
|
58715
|
+
initialized = true;
|
|
58716
|
+
}
|
|
58717
|
+
|
|
58718
|
+
public:
|
|
58719
|
+
bool initialized;
|
|
58720
|
+
vector<unique_ptr<Vector>> const_vectors;
|
|
58721
|
+
};
|
|
58722
|
+
|
|
58723
|
+
unique_ptr<GlobalOperatorState> PhysicalStreamingWindow::GetGlobalOperatorState(ClientContext &context) const {
|
|
58724
|
+
return make_unique<StreamingWindowGlobalState>();
|
|
58725
|
+
}
|
|
58726
|
+
|
|
58727
|
+
unique_ptr<OperatorState> PhysicalStreamingWindow::GetOperatorState(ExecutionContext &context) const {
|
|
58728
|
+
return make_unique<StreamingWindowState>();
|
|
58729
|
+
}
|
|
58730
|
+
|
|
58731
|
+
OperatorResultType PhysicalStreamingWindow::Execute(ExecutionContext &context, DataChunk &input, DataChunk &chunk,
|
|
58732
|
+
GlobalOperatorState &gstate_p, OperatorState &state_p) const {
|
|
58733
|
+
auto &gstate = (StreamingWindowGlobalState &)gstate_p;
|
|
58734
|
+
auto &state = (StreamingWindowState &)state_p;
|
|
58735
|
+
if (!state.initialized) {
|
|
58736
|
+
auto &allocator = Allocator::Get(context.client);
|
|
58737
|
+
state.Initialize(allocator, input, select_list);
|
|
58738
|
+
}
|
|
58739
|
+
// Put payload columns in place
|
|
58740
|
+
for (idx_t col_idx = 0; col_idx < input.data.size(); col_idx++) {
|
|
58741
|
+
chunk.data[col_idx].Reference(input.data[col_idx]);
|
|
58742
|
+
}
|
|
58743
|
+
// Compute window function
|
|
58744
|
+
const idx_t count = input.size();
|
|
58745
|
+
for (idx_t expr_idx = 0; expr_idx < select_list.size(); expr_idx++) {
|
|
58746
|
+
idx_t col_idx = input.data.size() + expr_idx;
|
|
58747
|
+
auto &expr = *select_list[expr_idx];
|
|
58748
|
+
switch (expr.GetExpressionType()) {
|
|
58749
|
+
case ExpressionType::WINDOW_FIRST_VALUE:
|
|
58750
|
+
case ExpressionType::WINDOW_PERCENT_RANK:
|
|
58751
|
+
case ExpressionType::WINDOW_RANK:
|
|
58752
|
+
case ExpressionType::WINDOW_RANK_DENSE: {
|
|
58753
|
+
// Reference constant vector
|
|
58754
|
+
chunk.data[col_idx].Reference(*state.const_vectors[expr_idx]);
|
|
58755
|
+
break;
|
|
58756
|
+
}
|
|
58757
|
+
case ExpressionType::WINDOW_ROW_NUMBER: {
|
|
58758
|
+
// Set row numbers
|
|
58759
|
+
auto rdata = FlatVector::GetData<int64_t>(chunk.data[col_idx]);
|
|
58760
|
+
for (idx_t i = 0; i < count; i++) {
|
|
58761
|
+
rdata[i] = gstate.row_number + i;
|
|
58762
|
+
}
|
|
58763
|
+
break;
|
|
58764
|
+
}
|
|
58765
|
+
default:
|
|
58766
|
+
throw NotImplementedException("%s for StreamingWindow", ExpressionTypeToString(expr.GetExpressionType()));
|
|
58767
|
+
}
|
|
58768
|
+
}
|
|
58769
|
+
gstate.row_number += count;
|
|
58770
|
+
chunk.SetCardinality(count);
|
|
58771
|
+
return OperatorResultType::NEED_MORE_INPUT;
|
|
58772
|
+
}
|
|
58773
|
+
|
|
58774
|
+
string PhysicalStreamingWindow::ParamsToString() const {
|
|
58775
|
+
string result;
|
|
58776
|
+
for (idx_t i = 0; i < select_list.size(); i++) {
|
|
58777
|
+
if (i > 0) {
|
|
58778
|
+
result += "\n";
|
|
58779
|
+
}
|
|
58780
|
+
result += select_list[i]->GetName();
|
|
58781
|
+
}
|
|
58782
|
+
return result;
|
|
58783
|
+
}
|
|
58784
|
+
|
|
58785
|
+
} // namespace duckdb
|
|
58786
|
+
//===----------------------------------------------------------------------===//
|
|
58787
|
+
// DuckDB
|
|
58788
|
+
//
|
|
58789
|
+
// duckdb/execution/operator/aggregate/physical_ungrouped_aggregate.hpp
|
|
58790
|
+
//
|
|
58791
|
+
//
|
|
58792
|
+
//===----------------------------------------------------------------------===//
|
|
58793
|
+
|
|
58794
|
+
|
|
58795
|
+
|
|
58796
|
+
|
|
58797
|
+
|
|
58798
|
+
|
|
58799
|
+
namespace duckdb {
|
|
58800
|
+
|
|
58801
|
+
//! PhysicalUngroupedAggregate is an aggregate operator that can only perform aggregates (1) without any groups, (2)
|
|
58612
58802
|
//! without any DISTINCT aggregates, and (3) when all aggregates are combineable
|
|
58613
|
-
class
|
|
58803
|
+
class PhysicalUngroupedAggregate : public PhysicalOperator {
|
|
58614
58804
|
public:
|
|
58615
|
-
|
|
58616
|
-
|
|
58805
|
+
PhysicalUngroupedAggregate(vector<LogicalType> types, vector<unique_ptr<Expression>> expressions,
|
|
58806
|
+
idx_t estimated_cardinality);
|
|
58617
58807
|
|
|
58618
58808
|
//! The aggregates that have to be computed
|
|
58619
58809
|
vector<unique_ptr<Expression>> aggregates;
|
|
@@ -58654,39 +58844,15 @@ public:
|
|
|
58654
58844
|
|
|
58655
58845
|
|
|
58656
58846
|
|
|
58657
|
-
//===----------------------------------------------------------------------===//
|
|
58658
|
-
// DuckDB
|
|
58659
|
-
//
|
|
58660
|
-
// duckdb/parallel/thread_context.hpp
|
|
58661
|
-
//
|
|
58662
|
-
//
|
|
58663
|
-
//===----------------------------------------------------------------------===//
|
|
58664
|
-
|
|
58665
|
-
|
|
58666
|
-
|
|
58667
|
-
|
|
58668
|
-
|
|
58669
|
-
namespace duckdb {
|
|
58670
|
-
class ClientContext;
|
|
58671
|
-
|
|
58672
|
-
//! The ThreadContext holds thread-local info for parallel usage
|
|
58673
|
-
class ThreadContext {
|
|
58674
|
-
public:
|
|
58675
|
-
explicit ThreadContext(ClientContext &context);
|
|
58676
|
-
|
|
58677
|
-
//! The operator profiler for the individual thread context
|
|
58678
|
-
OperatorProfiler profiler;
|
|
58679
|
-
};
|
|
58680
|
-
|
|
58681
|
-
} // namespace duckdb
|
|
58682
58847
|
|
|
58683
58848
|
|
|
58684
58849
|
|
|
58685
58850
|
namespace duckdb {
|
|
58686
58851
|
|
|
58687
|
-
|
|
58688
|
-
|
|
58689
|
-
|
|
58852
|
+
PhysicalUngroupedAggregate::PhysicalUngroupedAggregate(vector<LogicalType> types,
|
|
58853
|
+
vector<unique_ptr<Expression>> expressions,
|
|
58854
|
+
idx_t estimated_cardinality)
|
|
58855
|
+
: PhysicalOperator(PhysicalOperatorType::UNGROUPED_AGGREGATE, move(types), estimated_cardinality),
|
|
58690
58856
|
aggregates(move(expressions)) {
|
|
58691
58857
|
}
|
|
58692
58858
|
|
|
@@ -58785,16 +58951,16 @@ public:
|
|
|
58785
58951
|
AggregateFilterDataSet filter_set;
|
|
58786
58952
|
};
|
|
58787
58953
|
|
|
58788
|
-
unique_ptr<GlobalSinkState>
|
|
58954
|
+
unique_ptr<GlobalSinkState> PhysicalUngroupedAggregate::GetGlobalSinkState(ClientContext &context) const {
|
|
58789
58955
|
return make_unique<SimpleAggregateGlobalState>(aggregates);
|
|
58790
58956
|
}
|
|
58791
58957
|
|
|
58792
|
-
unique_ptr<LocalSinkState>
|
|
58958
|
+
unique_ptr<LocalSinkState> PhysicalUngroupedAggregate::GetLocalSinkState(ExecutionContext &context) const {
|
|
58793
58959
|
return make_unique<SimpleAggregateLocalState>(Allocator::Get(context.client), aggregates, children[0]->GetTypes());
|
|
58794
58960
|
}
|
|
58795
58961
|
|
|
58796
|
-
SinkResultType
|
|
58797
|
-
|
|
58962
|
+
SinkResultType PhysicalUngroupedAggregate::Sink(ExecutionContext &context, GlobalSinkState &state,
|
|
58963
|
+
LocalSinkState &lstate, DataChunk &input) const {
|
|
58798
58964
|
auto &sink = (SimpleAggregateLocalState &)lstate;
|
|
58799
58965
|
// perform the aggregation inside the local state
|
|
58800
58966
|
idx_t payload_idx = 0, payload_expr_idx = 0;
|
|
@@ -58840,7 +59006,8 @@ SinkResultType PhysicalSimpleAggregate::Sink(ExecutionContext &context, GlobalSi
|
|
|
58840
59006
|
//===--------------------------------------------------------------------===//
|
|
58841
59007
|
// Finalize
|
|
58842
59008
|
//===--------------------------------------------------------------------===//
|
|
58843
|
-
void
|
|
59009
|
+
void PhysicalUngroupedAggregate::Combine(ExecutionContext &context, GlobalSinkState &state,
|
|
59010
|
+
LocalSinkState &lstate) const {
|
|
58844
59011
|
auto &gstate = (SimpleAggregateGlobalState &)state;
|
|
58845
59012
|
auto &source = (SimpleAggregateLocalState &)lstate;
|
|
58846
59013
|
D_ASSERT(!gstate.finished);
|
|
@@ -58866,8 +59033,8 @@ void PhysicalSimpleAggregate::Combine(ExecutionContext &context, GlobalSinkState
|
|
|
58866
59033
|
client_profiler.Flush(context.thread.profiler);
|
|
58867
59034
|
}
|
|
58868
59035
|
|
|
58869
|
-
SinkFinalizeType
|
|
58870
|
-
|
|
59036
|
+
SinkFinalizeType PhysicalUngroupedAggregate::Finalize(Pipeline &pipeline, Event &event, ClientContext &context,
|
|
59037
|
+
GlobalSinkState &gstate_p) const {
|
|
58871
59038
|
auto &gstate = (SimpleAggregateGlobalState &)gstate_p;
|
|
58872
59039
|
|
|
58873
59040
|
D_ASSERT(!gstate.finished);
|
|
@@ -58886,7 +59053,7 @@ public:
|
|
|
58886
59053
|
bool finished;
|
|
58887
59054
|
};
|
|
58888
59055
|
|
|
58889
|
-
unique_ptr<GlobalSourceState>
|
|
59056
|
+
unique_ptr<GlobalSourceState> PhysicalUngroupedAggregate::GetGlobalSourceState(ClientContext &context) const {
|
|
58890
59057
|
return make_unique<SimpleAggregateState>();
|
|
58891
59058
|
}
|
|
58892
59059
|
|
|
@@ -58904,8 +59071,8 @@ void VerifyNullHandling(DataChunk &chunk, AggregateState &state, const vector<un
|
|
|
58904
59071
|
#endif
|
|
58905
59072
|
}
|
|
58906
59073
|
|
|
58907
|
-
void
|
|
58908
|
-
|
|
59074
|
+
void PhysicalUngroupedAggregate::GetData(ExecutionContext &context, DataChunk &chunk, GlobalSourceState &gstate_p,
|
|
59075
|
+
LocalSourceState &lstate) const {
|
|
58909
59076
|
auto &gstate = (SimpleAggregateGlobalState &)*sink_state;
|
|
58910
59077
|
auto &state = (SimpleAggregateState &)gstate_p;
|
|
58911
59078
|
D_ASSERT(gstate.finished);
|
|
@@ -58926,7 +59093,7 @@ void PhysicalSimpleAggregate::GetData(ExecutionContext &context, DataChunk &chun
|
|
|
58926
59093
|
state.finished = true;
|
|
58927
59094
|
}
|
|
58928
59095
|
|
|
58929
|
-
string
|
|
59096
|
+
string PhysicalUngroupedAggregate::ParamsToString() const {
|
|
58930
59097
|
string result;
|
|
58931
59098
|
for (idx_t i = 0; i < aggregates.size(); i++) {
|
|
58932
59099
|
auto &aggregate = (BoundAggregateExpression &)*aggregates[i];
|
|
@@ -58955,171 +59122,6 @@ string PhysicalSimpleAggregate::ParamsToString() const {
|
|
|
58955
59122
|
|
|
58956
59123
|
|
|
58957
59124
|
|
|
58958
|
-
namespace duckdb {
|
|
58959
|
-
|
|
58960
|
-
//! PhysicalStreamingWindow implements streaming window functions (i.e. with an empty OVER clause)
|
|
58961
|
-
class PhysicalStreamingWindow : public PhysicalOperator {
|
|
58962
|
-
public:
|
|
58963
|
-
PhysicalStreamingWindow(vector<LogicalType> types, vector<unique_ptr<Expression>> select_list,
|
|
58964
|
-
idx_t estimated_cardinality,
|
|
58965
|
-
PhysicalOperatorType type = PhysicalOperatorType::STREAMING_WINDOW);
|
|
58966
|
-
|
|
58967
|
-
//! The projection list of the WINDOW statement
|
|
58968
|
-
vector<unique_ptr<Expression>> select_list;
|
|
58969
|
-
|
|
58970
|
-
public:
|
|
58971
|
-
unique_ptr<GlobalOperatorState> GetGlobalOperatorState(ClientContext &context) const override;
|
|
58972
|
-
unique_ptr<OperatorState> GetOperatorState(ExecutionContext &context) const override;
|
|
58973
|
-
|
|
58974
|
-
OperatorResultType Execute(ExecutionContext &context, DataChunk &input, DataChunk &chunk,
|
|
58975
|
-
GlobalOperatorState &gstate, OperatorState &state) const override;
|
|
58976
|
-
|
|
58977
|
-
string ParamsToString() const override;
|
|
58978
|
-
};
|
|
58979
|
-
|
|
58980
|
-
} // namespace duckdb
|
|
58981
|
-
|
|
58982
|
-
|
|
58983
|
-
|
|
58984
|
-
|
|
58985
|
-
|
|
58986
|
-
|
|
58987
|
-
|
|
58988
|
-
namespace duckdb {
|
|
58989
|
-
|
|
58990
|
-
PhysicalStreamingWindow::PhysicalStreamingWindow(vector<LogicalType> types, vector<unique_ptr<Expression>> select_list,
|
|
58991
|
-
idx_t estimated_cardinality, PhysicalOperatorType type)
|
|
58992
|
-
: PhysicalOperator(type, move(types), estimated_cardinality), select_list(move(select_list)) {
|
|
58993
|
-
}
|
|
58994
|
-
|
|
58995
|
-
class StreamingWindowGlobalState : public GlobalOperatorState {
|
|
58996
|
-
public:
|
|
58997
|
-
StreamingWindowGlobalState() : row_number(1) {
|
|
58998
|
-
}
|
|
58999
|
-
|
|
59000
|
-
//! The next row number.
|
|
59001
|
-
std::atomic<int64_t> row_number;
|
|
59002
|
-
};
|
|
59003
|
-
|
|
59004
|
-
class StreamingWindowState : public OperatorState {
|
|
59005
|
-
public:
|
|
59006
|
-
StreamingWindowState() : initialized(false) {
|
|
59007
|
-
}
|
|
59008
|
-
|
|
59009
|
-
void Initialize(Allocator &allocator, DataChunk &input, const vector<unique_ptr<Expression>> &expressions) {
|
|
59010
|
-
for (idx_t expr_idx = 0; expr_idx < expressions.size(); expr_idx++) {
|
|
59011
|
-
auto &expr = *expressions[expr_idx];
|
|
59012
|
-
switch (expr.GetExpressionType()) {
|
|
59013
|
-
case ExpressionType::WINDOW_FIRST_VALUE: {
|
|
59014
|
-
auto &wexpr = (BoundWindowExpression &)expr;
|
|
59015
|
-
|
|
59016
|
-
// Just execute the expression once
|
|
59017
|
-
ExpressionExecutor executor(allocator);
|
|
59018
|
-
executor.AddExpression(*wexpr.children[0]);
|
|
59019
|
-
DataChunk result;
|
|
59020
|
-
result.Initialize(allocator, {wexpr.children[0]->return_type});
|
|
59021
|
-
executor.Execute(input, result);
|
|
59022
|
-
|
|
59023
|
-
const_vectors.push_back(make_unique<Vector>(result.GetValue(0, 0)));
|
|
59024
|
-
break;
|
|
59025
|
-
}
|
|
59026
|
-
case ExpressionType::WINDOW_PERCENT_RANK: {
|
|
59027
|
-
const_vectors.push_back(make_unique<Vector>(Value((double)0)));
|
|
59028
|
-
break;
|
|
59029
|
-
}
|
|
59030
|
-
case ExpressionType::WINDOW_RANK:
|
|
59031
|
-
case ExpressionType::WINDOW_RANK_DENSE: {
|
|
59032
|
-
const_vectors.push_back(make_unique<Vector>(Value((int64_t)1)));
|
|
59033
|
-
break;
|
|
59034
|
-
}
|
|
59035
|
-
default:
|
|
59036
|
-
const_vectors.push_back(nullptr);
|
|
59037
|
-
}
|
|
59038
|
-
}
|
|
59039
|
-
initialized = true;
|
|
59040
|
-
}
|
|
59041
|
-
|
|
59042
|
-
public:
|
|
59043
|
-
bool initialized;
|
|
59044
|
-
vector<unique_ptr<Vector>> const_vectors;
|
|
59045
|
-
};
|
|
59046
|
-
|
|
59047
|
-
unique_ptr<GlobalOperatorState> PhysicalStreamingWindow::GetGlobalOperatorState(ClientContext &context) const {
|
|
59048
|
-
return make_unique<StreamingWindowGlobalState>();
|
|
59049
|
-
}
|
|
59050
|
-
|
|
59051
|
-
unique_ptr<OperatorState> PhysicalStreamingWindow::GetOperatorState(ExecutionContext &context) const {
|
|
59052
|
-
return make_unique<StreamingWindowState>();
|
|
59053
|
-
}
|
|
59054
|
-
|
|
59055
|
-
OperatorResultType PhysicalStreamingWindow::Execute(ExecutionContext &context, DataChunk &input, DataChunk &chunk,
|
|
59056
|
-
GlobalOperatorState &gstate_p, OperatorState &state_p) const {
|
|
59057
|
-
auto &gstate = (StreamingWindowGlobalState &)gstate_p;
|
|
59058
|
-
auto &state = (StreamingWindowState &)state_p;
|
|
59059
|
-
if (!state.initialized) {
|
|
59060
|
-
auto &allocator = Allocator::Get(context.client);
|
|
59061
|
-
state.Initialize(allocator, input, select_list);
|
|
59062
|
-
}
|
|
59063
|
-
// Put payload columns in place
|
|
59064
|
-
for (idx_t col_idx = 0; col_idx < input.data.size(); col_idx++) {
|
|
59065
|
-
chunk.data[col_idx].Reference(input.data[col_idx]);
|
|
59066
|
-
}
|
|
59067
|
-
// Compute window function
|
|
59068
|
-
const idx_t count = input.size();
|
|
59069
|
-
for (idx_t expr_idx = 0; expr_idx < select_list.size(); expr_idx++) {
|
|
59070
|
-
idx_t col_idx = input.data.size() + expr_idx;
|
|
59071
|
-
auto &expr = *select_list[expr_idx];
|
|
59072
|
-
switch (expr.GetExpressionType()) {
|
|
59073
|
-
case ExpressionType::WINDOW_FIRST_VALUE:
|
|
59074
|
-
case ExpressionType::WINDOW_PERCENT_RANK:
|
|
59075
|
-
case ExpressionType::WINDOW_RANK:
|
|
59076
|
-
case ExpressionType::WINDOW_RANK_DENSE: {
|
|
59077
|
-
// Reference constant vector
|
|
59078
|
-
chunk.data[col_idx].Reference(*state.const_vectors[expr_idx]);
|
|
59079
|
-
break;
|
|
59080
|
-
}
|
|
59081
|
-
case ExpressionType::WINDOW_ROW_NUMBER: {
|
|
59082
|
-
// Set row numbers
|
|
59083
|
-
auto rdata = FlatVector::GetData<int64_t>(chunk.data[col_idx]);
|
|
59084
|
-
for (idx_t i = 0; i < count; i++) {
|
|
59085
|
-
rdata[i] = gstate.row_number + i;
|
|
59086
|
-
}
|
|
59087
|
-
break;
|
|
59088
|
-
}
|
|
59089
|
-
default:
|
|
59090
|
-
throw NotImplementedException("%s for StreamingWindow", ExpressionTypeToString(expr.GetExpressionType()));
|
|
59091
|
-
}
|
|
59092
|
-
}
|
|
59093
|
-
gstate.row_number += count;
|
|
59094
|
-
chunk.SetCardinality(count);
|
|
59095
|
-
return OperatorResultType::NEED_MORE_INPUT;
|
|
59096
|
-
}
|
|
59097
|
-
|
|
59098
|
-
string PhysicalStreamingWindow::ParamsToString() const {
|
|
59099
|
-
string result;
|
|
59100
|
-
for (idx_t i = 0; i < select_list.size(); i++) {
|
|
59101
|
-
if (i > 0) {
|
|
59102
|
-
result += "\n";
|
|
59103
|
-
}
|
|
59104
|
-
result += select_list[i]->GetName();
|
|
59105
|
-
}
|
|
59106
|
-
return result;
|
|
59107
|
-
}
|
|
59108
|
-
|
|
59109
|
-
} // namespace duckdb
|
|
59110
|
-
//===----------------------------------------------------------------------===//
|
|
59111
|
-
// DuckDB
|
|
59112
|
-
//
|
|
59113
|
-
// duckdb/execution/operator/aggregate/physical_window.hpp
|
|
59114
|
-
//
|
|
59115
|
-
//
|
|
59116
|
-
//===----------------------------------------------------------------------===//
|
|
59117
|
-
|
|
59118
|
-
|
|
59119
|
-
|
|
59120
|
-
|
|
59121
|
-
|
|
59122
|
-
|
|
59123
59125
|
|
|
59124
59126
|
namespace duckdb {
|
|
59125
59127
|
|
|
@@ -60301,34 +60303,41 @@ static void ComputeWindowExpression(BoundWindowExpression *wexpr, ChunkCollectio
|
|
|
60301
60303
|
}
|
|
60302
60304
|
case ExpressionType::WINDOW_NTILE: {
|
|
60303
60305
|
D_ASSERT(payload_collection.ColumnCount() == 1);
|
|
60304
|
-
|
|
60305
|
-
|
|
60306
|
-
int64_t n_total = bounds.partition_end - bounds.partition_start;
|
|
60307
|
-
if (n_param > n_total) {
|
|
60308
|
-
// more groups allowed than we have values
|
|
60309
|
-
// map every entry to a unique group
|
|
60310
|
-
n_param = n_total;
|
|
60311
|
-
}
|
|
60312
|
-
int64_t n_size = (n_total / n_param);
|
|
60313
|
-
// find the row idx within the group
|
|
60314
|
-
D_ASSERT(row_idx >= bounds.partition_start);
|
|
60315
|
-
int64_t adjusted_row_idx = row_idx - bounds.partition_start;
|
|
60316
|
-
// now compute the ntile
|
|
60317
|
-
int64_t n_large = n_total - n_param * n_size;
|
|
60318
|
-
int64_t i_small = n_large * (n_size + 1);
|
|
60319
|
-
int64_t result_ntile;
|
|
60320
|
-
|
|
60321
|
-
D_ASSERT((n_large * (n_size + 1) + (n_param - n_large) * n_size) == n_total);
|
|
60322
|
-
|
|
60323
|
-
if (adjusted_row_idx < i_small) {
|
|
60324
|
-
result_ntile = 1 + adjusted_row_idx / (n_size + 1);
|
|
60306
|
+
if (CellIsNull(payload_collection, 0, row_idx)) {
|
|
60307
|
+
FlatVector::SetNull(result, output_offset, true);
|
|
60325
60308
|
} else {
|
|
60326
|
-
|
|
60309
|
+
auto n_param = GetCell<int64_t>(payload_collection, 0, row_idx);
|
|
60310
|
+
if (n_param < 1) {
|
|
60311
|
+
throw InvalidInputException("Argument for ntile must be greater than zero");
|
|
60312
|
+
}
|
|
60313
|
+
// With thanks from SQLite's ntileValueFunc()
|
|
60314
|
+
int64_t n_total = bounds.partition_end - bounds.partition_start;
|
|
60315
|
+
if (n_param > n_total) {
|
|
60316
|
+
// more groups allowed than we have values
|
|
60317
|
+
// map every entry to a unique group
|
|
60318
|
+
n_param = n_total;
|
|
60319
|
+
}
|
|
60320
|
+
int64_t n_size = (n_total / n_param);
|
|
60321
|
+
// find the row idx within the group
|
|
60322
|
+
D_ASSERT(row_idx >= bounds.partition_start);
|
|
60323
|
+
int64_t adjusted_row_idx = row_idx - bounds.partition_start;
|
|
60324
|
+
// now compute the ntile
|
|
60325
|
+
int64_t n_large = n_total - n_param * n_size;
|
|
60326
|
+
int64_t i_small = n_large * (n_size + 1);
|
|
60327
|
+
int64_t result_ntile;
|
|
60328
|
+
|
|
60329
|
+
D_ASSERT((n_large * (n_size + 1) + (n_param - n_large) * n_size) == n_total);
|
|
60330
|
+
|
|
60331
|
+
if (adjusted_row_idx < i_small) {
|
|
60332
|
+
result_ntile = 1 + adjusted_row_idx / (n_size + 1);
|
|
60333
|
+
} else {
|
|
60334
|
+
result_ntile = 1 + n_large + (adjusted_row_idx - i_small) / n_size;
|
|
60335
|
+
}
|
|
60336
|
+
// result has to be between [1, NTILE]
|
|
60337
|
+
D_ASSERT(result_ntile >= 1 && result_ntile <= n_param);
|
|
60338
|
+
auto rdata = FlatVector::GetData<int64_t>(result);
|
|
60339
|
+
rdata[output_offset] = result_ntile;
|
|
60327
60340
|
}
|
|
60328
|
-
// result has to be between [1, NTILE]
|
|
60329
|
-
D_ASSERT(result_ntile >= 1 && result_ntile <= n_param);
|
|
60330
|
-
auto rdata = FlatVector::GetData<int64_t>(result);
|
|
60331
|
-
rdata[output_offset] = result_ntile;
|
|
60332
60341
|
break;
|
|
60333
60342
|
}
|
|
60334
60343
|
case ExpressionType::WINDOW_LEAD:
|
|
@@ -74763,8 +74772,8 @@ unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalAggregate
|
|
|
74763
74772
|
}
|
|
74764
74773
|
}
|
|
74765
74774
|
if (use_simple_aggregation) {
|
|
74766
|
-
groupby = make_unique_base<PhysicalOperator,
|
|
74767
|
-
|
|
74775
|
+
groupby = make_unique_base<PhysicalOperator, PhysicalUngroupedAggregate>(op.types, move(op.expressions),
|
|
74776
|
+
op.estimated_cardinality);
|
|
74768
74777
|
} else {
|
|
74769
74778
|
groupby = make_unique_base<PhysicalOperator, PhysicalHashAggregate>(context, op.types, move(op.expressions),
|
|
74770
74779
|
op.estimated_cardinality);
|
|
@@ -127308,7 +127317,7 @@ bool QueryProfiler::OperatorRequiresProfiling(PhysicalOperatorType op_type) {
|
|
|
127308
127317
|
case PhysicalOperatorType::TOP_N:
|
|
127309
127318
|
case PhysicalOperatorType::WINDOW:
|
|
127310
127319
|
case PhysicalOperatorType::UNNEST:
|
|
127311
|
-
case PhysicalOperatorType::
|
|
127320
|
+
case PhysicalOperatorType::UNGROUPED_AGGREGATE:
|
|
127312
127321
|
case PhysicalOperatorType::HASH_GROUP_BY:
|
|
127313
127322
|
case PhysicalOperatorType::FILTER:
|
|
127314
127323
|
case PhysicalOperatorType::PROJECTION:
|
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 "
|
|
15
|
-
#define DUCKDB_VERSION "v0.4.1-
|
|
14
|
+
#define DUCKDB_SOURCE_ID "f5be5d58a"
|
|
15
|
+
#define DUCKDB_VERSION "v0.4.1-dev464"
|
|
16
16
|
//===----------------------------------------------------------------------===//
|
|
17
17
|
// DuckDB
|
|
18
18
|
//
|
|
@@ -10544,7 +10544,7 @@ enum class PhysicalOperatorType : uint8_t {
|
|
|
10544
10544
|
TOP_N,
|
|
10545
10545
|
WINDOW,
|
|
10546
10546
|
UNNEST,
|
|
10547
|
-
|
|
10547
|
+
UNGROUPED_AGGREGATE,
|
|
10548
10548
|
HASH_GROUP_BY,
|
|
10549
10549
|
PERFECT_HASH_GROUP_BY,
|
|
10550
10550
|
FILTER,
|