duckdb 0.3.1-dev317.0 → 0.3.1-dev332.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 +128 -43
- package/src/duckdb.hpp +2 -2
package/package.json
CHANGED
package/src/duckdb.cpp
CHANGED
|
@@ -1028,10 +1028,12 @@ public:
|
|
|
1028
1028
|
static void ResolveParameterType(LogicalType &type);
|
|
1029
1029
|
static void ResolveParameterType(unique_ptr<Expression> &expr);
|
|
1030
1030
|
|
|
1031
|
-
|
|
1031
|
+
//! Bind the given expresion. Unlike Bind(), this does *not* mute the given ParsedExpression.
|
|
1032
|
+
//! Exposed to be used from sub-binders that aren't subclasses of ExpressionBinder.
|
|
1032
1033
|
virtual BindResult BindExpression(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth,
|
|
1033
1034
|
bool root_expression = false);
|
|
1034
1035
|
|
|
1036
|
+
protected:
|
|
1035
1037
|
BindResult BindExpression(BetweenExpression &expr, idx_t depth);
|
|
1036
1038
|
BindResult BindExpression(CaseExpression &expr, idx_t depth);
|
|
1037
1039
|
BindResult BindExpression(CollateExpression &expr, idx_t depth);
|
|
@@ -1331,6 +1333,7 @@ public:
|
|
|
1331
1333
|
|
|
1332
1334
|
namespace duckdb {
|
|
1333
1335
|
class BoundResultModifier;
|
|
1336
|
+
class BoundSelectNode;
|
|
1334
1337
|
class ClientContext;
|
|
1335
1338
|
class ExpressionBinder;
|
|
1336
1339
|
class LimitModifier;
|
|
@@ -1544,7 +1547,6 @@ private:
|
|
|
1544
1547
|
|
|
1545
1548
|
BoundStatement BindSummarize(ShowStatement &stmt);
|
|
1546
1549
|
unique_ptr<BoundResultModifier> BindLimit(LimitModifier &limit_mod);
|
|
1547
|
-
unique_ptr<Expression> BindFilter(unique_ptr<ParsedExpression> condition);
|
|
1548
1550
|
unique_ptr<Expression> BindOrderExpression(OrderBinder &order_binder, unique_ptr<ParsedExpression> expr);
|
|
1549
1551
|
|
|
1550
1552
|
unique_ptr<LogicalOperator> PlanFilter(unique_ptr<Expression> condition, unique_ptr<LogicalOperator> root);
|
|
@@ -58190,10 +58192,8 @@ SinkFinalizeType PhysicalHashJoin::Finalize(Pipeline &pipeline, Event &event, Cl
|
|
|
58190
58192
|
D_ASSERT(sink.hash_table->equality_types.size() == 1);
|
|
58191
58193
|
auto key_type = sink.hash_table->equality_types[0];
|
|
58192
58194
|
use_perfect_hash = sink.perfect_join_executor->BuildPerfectHashTable(key_type);
|
|
58193
|
-
} else {
|
|
58194
|
-
sink.perfect_join_executor.reset();
|
|
58195
58195
|
}
|
|
58196
|
-
// In case large build side or duplicates, use regular hash join
|
|
58196
|
+
// In case of a large build side or duplicates, use regular hash join
|
|
58197
58197
|
if (!use_perfect_hash) {
|
|
58198
58198
|
sink.perfect_join_executor.reset();
|
|
58199
58199
|
sink.hash_table->Finalize();
|
|
@@ -66465,7 +66465,7 @@ void CheckForPerfectJoinOpt(LogicalComparisonJoin &op, PerfectHashJoinStats &joi
|
|
|
66465
66465
|
return;
|
|
66466
66466
|
}
|
|
66467
66467
|
}
|
|
66468
|
-
// with integral types
|
|
66468
|
+
// with integral internal types
|
|
66469
66469
|
for (auto &&join_stat : op.join_stats) {
|
|
66470
66470
|
if (!TypeIsInteger(join_stat->type.InternalType()) || join_stat->type.InternalType() == PhysicalType::INT128) {
|
|
66471
66471
|
// perfect join not possible for non-integral types or hugeint
|
|
@@ -66490,7 +66490,7 @@ void CheckForPerfectJoinOpt(LogicalComparisonJoin &op, PerfectHashJoinStats &joi
|
|
|
66490
66490
|
join_state.build_min = stats_build->min;
|
|
66491
66491
|
join_state.build_max = stats_build->max;
|
|
66492
66492
|
join_state.estimated_cardinality = op.estimated_cardinality;
|
|
66493
|
-
if (build_range.type().
|
|
66493
|
+
if (!build_range.type().IsIntegral()) {
|
|
66494
66494
|
switch (build_range.type().InternalType()) {
|
|
66495
66495
|
case PhysicalType::INT16:
|
|
66496
66496
|
join_state.build_range = build_range.value_.smallint;
|
|
@@ -66502,19 +66502,15 @@ void CheckForPerfectJoinOpt(LogicalComparisonJoin &op, PerfectHashJoinStats &joi
|
|
|
66502
66502
|
join_state.build_range = build_range.value_.bigint;
|
|
66503
66503
|
break;
|
|
66504
66504
|
case PhysicalType::INT128:
|
|
66505
|
-
|
|
66506
|
-
|
|
66507
|
-
// break;
|
|
66505
|
+
// we do not support hugeint for this optimization
|
|
66506
|
+
return;
|
|
66508
66507
|
default:
|
|
66509
66508
|
throw InternalException("Invalid Physical Type for Decimals");
|
|
66510
66509
|
}
|
|
66511
66510
|
} else {
|
|
66512
66511
|
join_state.build_range = build_range.GetValue<idx_t>(); // cast integer types into idx_t
|
|
66513
66512
|
}
|
|
66514
|
-
if (join_state.build_range > MAX_BUILD_SIZE) {
|
|
66515
|
-
return;
|
|
66516
|
-
}
|
|
66517
|
-
if (stats_probe->max.is_null || stats_probe->min.is_null) {
|
|
66513
|
+
if (join_state.build_range > MAX_BUILD_SIZE || stats_probe->max.is_null || stats_probe->min.is_null) {
|
|
66518
66514
|
return;
|
|
66519
66515
|
}
|
|
66520
66516
|
if (stats_build->min <= stats_probe->min && stats_probe->max <= stats_build->max) {
|
|
@@ -136027,6 +136023,40 @@ unique_ptr<BoundQueryNode> Binder::BindNode(RecursiveCTENode &statement) {
|
|
|
136027
136023
|
|
|
136028
136024
|
|
|
136029
136025
|
|
|
136026
|
+
//===----------------------------------------------------------------------===//
|
|
136027
|
+
// DuckDB
|
|
136028
|
+
//
|
|
136029
|
+
// duckdb/planner/expression_binder/column_alias_binder.hpp
|
|
136030
|
+
//
|
|
136031
|
+
//
|
|
136032
|
+
//===----------------------------------------------------------------------===//
|
|
136033
|
+
|
|
136034
|
+
|
|
136035
|
+
|
|
136036
|
+
|
|
136037
|
+
|
|
136038
|
+
|
|
136039
|
+
namespace duckdb {
|
|
136040
|
+
|
|
136041
|
+
class BoundSelectNode;
|
|
136042
|
+
class ColumnRefExpression;
|
|
136043
|
+
|
|
136044
|
+
//! A helper binder for WhereBinder and HavingBinder which support alias as a columnref.
|
|
136045
|
+
class ColumnAliasBinder {
|
|
136046
|
+
public:
|
|
136047
|
+
ColumnAliasBinder(BoundSelectNode &node, const unordered_map<string, idx_t> &alias_map);
|
|
136048
|
+
|
|
136049
|
+
BindResult BindAlias(ExpressionBinder &enclosing_binder, ColumnRefExpression &expr, idx_t depth,
|
|
136050
|
+
bool root_expression);
|
|
136051
|
+
|
|
136052
|
+
private:
|
|
136053
|
+
BoundSelectNode &node;
|
|
136054
|
+
const unordered_map<string, idx_t> &alias_map;
|
|
136055
|
+
bool in_alias;
|
|
136056
|
+
};
|
|
136057
|
+
|
|
136058
|
+
} // namespace duckdb
|
|
136059
|
+
|
|
136030
136060
|
//===----------------------------------------------------------------------===//
|
|
136031
136061
|
// DuckDB
|
|
136032
136062
|
//
|
|
@@ -136117,6 +136147,7 @@ protected:
|
|
|
136117
136147
|
|
|
136118
136148
|
|
|
136119
136149
|
|
|
136150
|
+
|
|
136120
136151
|
namespace duckdb {
|
|
136121
136152
|
|
|
136122
136153
|
//! The HAVING binder is responsible for binding an expression within the HAVING clause of a SQL statement
|
|
@@ -136125,12 +136156,14 @@ public:
|
|
|
136125
136156
|
HavingBinder(Binder &binder, ClientContext &context, BoundSelectNode &node, BoundGroupInformation &info,
|
|
136126
136157
|
unordered_map<string, idx_t> &alias_map);
|
|
136127
136158
|
|
|
136128
|
-
unordered_map<string, idx_t> &alias_map;
|
|
136129
|
-
bool in_alias;
|
|
136130
|
-
|
|
136131
136159
|
protected:
|
|
136132
136160
|
BindResult BindExpression(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth,
|
|
136133
136161
|
bool root_expression = false) override;
|
|
136162
|
+
|
|
136163
|
+
private:
|
|
136164
|
+
BindResult BindColumnRef(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth, bool root_expression);
|
|
136165
|
+
|
|
136166
|
+
ColumnAliasBinder column_alias_binder;
|
|
136134
136167
|
};
|
|
136135
136168
|
|
|
136136
136169
|
} // namespace duckdb
|
|
@@ -136193,16 +136226,23 @@ private:
|
|
|
136193
136226
|
|
|
136194
136227
|
namespace duckdb {
|
|
136195
136228
|
|
|
136229
|
+
class ColumnAliasBinder;
|
|
136230
|
+
|
|
136196
136231
|
//! The WHERE binder is responsible for binding an expression within the WHERE clause of a SQL statement
|
|
136197
136232
|
class WhereBinder : public ExpressionBinder {
|
|
136198
136233
|
public:
|
|
136199
|
-
WhereBinder(Binder &binder, ClientContext &context);
|
|
136234
|
+
WhereBinder(Binder &binder, ClientContext &context, ColumnAliasBinder *column_alias_binder = nullptr);
|
|
136200
136235
|
|
|
136201
136236
|
protected:
|
|
136202
136237
|
BindResult BindExpression(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth,
|
|
136203
136238
|
bool root_expression = false) override;
|
|
136204
136239
|
|
|
136205
136240
|
string UnsupportedAggregateMessage() override;
|
|
136241
|
+
|
|
136242
|
+
private:
|
|
136243
|
+
BindResult BindColumnRef(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth, bool root_expression);
|
|
136244
|
+
|
|
136245
|
+
ColumnAliasBinder *column_alias_binder;
|
|
136206
136246
|
};
|
|
136207
136247
|
|
|
136208
136248
|
} // namespace duckdb
|
|
@@ -136211,10 +136251,6 @@ protected:
|
|
|
136211
136251
|
|
|
136212
136252
|
|
|
136213
136253
|
namespace duckdb {
|
|
136214
|
-
unique_ptr<Expression> Binder::BindFilter(unique_ptr<ParsedExpression> condition) {
|
|
136215
|
-
WhereBinder where_binder(*this, context);
|
|
136216
|
-
return where_binder.Bind(condition);
|
|
136217
|
-
}
|
|
136218
136254
|
|
|
136219
136255
|
unique_ptr<Expression> Binder::BindOrderExpression(OrderBinder &order_binder, unique_ptr<ParsedExpression> expr) {
|
|
136220
136256
|
// we treat the Distinct list as a order by
|
|
@@ -136413,7 +136449,10 @@ unique_ptr<BoundQueryNode> Binder::BindNode(SelectNode &statement) {
|
|
|
136413
136449
|
// first visit the WHERE clause
|
|
136414
136450
|
// the WHERE clause happens before the GROUP BY, PROJECTION or HAVING clauses
|
|
136415
136451
|
if (statement.where_clause) {
|
|
136416
|
-
result
|
|
136452
|
+
ColumnAliasBinder alias_binder(*result, alias_map);
|
|
136453
|
+
WhereBinder where_binder(*this, context, &alias_binder);
|
|
136454
|
+
unique_ptr<ParsedExpression> condition = move(statement.where_clause);
|
|
136455
|
+
result->where_clause = where_binder.Bind(condition);
|
|
136417
136456
|
}
|
|
136418
136457
|
|
|
136419
136458
|
// now bind all the result modifiers; including DISTINCT and ORDER BY targets
|
|
@@ -141757,6 +141796,38 @@ BindResult CheckBinder::BindCheckColumn(ColumnRefExpression &colref) {
|
|
|
141757
141796
|
} // namespace duckdb
|
|
141758
141797
|
|
|
141759
141798
|
|
|
141799
|
+
|
|
141800
|
+
|
|
141801
|
+
|
|
141802
|
+
|
|
141803
|
+
namespace duckdb {
|
|
141804
|
+
|
|
141805
|
+
ColumnAliasBinder::ColumnAliasBinder(BoundSelectNode &node, const unordered_map<string, idx_t> &alias_map)
|
|
141806
|
+
: node(node), alias_map(alias_map), in_alias(false) {
|
|
141807
|
+
}
|
|
141808
|
+
|
|
141809
|
+
BindResult ColumnAliasBinder::BindAlias(ExpressionBinder &enclosing_binder, ColumnRefExpression &expr, idx_t depth,
|
|
141810
|
+
bool root_expression) {
|
|
141811
|
+
if (!expr.table_name.empty()) {
|
|
141812
|
+
return BindResult(StringUtil::Format("Alias %s cannot be qualified.", expr.ToString()));
|
|
141813
|
+
}
|
|
141814
|
+
|
|
141815
|
+
auto alias_entry = alias_map.find(expr.column_name);
|
|
141816
|
+
if (alias_entry == alias_map.end()) {
|
|
141817
|
+
return BindResult(StringUtil::Format("Alias %s is not found.", expr.ToString()));
|
|
141818
|
+
}
|
|
141819
|
+
|
|
141820
|
+
// found an alias: bind the alias expression
|
|
141821
|
+
D_ASSERT(!in_alias);
|
|
141822
|
+
auto expression = node.original_expressions[alias_entry->second]->Copy();
|
|
141823
|
+
in_alias = true;
|
|
141824
|
+
auto result = enclosing_binder.BindExpression(&expression, depth, root_expression);
|
|
141825
|
+
in_alias = false;
|
|
141826
|
+
return result;
|
|
141827
|
+
}
|
|
141828
|
+
|
|
141829
|
+
} // namespace duckdb
|
|
141830
|
+
|
|
141760
141831
|
namespace duckdb {
|
|
141761
141832
|
|
|
141762
141833
|
ConstantBinder::ConstantBinder(Binder &binder, ClientContext &context, string clause)
|
|
@@ -141904,10 +141975,21 @@ namespace duckdb {
|
|
|
141904
141975
|
|
|
141905
141976
|
HavingBinder::HavingBinder(Binder &binder, ClientContext &context, BoundSelectNode &node, BoundGroupInformation &info,
|
|
141906
141977
|
unordered_map<string, idx_t> &alias_map)
|
|
141907
|
-
: SelectBinder(binder, context, node, info),
|
|
141978
|
+
: SelectBinder(binder, context, node, info), column_alias_binder(node, alias_map) {
|
|
141908
141979
|
target_type = LogicalType(LogicalTypeId::BOOLEAN);
|
|
141909
141980
|
}
|
|
141910
141981
|
|
|
141982
|
+
BindResult HavingBinder::BindColumnRef(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth, bool root_expression) {
|
|
141983
|
+
auto &expr = (ColumnRefExpression &)**expr_ptr;
|
|
141984
|
+
auto alias_result = column_alias_binder.BindAlias(*this, expr, depth, root_expression);
|
|
141985
|
+
if (!alias_result.HasError()) {
|
|
141986
|
+
return alias_result;
|
|
141987
|
+
}
|
|
141988
|
+
|
|
141989
|
+
return BindResult(StringUtil::Format(
|
|
141990
|
+
"column %s must appear in the GROUP BY clause or be used in an aggregate function", expr.ToString()));
|
|
141991
|
+
}
|
|
141992
|
+
|
|
141911
141993
|
BindResult HavingBinder::BindExpression(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth, bool root_expression) {
|
|
141912
141994
|
auto &expr = **expr_ptr;
|
|
141913
141995
|
// check if the expression binds to one of the groups
|
|
@@ -141919,22 +142001,7 @@ BindResult HavingBinder::BindExpression(unique_ptr<ParsedExpression> *expr_ptr,
|
|
|
141919
142001
|
case ExpressionClass::WINDOW:
|
|
141920
142002
|
return BindResult("HAVING clause cannot contain window functions!");
|
|
141921
142003
|
case ExpressionClass::COLUMN_REF:
|
|
141922
|
-
|
|
141923
|
-
auto &colref = (ColumnRefExpression &)expr;
|
|
141924
|
-
if (colref.table_name.empty()) {
|
|
141925
|
-
auto alias_entry = alias_map.find(colref.column_name);
|
|
141926
|
-
if (alias_entry != alias_map.end()) {
|
|
141927
|
-
// found an alias: bind the alias expression
|
|
141928
|
-
auto expression = node.original_expressions[alias_entry->second]->Copy();
|
|
141929
|
-
in_alias = true;
|
|
141930
|
-
auto result = BindExpression(&expression, depth, root_expression);
|
|
141931
|
-
in_alias = false;
|
|
141932
|
-
return result;
|
|
141933
|
-
}
|
|
141934
|
-
}
|
|
141935
|
-
}
|
|
141936
|
-
return BindResult(StringUtil::Format(
|
|
141937
|
-
"column %s must appear in the GROUP BY clause or be used in an aggregate function", expr.ToString()));
|
|
142004
|
+
return BindColumnRef(expr_ptr, depth, root_expression);
|
|
141938
142005
|
default:
|
|
141939
142006
|
return duckdb::SelectBinder::BindExpression(expr_ptr, depth);
|
|
141940
142007
|
}
|
|
@@ -142268,12 +142335,30 @@ string UpdateBinder::UnsupportedAggregateMessage() {
|
|
|
142268
142335
|
} // namespace duckdb
|
|
142269
142336
|
|
|
142270
142337
|
|
|
142338
|
+
|
|
142271
142339
|
namespace duckdb {
|
|
142272
142340
|
|
|
142273
|
-
WhereBinder::WhereBinder(Binder &binder, ClientContext &context
|
|
142341
|
+
WhereBinder::WhereBinder(Binder &binder, ClientContext &context, ColumnAliasBinder *column_alias_binder)
|
|
142342
|
+
: ExpressionBinder(binder, context), column_alias_binder(column_alias_binder) {
|
|
142274
142343
|
target_type = LogicalType(LogicalTypeId::BOOLEAN);
|
|
142275
142344
|
}
|
|
142276
142345
|
|
|
142346
|
+
BindResult WhereBinder::BindColumnRef(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth, bool root_expression) {
|
|
142347
|
+
auto &expr = (ColumnRefExpression &)**expr_ptr;
|
|
142348
|
+
auto result = ExpressionBinder::BindExpression(expr_ptr, depth);
|
|
142349
|
+
if (!result.HasError() || !column_alias_binder) {
|
|
142350
|
+
return result;
|
|
142351
|
+
}
|
|
142352
|
+
|
|
142353
|
+
BindResult alias_result = column_alias_binder->BindAlias(*this, expr, depth, root_expression);
|
|
142354
|
+
// This code path cannot be exercised at thispoint. #1547 might change that.
|
|
142355
|
+
if (!alias_result.HasError()) {
|
|
142356
|
+
return alias_result;
|
|
142357
|
+
}
|
|
142358
|
+
|
|
142359
|
+
return result;
|
|
142360
|
+
}
|
|
142361
|
+
|
|
142277
142362
|
BindResult WhereBinder::BindExpression(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth, bool root_expression) {
|
|
142278
142363
|
auto &expr = **expr_ptr;
|
|
142279
142364
|
switch (expr.GetExpressionClass()) {
|
|
@@ -142281,6 +142366,8 @@ BindResult WhereBinder::BindExpression(unique_ptr<ParsedExpression> *expr_ptr, i
|
|
|
142281
142366
|
return BindResult("WHERE clause cannot contain DEFAULT clause");
|
|
142282
142367
|
case ExpressionClass::WINDOW:
|
|
142283
142368
|
return BindResult("WHERE clause cannot contain window functions!");
|
|
142369
|
+
case ExpressionClass::COLUMN_REF:
|
|
142370
|
+
return BindColumnRef(expr_ptr, depth, root_expression);
|
|
142284
142371
|
default:
|
|
142285
142372
|
return ExpressionBinder::BindExpression(expr_ptr, depth);
|
|
142286
142373
|
}
|
|
@@ -142542,8 +142629,6 @@ void ExpressionBinder::BindTableNames(Binder &binder, ParsedExpression &expr, un
|
|
|
142542
142629
|
if (binder.macro_binding != nullptr && binder.macro_binding->HasMatchingBinding(colref.column_name)) {
|
|
142543
142630
|
// macro parameters get priority
|
|
142544
142631
|
colref.table_name = binder.macro_binding->alias;
|
|
142545
|
-
} else if (alias_map && alias_map->find(colref.column_name) != alias_map->end()) {
|
|
142546
|
-
// alias: leave unqualified
|
|
142547
142632
|
} else {
|
|
142548
142633
|
colref.table_name = binder.bind_context.GetMatchingBinding(colref.column_name);
|
|
142549
142634
|
}
|
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.1-
|
|
13
|
+
#define DUCKDB_SOURCE_ID "62382bcc0"
|
|
14
|
+
#define DUCKDB_VERSION "0.3.1-dev332"
|
|
15
15
|
//===----------------------------------------------------------------------===//
|
|
16
16
|
// DuckDB
|
|
17
17
|
//
|