duckdb 0.3.2-dev658.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 +365 -11
- package/src/duckdb.hpp +6 -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:
|
|
@@ -24915,8 +24917,8 @@ static void GatherNestedVector(Vector &rows, const SelectionVector &row_sel, Vec
|
|
|
24915
24917
|
auto ptrs = FlatVector::GetData<data_ptr_t>(rows);
|
|
24916
24918
|
|
|
24917
24919
|
// Build the gather locations
|
|
24918
|
-
|
|
24919
|
-
|
|
24920
|
+
auto data_locations = unique_ptr<data_ptr_t[]>(new data_ptr_t[count]);
|
|
24921
|
+
auto mask_locations = unique_ptr<data_ptr_t[]>(new data_ptr_t[count]);
|
|
24920
24922
|
for (idx_t i = 0; i < count; i++) {
|
|
24921
24923
|
auto row_idx = row_sel.get_index(i);
|
|
24922
24924
|
mask_locations[i] = ptrs[row_idx];
|
|
@@ -24924,7 +24926,7 @@ static void GatherNestedVector(Vector &rows, const SelectionVector &row_sel, Vec
|
|
|
24924
24926
|
}
|
|
24925
24927
|
|
|
24926
24928
|
// Deserialise into the selected locations
|
|
24927
|
-
RowOperations::HeapGather(col, count, col_sel, col_no, data_locations, mask_locations);
|
|
24929
|
+
RowOperations::HeapGather(col, count, col_sel, col_no, data_locations.get(), mask_locations.get());
|
|
24928
24930
|
}
|
|
24929
24931
|
|
|
24930
24932
|
void RowOperations::Gather(Vector &rows, const SelectionVector &row_sel, Vector &col, const SelectionVector &col_sel,
|
|
@@ -37647,6 +37649,19 @@ T Value::GetValueInternal() const {
|
|
|
37647
37649
|
return Cast::Operation<interval_t, T>(value_.interval);
|
|
37648
37650
|
case LogicalTypeId::DECIMAL:
|
|
37649
37651
|
return CastAs(LogicalType::DOUBLE).GetValueInternal<T>();
|
|
37652
|
+
case LogicalTypeId::ENUM: {
|
|
37653
|
+
switch (type_.InternalType()) {
|
|
37654
|
+
case PhysicalType::UINT8:
|
|
37655
|
+
return Cast::Operation<uint8_t, T>(value_.utinyint);
|
|
37656
|
+
case PhysicalType::UINT16:
|
|
37657
|
+
return Cast::Operation<uint16_t, T>(value_.usmallint);
|
|
37658
|
+
case PhysicalType::UINT32:
|
|
37659
|
+
return Cast::Operation<uint32_t, T>(value_.uinteger);
|
|
37660
|
+
default:
|
|
37661
|
+
throw InternalException("Invalid Internal Type for ENUMs");
|
|
37662
|
+
}
|
|
37663
|
+
}
|
|
37664
|
+
|
|
37650
37665
|
default:
|
|
37651
37666
|
throw NotImplementedException("Unimplemented type \"%s\" for GetValue()", type_.ToString());
|
|
37652
37667
|
}
|
|
@@ -52678,6 +52693,149 @@ string PhysicalSimpleAggregate::ParamsToString() const {
|
|
|
52678
52693
|
|
|
52679
52694
|
|
|
52680
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
|
+
|
|
52681
52839
|
|
|
52682
52840
|
namespace duckdb {
|
|
52683
52841
|
|
|
@@ -68396,6 +68554,9 @@ unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalUpdate &op
|
|
|
68396
68554
|
|
|
68397
68555
|
|
|
68398
68556
|
|
|
68557
|
+
|
|
68558
|
+
|
|
68559
|
+
|
|
68399
68560
|
//===----------------------------------------------------------------------===//
|
|
68400
68561
|
// DuckDB
|
|
68401
68562
|
//
|
|
@@ -68429,12 +68590,28 @@ protected:
|
|
|
68429
68590
|
} // namespace duckdb
|
|
68430
68591
|
|
|
68431
68592
|
|
|
68432
|
-
|
|
68433
|
-
|
|
68434
68593
|
#include <numeric>
|
|
68435
68594
|
|
|
68436
68595
|
namespace duckdb {
|
|
68437
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
|
+
|
|
68438
68615
|
unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalWindow &op) {
|
|
68439
68616
|
D_ASSERT(op.children.size() == 1);
|
|
68440
68617
|
|
|
@@ -68450,11 +68627,23 @@ unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalWindow &op
|
|
|
68450
68627
|
const auto output_idx = types.size() - op.expressions.size();
|
|
68451
68628
|
types.resize(output_idx);
|
|
68452
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
|
+
|
|
68453
68641
|
// Process the window functions by sharing the partition/order definitions
|
|
68454
68642
|
vector<idx_t> evaluation_order;
|
|
68455
|
-
|
|
68456
|
-
|
|
68457
|
-
|
|
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
|
+
|
|
68458
68647
|
// Find all functions that share the partitioning of the first remaining expression
|
|
68459
68648
|
const auto over_idx = remaining[0];
|
|
68460
68649
|
auto over_expr = reinterpret_cast<BoundWindowExpression *>(op.expressions[over_idx].get());
|
|
@@ -68480,7 +68669,12 @@ unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalWindow &op
|
|
|
68480
68669
|
}
|
|
68481
68670
|
|
|
68482
68671
|
// Chain the new window operator on top of the plan
|
|
68483
|
-
|
|
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
|
+
}
|
|
68484
68678
|
window->children.push_back(move(plan));
|
|
68485
68679
|
plan = move(window);
|
|
68486
68680
|
|
|
@@ -77539,6 +77733,7 @@ void BuiltinFunctions::Initialize() {
|
|
|
77539
77733
|
RegisterRegressiveAggregates();
|
|
77540
77734
|
|
|
77541
77735
|
RegisterDateFunctions();
|
|
77736
|
+
RegisterEnumFunctions();
|
|
77542
77737
|
RegisterGenericFunctions();
|
|
77543
77738
|
RegisterMathFunctions();
|
|
77544
77739
|
RegisterOperators();
|
|
@@ -82043,6 +82238,163 @@ void BuiltinFunctions::RegisterDateFunctions() {
|
|
|
82043
82238
|
Register<ToIntervalFun>();
|
|
82044
82239
|
}
|
|
82045
82240
|
|
|
82241
|
+
} // namespace duckdb
|
|
82242
|
+
//===----------------------------------------------------------------------===//
|
|
82243
|
+
// DuckDB
|
|
82244
|
+
//
|
|
82245
|
+
// duckdb/function/scalar/enum_functions.hpp
|
|
82246
|
+
//
|
|
82247
|
+
//
|
|
82248
|
+
//===----------------------------------------------------------------------===//
|
|
82249
|
+
|
|
82250
|
+
|
|
82251
|
+
|
|
82252
|
+
|
|
82253
|
+
|
|
82254
|
+
|
|
82255
|
+
namespace duckdb {
|
|
82256
|
+
|
|
82257
|
+
struct EnumFirst {
|
|
82258
|
+
static void RegisterFunction(BuiltinFunctions &set);
|
|
82259
|
+
};
|
|
82260
|
+
|
|
82261
|
+
struct EnumLast {
|
|
82262
|
+
static void RegisterFunction(BuiltinFunctions &set);
|
|
82263
|
+
};
|
|
82264
|
+
|
|
82265
|
+
struct EnumRange {
|
|
82266
|
+
static void RegisterFunction(BuiltinFunctions &set);
|
|
82267
|
+
};
|
|
82268
|
+
|
|
82269
|
+
struct EnumRangeBoundary {
|
|
82270
|
+
static void RegisterFunction(BuiltinFunctions &set);
|
|
82271
|
+
};
|
|
82272
|
+
|
|
82273
|
+
} // namespace duckdb
|
|
82274
|
+
|
|
82275
|
+
|
|
82276
|
+
namespace duckdb {
|
|
82277
|
+
|
|
82278
|
+
static void EnumFirstFunction(DataChunk &input, ExpressionState &state, Vector &result) {
|
|
82279
|
+
D_ASSERT(input.GetTypes().size() == 1);
|
|
82280
|
+
auto &enum_vector = EnumType::GetValuesInsertOrder(input.GetTypes()[0]);
|
|
82281
|
+
auto val = Value(enum_vector.GetValue(0));
|
|
82282
|
+
result.Reference(val);
|
|
82283
|
+
}
|
|
82284
|
+
|
|
82285
|
+
static void EnumLastFunction(DataChunk &input, ExpressionState &state, Vector &result) {
|
|
82286
|
+
D_ASSERT(input.GetTypes().size() == 1);
|
|
82287
|
+
auto enum_size = EnumType::GetSize(input.GetTypes()[0]);
|
|
82288
|
+
auto &enum_vector = EnumType::GetValuesInsertOrder(input.GetTypes()[0]);
|
|
82289
|
+
auto val = Value(enum_vector.GetValue(enum_size - 1));
|
|
82290
|
+
result.Reference(val);
|
|
82291
|
+
}
|
|
82292
|
+
|
|
82293
|
+
static void EnumRangeFunction(DataChunk &input, ExpressionState &state, Vector &result) {
|
|
82294
|
+
D_ASSERT(input.GetTypes().size() == 1);
|
|
82295
|
+
auto enum_size = EnumType::GetSize(input.GetTypes()[0]);
|
|
82296
|
+
auto &enum_vector = EnumType::GetValuesInsertOrder(input.GetTypes()[0]);
|
|
82297
|
+
vector<Value> enum_values;
|
|
82298
|
+
for (idx_t i = 0; i < enum_size; i++) {
|
|
82299
|
+
enum_values.emplace_back(enum_vector.GetValue(i));
|
|
82300
|
+
}
|
|
82301
|
+
auto val = Value::LIST(enum_values);
|
|
82302
|
+
result.Reference(val);
|
|
82303
|
+
}
|
|
82304
|
+
|
|
82305
|
+
static void EnumRangeBoundaryFunction(DataChunk &input, ExpressionState &state, Vector &result) {
|
|
82306
|
+
D_ASSERT(input.GetTypes().size() == 2);
|
|
82307
|
+
idx_t start, end;
|
|
82308
|
+
auto first_param = input.GetValue(0, 0);
|
|
82309
|
+
auto second_param = input.GetValue(1, 0);
|
|
82310
|
+
|
|
82311
|
+
auto &enum_vector = first_param.is_null ? EnumType::GetValuesInsertOrder(input.GetTypes()[1])
|
|
82312
|
+
: EnumType::GetValuesInsertOrder(input.GetTypes()[0]);
|
|
82313
|
+
|
|
82314
|
+
if (first_param.is_null) {
|
|
82315
|
+
start = 0;
|
|
82316
|
+
} else {
|
|
82317
|
+
start = first_param.GetValue<uint32_t>();
|
|
82318
|
+
}
|
|
82319
|
+
if (second_param.is_null) {
|
|
82320
|
+
end = EnumType::GetSize(input.GetTypes()[0]);
|
|
82321
|
+
} else {
|
|
82322
|
+
end = second_param.GetValue<uint32_t>() + 1;
|
|
82323
|
+
}
|
|
82324
|
+
vector<Value> enum_values;
|
|
82325
|
+
for (idx_t i = start; i < end; i++) {
|
|
82326
|
+
enum_values.emplace_back(enum_vector.GetValue(i));
|
|
82327
|
+
}
|
|
82328
|
+
Value val;
|
|
82329
|
+
if (enum_values.empty()) {
|
|
82330
|
+
val = Value::EMPTYLIST(LogicalType::VARCHAR);
|
|
82331
|
+
} else {
|
|
82332
|
+
val = Value::LIST(enum_values);
|
|
82333
|
+
}
|
|
82334
|
+
result.Reference(val);
|
|
82335
|
+
}
|
|
82336
|
+
|
|
82337
|
+
unique_ptr<FunctionData> BindEnumFunction(ClientContext &context, ScalarFunction &bound_function,
|
|
82338
|
+
vector<unique_ptr<Expression>> &arguments) {
|
|
82339
|
+
if (arguments[0]->return_type.id() != LogicalTypeId::ENUM) {
|
|
82340
|
+
throw BinderException("This function needs an ENUM as an argument");
|
|
82341
|
+
}
|
|
82342
|
+
return nullptr;
|
|
82343
|
+
}
|
|
82344
|
+
|
|
82345
|
+
unique_ptr<FunctionData> BindEnumRangeBoundaryFunction(ClientContext &context, ScalarFunction &bound_function,
|
|
82346
|
+
vector<unique_ptr<Expression>> &arguments) {
|
|
82347
|
+
if (arguments[0]->return_type.id() != LogicalTypeId::ENUM && arguments[0]->return_type != LogicalType::SQLNULL) {
|
|
82348
|
+
throw BinderException("This function needs an ENUM as an argument");
|
|
82349
|
+
}
|
|
82350
|
+
if (arguments[1]->return_type.id() != LogicalTypeId::ENUM && arguments[1]->return_type != LogicalType::SQLNULL) {
|
|
82351
|
+
throw BinderException("This function needs an ENUM as an argument");
|
|
82352
|
+
}
|
|
82353
|
+
if (arguments[0]->return_type == LogicalType::SQLNULL && arguments[1]->return_type == LogicalType::SQLNULL) {
|
|
82354
|
+
throw BinderException("This function needs an ENUM as an argument");
|
|
82355
|
+
}
|
|
82356
|
+
if (arguments[0]->return_type.id() == LogicalTypeId::ENUM &&
|
|
82357
|
+
arguments[1]->return_type.id() == LogicalTypeId::ENUM &&
|
|
82358
|
+
arguments[0]->return_type != arguments[1]->return_type) {
|
|
82359
|
+
|
|
82360
|
+
throw BinderException("The parameters need to link to ONLY one enum OR be NULL ");
|
|
82361
|
+
}
|
|
82362
|
+
return nullptr;
|
|
82363
|
+
}
|
|
82364
|
+
|
|
82365
|
+
void EnumFirst::RegisterFunction(BuiltinFunctions &set) {
|
|
82366
|
+
set.AddFunction(ScalarFunction("enum_first", {LogicalType::ANY}, LogicalType::VARCHAR, EnumFirstFunction, false,
|
|
82367
|
+
BindEnumFunction));
|
|
82368
|
+
}
|
|
82369
|
+
|
|
82370
|
+
void EnumLast::RegisterFunction(BuiltinFunctions &set) {
|
|
82371
|
+
set.AddFunction(ScalarFunction("enum_last", {LogicalType::ANY}, LogicalType::VARCHAR, EnumLastFunction, false,
|
|
82372
|
+
BindEnumFunction));
|
|
82373
|
+
}
|
|
82374
|
+
|
|
82375
|
+
void EnumRange::RegisterFunction(BuiltinFunctions &set) {
|
|
82376
|
+
set.AddFunction(ScalarFunction("enum_range", {LogicalType::ANY}, LogicalType::LIST(LogicalType::VARCHAR),
|
|
82377
|
+
EnumRangeFunction, false, BindEnumFunction));
|
|
82378
|
+
}
|
|
82379
|
+
|
|
82380
|
+
void EnumRangeBoundary::RegisterFunction(BuiltinFunctions &set) {
|
|
82381
|
+
set.AddFunction(ScalarFunction("enum_range_boundary", {LogicalType::ANY, LogicalType::ANY},
|
|
82382
|
+
LogicalType::LIST(LogicalType::VARCHAR), EnumRangeBoundaryFunction, false,
|
|
82383
|
+
BindEnumRangeBoundaryFunction));
|
|
82384
|
+
}
|
|
82385
|
+
|
|
82386
|
+
} // namespace duckdb
|
|
82387
|
+
|
|
82388
|
+
|
|
82389
|
+
namespace duckdb {
|
|
82390
|
+
|
|
82391
|
+
void BuiltinFunctions::RegisterEnumFunctions() {
|
|
82392
|
+
Register<EnumFirst>();
|
|
82393
|
+
Register<EnumLast>();
|
|
82394
|
+
Register<EnumRange>();
|
|
82395
|
+
Register<EnumRangeBoundary>();
|
|
82396
|
+
}
|
|
82397
|
+
|
|
82046
82398
|
} // namespace duckdb
|
|
82047
82399
|
//===----------------------------------------------------------------------===//
|
|
82048
82400
|
// DuckDB
|
|
@@ -145303,8 +145655,10 @@ BindResult ExpressionBinder::BindExpression(BetweenExpression &expr, idx_t depth
|
|
|
145303
145655
|
lower.expr = PushCollation(context, move(lower.expr), collation, false);
|
|
145304
145656
|
upper.expr = PushCollation(context, move(upper.expr), collation, false);
|
|
145305
145657
|
}
|
|
145306
|
-
if (!input.expr->HasSideEffects() && !input.expr->HasParameter()) {
|
|
145307
|
-
// the expression does not have side effects: create two comparisons
|
|
145658
|
+
if (!input.expr->HasSideEffects() && !input.expr->HasParameter() && !input.expr->HasSubquery()) {
|
|
145659
|
+
// the expression does not have side effects and can be copied: create two comparisons
|
|
145660
|
+
// the reason we do this is that individual comparisons are easier to handle in optimizers
|
|
145661
|
+
// if both comparisons remain they will be folded together again into a single BETWEEN in the optimizer
|
|
145308
145662
|
auto left_compare = make_unique<BoundComparisonExpression>(ExpressionType::COMPARE_GREATERTHANOREQUALTO,
|
|
145309
145663
|
input.expr->Copy(), move(lower.expr));
|
|
145310
145664
|
auto right_compare = make_unique<BoundComparisonExpression>(ExpressionType::COMPARE_LESSTHANOREQUALTO,
|
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
|
|
|
@@ -5742,6 +5742,7 @@ private:
|
|
|
5742
5742
|
|
|
5743
5743
|
// scalar functions
|
|
5744
5744
|
void RegisterDateFunctions();
|
|
5745
|
+
void RegisterEnumFunctions();
|
|
5745
5746
|
void RegisterGenericFunctions();
|
|
5746
5747
|
void RegisterMathFunctions();
|
|
5747
5748
|
void RegisterOperators();
|
|
@@ -9186,6 +9187,7 @@ enum class PhysicalOperatorType : uint8_t {
|
|
|
9186
9187
|
COPY_TO_FILE,
|
|
9187
9188
|
RESERVOIR_SAMPLE,
|
|
9188
9189
|
STREAMING_SAMPLE,
|
|
9190
|
+
STREAMING_WINDOW,
|
|
9189
9191
|
// -----------------------------
|
|
9190
9192
|
// Scans
|
|
9191
9193
|
// -----------------------------
|