Skip to content

Commit

Permalink
Update vendored DuckDB sources to 32528f5
Browse files Browse the repository at this point in the history
  • Loading branch information
duckdblabs-bot committed Aug 25, 2024
1 parent 32528f5 commit bc4117d
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static void EnumRangeFunction(DataChunk &input, ExpressionState &state, Vector &
for (idx_t i = 0; i < enum_size; i++) {
enum_values.emplace_back(enum_vector.GetValue(i));
}
auto val = Value::LIST(enum_values);
auto val = Value::LIST(LogicalType::VARCHAR, enum_values);
result.Reference(val);
}

Expand Down
6 changes: 3 additions & 3 deletions src/duckdb/src/function/table/version/pragma_version.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef DUCKDB_PATCH_VERSION
#define DUCKDB_PATCH_VERSION "1-dev4673"
#define DUCKDB_PATCH_VERSION "1-dev4683"
#endif
#ifndef DUCKDB_MINOR_VERSION
#define DUCKDB_MINOR_VERSION 0
Expand All @@ -8,10 +8,10 @@
#define DUCKDB_MAJOR_VERSION 1
#endif
#ifndef DUCKDB_VERSION
#define DUCKDB_VERSION "v1.0.1-dev4673"
#define DUCKDB_VERSION "v1.0.1-dev4683"
#endif
#ifndef DUCKDB_SOURCE_ID
#define DUCKDB_SOURCE_ID "f0dbafd48f"
#define DUCKDB_SOURCE_ID "5819112b7e"
#endif
#include "duckdb/function/table/system_functions.hpp"
#include "duckdb/main/database.hpp"
Expand Down
2 changes: 2 additions & 0 deletions src/duckdb/src/include/duckdb/main/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ struct DBConfigOptions {
bool scalar_subquery_error_on_multiple_rows = true;
//! Use IEE754-compliant floating point operations (returning NAN instead of errors/NULL)
bool ieee_floating_point_ops = true;
//! Allow ordering by non-integer literals - ordering by such literals has no effect
bool order_by_non_integer_literal = false;

bool operator==(const DBConfigOptions &other) const;
};
Expand Down
10 changes: 10 additions & 0 deletions src/duckdb/src/include/duckdb/main/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,16 @@ struct OldImplicitCasting {
static Value GetSetting(const ClientContext &context);
};

struct OrderByNonIntegerLiteral {
static constexpr const char *Name = "order_by_non_integer_literal";
static constexpr const char *Description =
"Allow ordering by non-integer literals - ordering by such literals has no effect";
static constexpr const LogicalTypeId InputType = LogicalTypeId::BOOLEAN;
static void SetGlobal(DatabaseInstance *db, DBConfig &config, const Value &parameter);
static void ResetGlobal(DatabaseInstance *db, DBConfig &config);
static Value GetSetting(const ClientContext &context);
};

struct PartitionedWriteFlushThreshold {
static constexpr const char *Name = "partitioned_write_flush_threshold";
static constexpr const char *Description =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ struct SelectBindState;
//! The ORDER binder is responsible for binding an expression within the ORDER BY clause of a SQL statement
class OrderBinder {
public:
OrderBinder(vector<Binder *> binders, SelectBindState &bind_state);
OrderBinder(vector<Binder *> binders, SelectNode &node, SelectBindState &bind_state);
OrderBinder(vector<reference<Binder>> binders, SelectBindState &bind_state);
OrderBinder(vector<reference<Binder>> binders, SelectNode &node, SelectBindState &bind_state);

public:
unique_ptr<Expression> Bind(unique_ptr<ParsedExpression> expr);

bool HasExtraList() const {
return extra_list;
}
const vector<Binder *> &GetBinders() const {
const vector<reference<Binder>> &GetBinders() const {
return binders;
}

Expand All @@ -43,7 +43,7 @@ class OrderBinder {
optional_idx TryGetProjectionReference(ParsedExpression &expr) const;

private:
vector<Binder *> binders;
vector<reference<Binder>> binders;
optional_ptr<vector<unique_ptr<ParsedExpression>>> extra_list;
SelectBindState &bind_state;
};
Expand Down
1 change: 1 addition & 0 deletions src/duckdb/src/main/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ static const ConfigurationOption internal_options[] = {
DUCKDB_GLOBAL(OldImplicitCasting),
DUCKDB_GLOBAL_ALIAS("memory_limit", MaximumMemorySetting),
DUCKDB_GLOBAL_ALIAS("null_order", DefaultNullOrderSetting),
DUCKDB_GLOBAL(OrderByNonIntegerLiteral),
DUCKDB_LOCAL(OrderedAggregateThreshold),
DUCKDB_GLOBAL(PasswordSetting),
DUCKDB_LOCAL(PerfectHashThresholdSetting),
Expand Down
16 changes: 16 additions & 0 deletions src/duckdb/src/main/settings/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,22 @@ Value OldImplicitCasting::GetSetting(const ClientContext &context) {
return Value::BOOLEAN(config.options.old_implicit_casting);
}

//===--------------------------------------------------------------------===//
// Old Implicit Casting
//===--------------------------------------------------------------------===//
void OrderByNonIntegerLiteral::SetGlobal(DatabaseInstance *db, DBConfig &config, const Value &input) {
config.options.order_by_non_integer_literal = input.GetValue<bool>();
}

void OrderByNonIntegerLiteral::ResetGlobal(DatabaseInstance *db, DBConfig &config) {
config.options.order_by_non_integer_literal = DBConfig().options.order_by_non_integer_literal;
}

Value OrderByNonIntegerLiteral::GetSetting(const ClientContext &context) {
auto &config = DBConfig::GetConfig(context);
return Value::BOOLEAN(config.options.order_by_non_integer_literal);
}

//===--------------------------------------------------------------------===//
// Partitioned Write Flush Threshold
//===--------------------------------------------------------------------===//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
#include "duckdb/catalog/catalog_entry/aggregate_function_catalog_entry.hpp"
#include "duckdb/common/pair.hpp"
#include "duckdb/common/operator/cast_operators.hpp"
#include "duckdb/common/pair.hpp"
#include "duckdb/execution/expression_executor.hpp"
#include "duckdb/function/function_binder.hpp"
#include "duckdb/function/scalar/generic_functions.hpp"
#include "duckdb/main/config.hpp"
#include "duckdb/parser/expression/constant_expression.hpp"
#include "duckdb/parser/expression/function_expression.hpp"
#include "duckdb/planner/binder.hpp"
#include "duckdb/planner/expression/bound_aggregate_expression.hpp"
#include "duckdb/planner/expression/bound_cast_expression.hpp"
#include "duckdb/planner/expression/bound_columnref_expression.hpp"
#include "duckdb/planner/expression/bound_constant_expression.hpp"
#include "duckdb/planner/expression/bound_function_expression.hpp"
#include "duckdb/planner/expression_iterator.hpp"
#include "duckdb/planner/expression_binder/aggregate_binder.hpp"
#include "duckdb/planner/expression_binder/base_select_binder.hpp"
#include "duckdb/planner/expression_iterator.hpp"
#include "duckdb/planner/query_node/bound_select_node.hpp"
#include "duckdb/execution/expression_executor.hpp"
#include "duckdb/function/scalar/generic_functions.hpp"
#include "duckdb/main/config.hpp"
#include "duckdb/function/function_binder.hpp"
#include "duckdb/planner/binder.hpp"

namespace duckdb {

Expand Down Expand Up @@ -140,6 +141,19 @@ BindResult BaseSelectBinder::BindAggregate(FunctionExpression &aggr, AggregateFu
// Bind the ORDER BYs, if any
if (aggr.order_bys && !aggr.order_bys->orders.empty()) {
for (auto &order : aggr.order_bys->orders) {
if (order.expression->type == ExpressionType::VALUE_CONSTANT) {
auto &const_expr = order.expression->Cast<ConstantExpression>();
if (!const_expr.value.type().IsIntegral()) {
auto &config = DBConfig::GetConfig(context);
if (!config.options.order_by_non_integer_literal) {
throw BinderException(
*order.expression,
"ORDER BY non-integer literal has no effect.\n* SET order_by_non_integer_literal=true to "
"allow this behavior.\n\nPerhaps you misplaced ORDER BY; ORDER BY must appear "
"after all regular arguments of the aggregate.");
}
}
}
aggregate_binder.BindChild(order.expression, 0, error);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/duckdb/src/planner/binder/query_node/bind_select_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void Binder::PrepareModifiers(OrderBinder &order_binder, QueryNode &statement, B
#endif
for (auto &order_node : order.orders) {
vector<unique_ptr<ParsedExpression>> order_list;
order_binders[0]->ExpandStarExpression(std::move(order_node.expression), order_list);
order_binders[0].get().ExpandStarExpression(std::move(order_node.expression), order_list);

auto type = config.ResolveOrder(order_node.type);
auto null_order = config.ResolveNullOrder(type, order_node.null_order);
Expand Down Expand Up @@ -453,7 +453,7 @@ unique_ptr<BoundQueryNode> Binder::BindSelectNode(SelectNode &statement, unique_
}

// now bind all the result modifiers; including DISTINCT and ORDER BY targets
OrderBinder order_binder({this}, statement, bind_state);
OrderBinder order_binder({*this}, statement, bind_state);
PrepareModifiers(order_binder, statement, *result);

vector<unique_ptr<ParsedExpression>> unbound_groups;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ unique_ptr<BoundQueryNode> Binder::BindNode(SetOperationNode &statement) {
GatherAliases(*result, bind_state, reorder_idx);
}
// now we perform the actual resolution of the ORDER BY/DISTINCT expressions
OrderBinder order_binder({result->left_binder.get(), result->right_binder.get()}, bind_state);
OrderBinder order_binder({*result->left_binder, *result->right_binder}, bind_state);
PrepareModifiers(order_binder, statement, *result);
}

Expand Down
16 changes: 11 additions & 5 deletions src/duckdb/src/planner/expression_binder/order_binder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
#include "duckdb/planner/expression/bound_parameter_expression.hpp"
#include "duckdb/planner/expression_binder.hpp"
#include "duckdb/planner/expression_binder/select_bind_state.hpp"
#include "duckdb/main/config.hpp"
#include "duckdb/common/pair.hpp"

namespace duckdb {

OrderBinder::OrderBinder(vector<Binder *> binders, SelectBindState &bind_state)
OrderBinder::OrderBinder(vector<reference<Binder>> binders, SelectBindState &bind_state)
: binders(std::move(binders)), extra_list(nullptr), bind_state(bind_state) {
}
OrderBinder::OrderBinder(vector<Binder *> binders, SelectNode &node, SelectBindState &bind_state)
OrderBinder::OrderBinder(vector<reference<Binder>> binders, SelectNode &node, SelectBindState &bind_state)
: binders(std::move(binders)), bind_state(bind_state) {
this->extra_list = &node.select_list;
}
Expand Down Expand Up @@ -55,9 +56,14 @@ optional_idx OrderBinder::TryGetProjectionReference(ParsedExpression &expr) cons
auto &constant = expr.Cast<ConstantExpression>();
// ORDER BY a constant
if (!constant.value.type().IsIntegral()) {
// non-integral expression, we just leave the constant here.
// non-integral expression
// ORDER BY <constant> has no effect
// CONTROVERSIAL: maybe we should throw an error
// this is disabled by default (matching Postgres) - but we can control this with a setting
auto &config = DBConfig::GetConfig(binders[0].get().context);
if (!config.options.order_by_non_integer_literal) {
throw BinderException(expr, "ORDER BY non-integer literal has no effect.\n* SET "
"order_by_non_integer_literal=true to allow this behavior.");
}
break;
}
// INTEGER constant: we use the integer as an index into the select list (e.g. ORDER BY 1)
Expand Down Expand Up @@ -143,7 +149,7 @@ unique_ptr<Expression> OrderBinder::Bind(unique_ptr<ParsedExpression> expr) {
// general case
// first bind the table names of this entry
for (auto &binder : binders) {
ExpressionBinder::QualifyColumnNames(*binder, expr);
ExpressionBinder::QualifyColumnNames(binder.get(), expr);
}
// first check if the ORDER BY clause already points to an entry in the projection list
auto entry = bind_state.projection_map.find(*expr);
Expand Down

0 comments on commit bc4117d

Please sign in to comment.