duckdb 0.3.1-dev289.0 → 0.3.1-dev291.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 +63 -2
- package/src/duckdb.hpp +2 -2
package/package.json
CHANGED
package/src/duckdb.cpp
CHANGED
|
@@ -130128,16 +130128,23 @@ unique_ptr<ParsedExpression> Transformer::TransformFuncCall(duckdb_libpgquery::P
|
|
|
130128
130128
|
throw ParserException("Cannot use multiple ORDER BY clauses with WITHIN GROUP");
|
|
130129
130129
|
}
|
|
130130
130130
|
if (lowercase_name == "percentile_cont") {
|
|
130131
|
+
if (children.size() != 1) {
|
|
130132
|
+
throw ParserException("Wrong number of arguments for PERCENTILE_CONT");
|
|
130133
|
+
}
|
|
130131
130134
|
lowercase_name = "quantile_cont";
|
|
130132
130135
|
} else if (lowercase_name == "percentile_disc") {
|
|
130136
|
+
if (children.size() != 1) {
|
|
130137
|
+
throw ParserException("Wrong number of arguments for PERCENTILE_DISC");
|
|
130138
|
+
}
|
|
130133
130139
|
lowercase_name = "quantile_disc";
|
|
130134
130140
|
} else if (lowercase_name == "mode") {
|
|
130141
|
+
if (!children.empty()) {
|
|
130142
|
+
throw ParserException("Wrong number of arguments for MODE");
|
|
130143
|
+
}
|
|
130135
130144
|
lowercase_name = "mode";
|
|
130136
130145
|
} else {
|
|
130137
130146
|
throw ParserException("Unknown ordered aggregate \"%s\".", function_name);
|
|
130138
130147
|
}
|
|
130139
|
-
children.insert(children.begin(), move(order_bys->orders[0].expression));
|
|
130140
|
-
order_bys->orders.clear();
|
|
130141
130148
|
}
|
|
130142
130149
|
|
|
130143
130150
|
// star gets eaten in the parser
|
|
@@ -134249,6 +134256,7 @@ void BindContext::AddContext(BindContext other) {
|
|
|
134249
134256
|
|
|
134250
134257
|
|
|
134251
134258
|
|
|
134259
|
+
|
|
134252
134260
|
//===----------------------------------------------------------------------===//
|
|
134253
134261
|
// DuckDB
|
|
134254
134262
|
//
|
|
@@ -134466,8 +134474,30 @@ public:
|
|
|
134466
134474
|
|
|
134467
134475
|
|
|
134468
134476
|
|
|
134477
|
+
|
|
134469
134478
|
namespace duckdb {
|
|
134470
134479
|
|
|
134480
|
+
static void InvertPercentileFractions(unique_ptr<ParsedExpression> &fractions) {
|
|
134481
|
+
D_ASSERT(fractions.get());
|
|
134482
|
+
D_ASSERT(fractions->expression_class == ExpressionClass::BOUND_EXPRESSION);
|
|
134483
|
+
auto &bound = (BoundExpression &)*fractions;
|
|
134484
|
+
|
|
134485
|
+
if (!bound.expr->IsFoldable()) {
|
|
134486
|
+
return;
|
|
134487
|
+
}
|
|
134488
|
+
|
|
134489
|
+
Value value = ExpressionExecutor::EvaluateScalar(*bound.expr);
|
|
134490
|
+
if (value.type().id() == LogicalTypeId::LIST) {
|
|
134491
|
+
vector<Value> values;
|
|
134492
|
+
for (const auto &element_val : value.list_value) {
|
|
134493
|
+
values.emplace_back(Value(1) - element_val);
|
|
134494
|
+
}
|
|
134495
|
+
bound.expr = make_unique<BoundConstantExpression>(Value::LIST(values));
|
|
134496
|
+
} else {
|
|
134497
|
+
bound.expr = make_unique<BoundConstantExpression>(Value(1) - value);
|
|
134498
|
+
}
|
|
134499
|
+
}
|
|
134500
|
+
|
|
134471
134501
|
BindResult SelectBinder::BindAggregate(FunctionExpression &aggr, AggregateFunctionCatalogEntry *func, idx_t depth) {
|
|
134472
134502
|
// first bind the child of the aggregate expression (if any)
|
|
134473
134503
|
this->bound_aggregate = true;
|
|
@@ -134480,8 +134510,28 @@ BindResult SelectBinder::BindAggregate(FunctionExpression &aggr, AggregateFuncti
|
|
|
134480
134510
|
aggregate_binder.BindChild(aggr.filter, 0, error);
|
|
134481
134511
|
}
|
|
134482
134512
|
|
|
134513
|
+
// Handle ordered-set aggregates by moving the single ORDER BY expression to the front of the children.
|
|
134514
|
+
// https://www.postgresql.org/docs/current/functions-aggregate.html#FUNCTIONS-ORDEREDSET-TABLE
|
|
134515
|
+
bool ordered_set_agg = false;
|
|
134516
|
+
bool invert_fractions = false;
|
|
134517
|
+
if (aggr.order_bys && aggr.order_bys->orders.size() == 1) {
|
|
134518
|
+
const auto &func_name = aggr.function_name;
|
|
134519
|
+
ordered_set_agg = (func_name == "quantile_cont" || func_name == "quantile_disc" || func_name == "mode");
|
|
134520
|
+
|
|
134521
|
+
if (ordered_set_agg) {
|
|
134522
|
+
auto &config = DBConfig::GetConfig(context);
|
|
134523
|
+
const auto &order = aggr.order_bys->orders[0];
|
|
134524
|
+
const auto sense = (order.type == OrderType::ORDER_DEFAULT) ? config.default_order_type : order.type;
|
|
134525
|
+
invert_fractions = (sense == OrderType::DESCENDING);
|
|
134526
|
+
}
|
|
134527
|
+
}
|
|
134528
|
+
|
|
134483
134529
|
for (auto &child : aggr.children) {
|
|
134484
134530
|
aggregate_binder.BindChild(child, 0, error);
|
|
134531
|
+
// We have to invert the fractions for PERCENTILE_XXXX DESC
|
|
134532
|
+
if (invert_fractions) {
|
|
134533
|
+
InvertPercentileFractions(child);
|
|
134534
|
+
}
|
|
134485
134535
|
}
|
|
134486
134536
|
|
|
134487
134537
|
// Bind the ORDER BYs, if any
|
|
@@ -134543,6 +134593,17 @@ BindResult SelectBinder::BindAggregate(FunctionExpression &aggr, AggregateFuncti
|
|
|
134543
134593
|
vector<LogicalType> types;
|
|
134544
134594
|
vector<LogicalType> arguments;
|
|
134545
134595
|
vector<unique_ptr<Expression>> children;
|
|
134596
|
+
|
|
134597
|
+
if (ordered_set_agg) {
|
|
134598
|
+
for (auto &order : aggr.order_bys->orders) {
|
|
134599
|
+
auto &child = (BoundExpression &)*order.expression;
|
|
134600
|
+
types.push_back(child.expr->return_type);
|
|
134601
|
+
arguments.push_back(child.expr->return_type);
|
|
134602
|
+
children.push_back(move(child.expr));
|
|
134603
|
+
}
|
|
134604
|
+
aggr.order_bys->orders.clear();
|
|
134605
|
+
}
|
|
134606
|
+
|
|
134546
134607
|
for (idx_t i = 0; i < aggr.children.size(); i++) {
|
|
134547
134608
|
auto &child = (BoundExpression &)*aggr.children[i];
|
|
134548
134609
|
types.push_back(child.expr->return_type);
|
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 "041bb3216"
|
|
14
|
+
#define DUCKDB_VERSION "0.3.1-dev291"
|
|
15
15
|
//===----------------------------------------------------------------------===//
|
|
16
16
|
// DuckDB
|
|
17
17
|
//
|