duckdb 0.3.2-dev656.0 → 0.3.2-dev668.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 +212 -26
- package/src/duckdb.hpp +3 -2
package/package.json
CHANGED
package/src/duckdb.cpp
CHANGED
|
@@ -24915,8 +24915,8 @@ static void GatherNestedVector(Vector &rows, const SelectionVector &row_sel, Vec
|
|
|
24915
24915
|
auto ptrs = FlatVector::GetData<data_ptr_t>(rows);
|
|
24916
24916
|
|
|
24917
24917
|
// Build the gather locations
|
|
24918
|
-
|
|
24919
|
-
|
|
24918
|
+
auto data_locations = unique_ptr<data_ptr_t[]>(new data_ptr_t[count]);
|
|
24919
|
+
auto mask_locations = unique_ptr<data_ptr_t[]>(new data_ptr_t[count]);
|
|
24920
24920
|
for (idx_t i = 0; i < count; i++) {
|
|
24921
24921
|
auto row_idx = row_sel.get_index(i);
|
|
24922
24922
|
mask_locations[i] = ptrs[row_idx];
|
|
@@ -24924,7 +24924,7 @@ static void GatherNestedVector(Vector &rows, const SelectionVector &row_sel, Vec
|
|
|
24924
24924
|
}
|
|
24925
24925
|
|
|
24926
24926
|
// Deserialise into the selected locations
|
|
24927
|
-
RowOperations::HeapGather(col, count, col_sel, col_no, data_locations, mask_locations);
|
|
24927
|
+
RowOperations::HeapGather(col, count, col_sel, col_no, data_locations.get(), mask_locations.get());
|
|
24928
24928
|
}
|
|
24929
24929
|
|
|
24930
24930
|
void RowOperations::Gather(Vector &rows, const SelectionVector &row_sel, Vector &col, const SelectionVector &col_sel,
|
|
@@ -37647,6 +37647,19 @@ T Value::GetValueInternal() const {
|
|
|
37647
37647
|
return Cast::Operation<interval_t, T>(value_.interval);
|
|
37648
37648
|
case LogicalTypeId::DECIMAL:
|
|
37649
37649
|
return CastAs(LogicalType::DOUBLE).GetValueInternal<T>();
|
|
37650
|
+
case LogicalTypeId::ENUM: {
|
|
37651
|
+
switch (type_.InternalType()) {
|
|
37652
|
+
case PhysicalType::UINT8:
|
|
37653
|
+
return Cast::Operation<uint8_t, T>(value_.utinyint);
|
|
37654
|
+
case PhysicalType::UINT16:
|
|
37655
|
+
return Cast::Operation<uint16_t, T>(value_.usmallint);
|
|
37656
|
+
case PhysicalType::UINT32:
|
|
37657
|
+
return Cast::Operation<uint32_t, T>(value_.uinteger);
|
|
37658
|
+
default:
|
|
37659
|
+
throw InternalException("Invalid Internal Type for ENUMs");
|
|
37660
|
+
}
|
|
37661
|
+
}
|
|
37662
|
+
|
|
37650
37663
|
default:
|
|
37651
37664
|
throw NotImplementedException("Unimplemented type \"%s\" for GetValue()", type_.ToString());
|
|
37652
37665
|
}
|
|
@@ -65497,6 +65510,7 @@ unique_ptr<PhysicalOperator> PhysicalPlanGenerator::CreatePlan(LogicalChunkGet &
|
|
|
65497
65510
|
|
|
65498
65511
|
|
|
65499
65512
|
|
|
65513
|
+
|
|
65500
65514
|
namespace duckdb {
|
|
65501
65515
|
|
|
65502
65516
|
static bool CanPlanIndexJoin(Transaction &transaction, TableScanBindData *bind_data, PhysicalTableScan &scan) {
|
|
@@ -65516,6 +65530,30 @@ static bool CanPlanIndexJoin(Transaction &transaction, TableScanBindData *bind_d
|
|
|
65516
65530
|
return true;
|
|
65517
65531
|
}
|
|
65518
65532
|
|
|
65533
|
+
bool ExtractNumericValue(Value val, int64_t &result) {
|
|
65534
|
+
if (!val.type().IsIntegral()) {
|
|
65535
|
+
switch (val.type().InternalType()) {
|
|
65536
|
+
case PhysicalType::INT16:
|
|
65537
|
+
result = val.GetValueUnsafe<int16_t>();
|
|
65538
|
+
break;
|
|
65539
|
+
case PhysicalType::INT32:
|
|
65540
|
+
result = val.GetValueUnsafe<int32_t>();
|
|
65541
|
+
break;
|
|
65542
|
+
case PhysicalType::INT64:
|
|
65543
|
+
result = val.GetValueUnsafe<int64_t>();
|
|
65544
|
+
break;
|
|
65545
|
+
default:
|
|
65546
|
+
return false;
|
|
65547
|
+
}
|
|
65548
|
+
} else {
|
|
65549
|
+
if (!val.TryCastAs(LogicalType::BIGINT)) {
|
|
65550
|
+
return false;
|
|
65551
|
+
}
|
|
65552
|
+
result = val.GetValue<int64_t>();
|
|
65553
|
+
}
|
|
65554
|
+
return true;
|
|
65555
|
+
}
|
|
65556
|
+
|
|
65519
65557
|
void CheckForPerfectJoinOpt(LogicalComparisonJoin &op, PerfectHashJoinStats &join_state) {
|
|
65520
65558
|
// we only do this optimization for inner joins
|
|
65521
65559
|
if (op.join_type != JoinType::INNER) {
|
|
@@ -65548,7 +65586,14 @@ void CheckForPerfectJoinOpt(LogicalComparisonJoin &op, PerfectHashJoinStats &joi
|
|
|
65548
65586
|
if (stats_build->min.is_null || stats_build->max.is_null) {
|
|
65549
65587
|
return;
|
|
65550
65588
|
}
|
|
65551
|
-
|
|
65589
|
+
int64_t min_value, max_value;
|
|
65590
|
+
if (!ExtractNumericValue(stats_build->min, min_value) || !ExtractNumericValue(stats_build->max, max_value)) {
|
|
65591
|
+
return;
|
|
65592
|
+
}
|
|
65593
|
+
int64_t build_range;
|
|
65594
|
+
if (!TrySubtractOperator::Operation(max_value, min_value, build_range)) {
|
|
65595
|
+
return;
|
|
65596
|
+
}
|
|
65552
65597
|
|
|
65553
65598
|
// Fill join_stats for invisible join
|
|
65554
65599
|
auto stats_probe = reinterpret_cast<NumericStatistics *>(op.join_stats[1].get()); // rhs stats
|
|
@@ -65560,26 +65605,7 @@ void CheckForPerfectJoinOpt(LogicalComparisonJoin &op, PerfectHashJoinStats &joi
|
|
|
65560
65605
|
join_state.build_min = stats_build->min;
|
|
65561
65606
|
join_state.build_max = stats_build->max;
|
|
65562
65607
|
join_state.estimated_cardinality = op.estimated_cardinality;
|
|
65563
|
-
|
|
65564
|
-
switch (build_range.type().InternalType()) {
|
|
65565
|
-
case PhysicalType::INT16:
|
|
65566
|
-
join_state.build_range = build_range.value_.smallint;
|
|
65567
|
-
break;
|
|
65568
|
-
case PhysicalType::INT32:
|
|
65569
|
-
join_state.build_range = build_range.value_.integer;
|
|
65570
|
-
break;
|
|
65571
|
-
case PhysicalType::INT64:
|
|
65572
|
-
join_state.build_range = build_range.value_.bigint;
|
|
65573
|
-
break;
|
|
65574
|
-
case PhysicalType::INT128:
|
|
65575
|
-
// we do not support hugeint for this optimization
|
|
65576
|
-
return;
|
|
65577
|
-
default:
|
|
65578
|
-
throw InternalException("Invalid Physical Type for Decimals");
|
|
65579
|
-
}
|
|
65580
|
-
} else {
|
|
65581
|
-
join_state.build_range = build_range.GetValue<idx_t>(); // cast integer types into idx_t
|
|
65582
|
-
}
|
|
65608
|
+
join_state.build_range = build_range;
|
|
65583
65609
|
if (join_state.build_range > MAX_BUILD_SIZE || stats_probe->max.is_null || stats_probe->min.is_null) {
|
|
65584
65610
|
return;
|
|
65585
65611
|
}
|
|
@@ -77526,6 +77552,7 @@ void BuiltinFunctions::Initialize() {
|
|
|
77526
77552
|
RegisterRegressiveAggregates();
|
|
77527
77553
|
|
|
77528
77554
|
RegisterDateFunctions();
|
|
77555
|
+
RegisterEnumFunctions();
|
|
77529
77556
|
RegisterGenericFunctions();
|
|
77530
77557
|
RegisterMathFunctions();
|
|
77531
77558
|
RegisterOperators();
|
|
@@ -82030,6 +82057,163 @@ void BuiltinFunctions::RegisterDateFunctions() {
|
|
|
82030
82057
|
Register<ToIntervalFun>();
|
|
82031
82058
|
}
|
|
82032
82059
|
|
|
82060
|
+
} // namespace duckdb
|
|
82061
|
+
//===----------------------------------------------------------------------===//
|
|
82062
|
+
// DuckDB
|
|
82063
|
+
//
|
|
82064
|
+
// duckdb/function/scalar/enum_functions.hpp
|
|
82065
|
+
//
|
|
82066
|
+
//
|
|
82067
|
+
//===----------------------------------------------------------------------===//
|
|
82068
|
+
|
|
82069
|
+
|
|
82070
|
+
|
|
82071
|
+
|
|
82072
|
+
|
|
82073
|
+
|
|
82074
|
+
namespace duckdb {
|
|
82075
|
+
|
|
82076
|
+
struct EnumFirst {
|
|
82077
|
+
static void RegisterFunction(BuiltinFunctions &set);
|
|
82078
|
+
};
|
|
82079
|
+
|
|
82080
|
+
struct EnumLast {
|
|
82081
|
+
static void RegisterFunction(BuiltinFunctions &set);
|
|
82082
|
+
};
|
|
82083
|
+
|
|
82084
|
+
struct EnumRange {
|
|
82085
|
+
static void RegisterFunction(BuiltinFunctions &set);
|
|
82086
|
+
};
|
|
82087
|
+
|
|
82088
|
+
struct EnumRangeBoundary {
|
|
82089
|
+
static void RegisterFunction(BuiltinFunctions &set);
|
|
82090
|
+
};
|
|
82091
|
+
|
|
82092
|
+
} // namespace duckdb
|
|
82093
|
+
|
|
82094
|
+
|
|
82095
|
+
namespace duckdb {
|
|
82096
|
+
|
|
82097
|
+
static void EnumFirstFunction(DataChunk &input, ExpressionState &state, Vector &result) {
|
|
82098
|
+
D_ASSERT(input.GetTypes().size() == 1);
|
|
82099
|
+
auto &enum_vector = EnumType::GetValuesInsertOrder(input.GetTypes()[0]);
|
|
82100
|
+
auto val = Value(enum_vector.GetValue(0));
|
|
82101
|
+
result.Reference(val);
|
|
82102
|
+
}
|
|
82103
|
+
|
|
82104
|
+
static void EnumLastFunction(DataChunk &input, ExpressionState &state, Vector &result) {
|
|
82105
|
+
D_ASSERT(input.GetTypes().size() == 1);
|
|
82106
|
+
auto enum_size = EnumType::GetSize(input.GetTypes()[0]);
|
|
82107
|
+
auto &enum_vector = EnumType::GetValuesInsertOrder(input.GetTypes()[0]);
|
|
82108
|
+
auto val = Value(enum_vector.GetValue(enum_size - 1));
|
|
82109
|
+
result.Reference(val);
|
|
82110
|
+
}
|
|
82111
|
+
|
|
82112
|
+
static void EnumRangeFunction(DataChunk &input, ExpressionState &state, Vector &result) {
|
|
82113
|
+
D_ASSERT(input.GetTypes().size() == 1);
|
|
82114
|
+
auto enum_size = EnumType::GetSize(input.GetTypes()[0]);
|
|
82115
|
+
auto &enum_vector = EnumType::GetValuesInsertOrder(input.GetTypes()[0]);
|
|
82116
|
+
vector<Value> enum_values;
|
|
82117
|
+
for (idx_t i = 0; i < enum_size; i++) {
|
|
82118
|
+
enum_values.emplace_back(enum_vector.GetValue(i));
|
|
82119
|
+
}
|
|
82120
|
+
auto val = Value::LIST(enum_values);
|
|
82121
|
+
result.Reference(val);
|
|
82122
|
+
}
|
|
82123
|
+
|
|
82124
|
+
static void EnumRangeBoundaryFunction(DataChunk &input, ExpressionState &state, Vector &result) {
|
|
82125
|
+
D_ASSERT(input.GetTypes().size() == 2);
|
|
82126
|
+
idx_t start, end;
|
|
82127
|
+
auto first_param = input.GetValue(0, 0);
|
|
82128
|
+
auto second_param = input.GetValue(1, 0);
|
|
82129
|
+
|
|
82130
|
+
auto &enum_vector = first_param.is_null ? EnumType::GetValuesInsertOrder(input.GetTypes()[1])
|
|
82131
|
+
: EnumType::GetValuesInsertOrder(input.GetTypes()[0]);
|
|
82132
|
+
|
|
82133
|
+
if (first_param.is_null) {
|
|
82134
|
+
start = 0;
|
|
82135
|
+
} else {
|
|
82136
|
+
start = first_param.GetValue<uint32_t>();
|
|
82137
|
+
}
|
|
82138
|
+
if (second_param.is_null) {
|
|
82139
|
+
end = EnumType::GetSize(input.GetTypes()[0]);
|
|
82140
|
+
} else {
|
|
82141
|
+
end = second_param.GetValue<uint32_t>() + 1;
|
|
82142
|
+
}
|
|
82143
|
+
vector<Value> enum_values;
|
|
82144
|
+
for (idx_t i = start; i < end; i++) {
|
|
82145
|
+
enum_values.emplace_back(enum_vector.GetValue(i));
|
|
82146
|
+
}
|
|
82147
|
+
Value val;
|
|
82148
|
+
if (enum_values.empty()) {
|
|
82149
|
+
val = Value::EMPTYLIST(LogicalType::VARCHAR);
|
|
82150
|
+
} else {
|
|
82151
|
+
val = Value::LIST(enum_values);
|
|
82152
|
+
}
|
|
82153
|
+
result.Reference(val);
|
|
82154
|
+
}
|
|
82155
|
+
|
|
82156
|
+
unique_ptr<FunctionData> BindEnumFunction(ClientContext &context, ScalarFunction &bound_function,
|
|
82157
|
+
vector<unique_ptr<Expression>> &arguments) {
|
|
82158
|
+
if (arguments[0]->return_type.id() != LogicalTypeId::ENUM) {
|
|
82159
|
+
throw BinderException("This function needs an ENUM as an argument");
|
|
82160
|
+
}
|
|
82161
|
+
return nullptr;
|
|
82162
|
+
}
|
|
82163
|
+
|
|
82164
|
+
unique_ptr<FunctionData> BindEnumRangeBoundaryFunction(ClientContext &context, ScalarFunction &bound_function,
|
|
82165
|
+
vector<unique_ptr<Expression>> &arguments) {
|
|
82166
|
+
if (arguments[0]->return_type.id() != LogicalTypeId::ENUM && arguments[0]->return_type != LogicalType::SQLNULL) {
|
|
82167
|
+
throw BinderException("This function needs an ENUM as an argument");
|
|
82168
|
+
}
|
|
82169
|
+
if (arguments[1]->return_type.id() != LogicalTypeId::ENUM && arguments[1]->return_type != LogicalType::SQLNULL) {
|
|
82170
|
+
throw BinderException("This function needs an ENUM as an argument");
|
|
82171
|
+
}
|
|
82172
|
+
if (arguments[0]->return_type == LogicalType::SQLNULL && arguments[1]->return_type == LogicalType::SQLNULL) {
|
|
82173
|
+
throw BinderException("This function needs an ENUM as an argument");
|
|
82174
|
+
}
|
|
82175
|
+
if (arguments[0]->return_type.id() == LogicalTypeId::ENUM &&
|
|
82176
|
+
arguments[1]->return_type.id() == LogicalTypeId::ENUM &&
|
|
82177
|
+
arguments[0]->return_type != arguments[1]->return_type) {
|
|
82178
|
+
|
|
82179
|
+
throw BinderException("The parameters need to link to ONLY one enum OR be NULL ");
|
|
82180
|
+
}
|
|
82181
|
+
return nullptr;
|
|
82182
|
+
}
|
|
82183
|
+
|
|
82184
|
+
void EnumFirst::RegisterFunction(BuiltinFunctions &set) {
|
|
82185
|
+
set.AddFunction(ScalarFunction("enum_first", {LogicalType::ANY}, LogicalType::VARCHAR, EnumFirstFunction, false,
|
|
82186
|
+
BindEnumFunction));
|
|
82187
|
+
}
|
|
82188
|
+
|
|
82189
|
+
void EnumLast::RegisterFunction(BuiltinFunctions &set) {
|
|
82190
|
+
set.AddFunction(ScalarFunction("enum_last", {LogicalType::ANY}, LogicalType::VARCHAR, EnumLastFunction, false,
|
|
82191
|
+
BindEnumFunction));
|
|
82192
|
+
}
|
|
82193
|
+
|
|
82194
|
+
void EnumRange::RegisterFunction(BuiltinFunctions &set) {
|
|
82195
|
+
set.AddFunction(ScalarFunction("enum_range", {LogicalType::ANY}, LogicalType::LIST(LogicalType::VARCHAR),
|
|
82196
|
+
EnumRangeFunction, false, BindEnumFunction));
|
|
82197
|
+
}
|
|
82198
|
+
|
|
82199
|
+
void EnumRangeBoundary::RegisterFunction(BuiltinFunctions &set) {
|
|
82200
|
+
set.AddFunction(ScalarFunction("enum_range_boundary", {LogicalType::ANY, LogicalType::ANY},
|
|
82201
|
+
LogicalType::LIST(LogicalType::VARCHAR), EnumRangeBoundaryFunction, false,
|
|
82202
|
+
BindEnumRangeBoundaryFunction));
|
|
82203
|
+
}
|
|
82204
|
+
|
|
82205
|
+
} // namespace duckdb
|
|
82206
|
+
|
|
82207
|
+
|
|
82208
|
+
namespace duckdb {
|
|
82209
|
+
|
|
82210
|
+
void BuiltinFunctions::RegisterEnumFunctions() {
|
|
82211
|
+
Register<EnumFirst>();
|
|
82212
|
+
Register<EnumLast>();
|
|
82213
|
+
Register<EnumRange>();
|
|
82214
|
+
Register<EnumRangeBoundary>();
|
|
82215
|
+
}
|
|
82216
|
+
|
|
82033
82217
|
} // namespace duckdb
|
|
82034
82218
|
//===----------------------------------------------------------------------===//
|
|
82035
82219
|
// DuckDB
|
|
@@ -145290,8 +145474,10 @@ BindResult ExpressionBinder::BindExpression(BetweenExpression &expr, idx_t depth
|
|
|
145290
145474
|
lower.expr = PushCollation(context, move(lower.expr), collation, false);
|
|
145291
145475
|
upper.expr = PushCollation(context, move(upper.expr), collation, false);
|
|
145292
145476
|
}
|
|
145293
|
-
if (!input.expr->HasSideEffects() && !input.expr->HasParameter()) {
|
|
145294
|
-
// the expression does not have side effects: create two comparisons
|
|
145477
|
+
if (!input.expr->HasSideEffects() && !input.expr->HasParameter() && !input.expr->HasSubquery()) {
|
|
145478
|
+
// the expression does not have side effects and can be copied: create two comparisons
|
|
145479
|
+
// the reason we do this is that individual comparisons are easier to handle in optimizers
|
|
145480
|
+
// if both comparisons remain they will be folded together again into a single BETWEEN in the optimizer
|
|
145295
145481
|
auto left_compare = make_unique<BoundComparisonExpression>(ExpressionType::COMPARE_GREATERTHANOREQUALTO,
|
|
145296
145482
|
input.expr->Copy(), move(lower.expr));
|
|
145297
145483
|
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 "a5e6d9bd4"
|
|
14
|
+
#define DUCKDB_VERSION "0.3.2-dev668"
|
|
15
15
|
//===----------------------------------------------------------------------===//
|
|
16
16
|
// DuckDB
|
|
17
17
|
//
|
|
@@ -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();
|