From 25c7873cc05c74d01cce306c741304977ab66df5 Mon Sep 17 00:00:00 2001 From: DuckDB Labs GitHub Bot Date: Wed, 18 Dec 2024 00:35:27 +0000 Subject: [PATCH] Update vendored DuckDB sources to 2e8ebca5 --- .../core_functions/scalar/generic/alias.cpp | 2 +- .../core_functions/scalar/generic/least.cpp | 2 +- .../scalar/list/list_filter.cpp | 2 +- .../scalar/list/list_reduce.cpp | 2 +- .../scalar/list/list_transform.cpp | 2 +- .../core_functions/scalar/list/list_value.cpp | 4 +- .../scalar/struct/struct_insert.cpp | 10 +-- .../scalar/union/union_value.cpp | 4 +- .../json/json_functions/copy_json.cpp | 2 +- .../json_functions/json_serialize_plan.cpp | 13 +-- .../json_functions/json_serialize_sql.cpp | 11 +-- .../extension/parquet/parquet_extension.cpp | 8 +- .../catalog_entry/duck_table_entry.cpp | 2 +- .../catalog_entry/table_catalog_entry.cpp | 2 +- src/duckdb/src/common/error_data.cpp | 2 +- src/duckdb/src/common/exception.cpp | 4 +- .../src/common/exception/binder_exception.cpp | 2 +- src/duckdb/src/common/hive_partitioning.cpp | 2 +- .../src/execution/aggregate_hashtable.cpp | 18 +++- .../src/execution/column_binding_resolver.cpp | 4 +- .../src/execution/expression_executor.cpp | 6 +- .../expression_executor/execute_cast.cpp | 4 +- .../execute_comparison.cpp | 4 +- .../execute_conjunction.cpp | 4 +- .../expression_executor/execute_operator.cpp | 9 +- src/duckdb/src/execution/index/art/art.cpp | 10 +-- .../src/execution/index/bound_index.cpp | 2 +- .../aggregate/grouped_aggregate_data.cpp | 2 +- .../aggregate/physical_hash_aggregate.cpp | 4 +- .../physical_perfecthash_aggregate.cpp | 6 +- .../aggregate/physical_streaming_window.cpp | 4 +- .../operator/aggregate/physical_window.cpp | 6 +- .../operator/persistent/physical_update.cpp | 5 +- .../operator/projection/physical_unnest.cpp | 2 +- .../physical_plan/plan_aggregate.cpp | 4 +- .../physical_plan/plan_comparison_join.cpp | 2 +- .../execution/physical_plan/plan_delete.cpp | 2 +- .../physical_plan/plan_delim_join.cpp | 2 +- .../execution/physical_plan/plan_distinct.cpp | 4 +- .../physical_plan/plan_projection.cpp | 2 +- .../execution/radix_partitioned_hashtable.cpp | 2 +- src/duckdb/src/function/macro_function.cpp | 8 +- .../function/scalar/struct/struct_pack.cpp | 4 +- .../scalar/system/aggregate_export.cpp | 2 +- .../table/system/duckdb_functions.cpp | 4 +- src/duckdb/src/function/table/table_scan.cpp | 2 +- .../function/table/version/pragma_version.cpp | 6 +- .../window/window_boundaries_state.cpp | 10 +-- .../function/window/window_value_function.cpp | 2 +- .../duckdb/function/table/read_csv.hpp | 4 +- .../optimizer/expression_heuristics.hpp | 2 +- .../include/duckdb/parser/base_expression.hpp | 54 +++++++++++- .../expression/comparison_expression.hpp | 4 +- .../expression/conjunction_expression.hpp | 2 +- .../parser/expression/function_expression.hpp | 4 +- .../parser/expression/operator_expression.hpp | 12 +-- .../storage/compression/alp/alp_compress.hpp | 1 - .../compression/alprd/alprd_compress.hpp | 1 - .../duckdb/storage/table/column_data.hpp | 4 +- .../duckdb/storage/table/column_segment.hpp | 53 ++++++------ src/duckdb/src/main/relation.cpp | 4 +- .../src/main/relation/projection_relation.cpp | 4 +- .../src/optimizer/column_binding_replacer.cpp | 2 +- .../optimizer/column_lifetime_analyzer.cpp | 2 +- .../compress_aggregate.cpp | 6 +- .../compress_distinct.cpp | 4 +- src/duckdb/src/optimizer/cse_optimizer.cpp | 14 +-- src/duckdb/src/optimizer/deliminator.cpp | 11 +-- .../src/optimizer/expression_heuristics.cpp | 6 +- src/duckdb/src/optimizer/filter_combiner.cpp | 86 ++++++++++--------- src/duckdb/src/optimizer/filter_pushdown.cpp | 2 +- .../src/optimizer/in_clause_rewriter.cpp | 5 +- .../join_filter_pushdown_optimizer.cpp | 4 +- .../join_order/cardinality_estimator.cpp | 7 +- .../join_order/query_graph_manager.cpp | 14 +-- .../optimizer/join_order/relation_manager.cpp | 10 +-- .../join_order/relation_statistics_helper.cpp | 4 +- .../optimizer/matcher/expression_matcher.cpp | 5 +- .../optimizer/pullup/pullup_projection.cpp | 4 +- .../optimizer/pullup/pullup_set_operation.cpp | 2 +- .../optimizer/pushdown/pushdown_aggregate.cpp | 4 +- .../optimizer/pushdown/pushdown_left_join.cpp | 2 +- .../optimizer/pushdown/pushdown_mark_join.cpp | 6 +- .../pushdown/pushdown_projection.cpp | 4 +- .../pushdown/pushdown_set_operation.cpp | 2 +- .../optimizer/pushdown/pushdown_window.cpp | 4 +- .../src/optimizer/regex_range_filter.cpp | 2 +- .../src/optimizer/remove_duplicate_groups.cpp | 2 +- .../src/optimizer/remove_unused_columns.cpp | 4 +- .../rule/comparison_simplification.cpp | 6 +- .../rule/conjunction_simplification.cpp | 4 +- .../src/optimizer/rule/constant_folding.cpp | 4 +- .../src/optimizer/rule/distributivity.cpp | 4 +- .../src/optimizer/rule/enum_comparison.cpp | 3 +- .../rule/equal_or_null_simplification.cpp | 7 +- .../rule/in_clause_simplification_rule.cpp | 6 +- .../src/optimizer/rule/move_constants.cpp | 18 ++-- .../optimizer/rule/timestamp_comparison.cpp | 2 +- .../expression/propagate_comparison.cpp | 2 +- .../expression/propagate_conjunction.cpp | 2 +- .../expression/propagate_operator.cpp | 2 +- .../operator/propagate_aggregate.cpp | 4 +- .../statistics/operator/propagate_filter.cpp | 15 ++-- .../statistics/operator/propagate_join.cpp | 6 +- src/duckdb/src/optimizer/sum_rewriter.cpp | 2 +- src/duckdb/src/optimizer/topn_optimizer.cpp | 2 +- src/duckdb/src/optimizer/unnest_rewriter.cpp | 6 +- src/duckdb/src/parser/column_definition.cpp | 6 +- .../expression/conjunction_expression.cpp | 2 +- .../parser/expression/function_expression.cpp | 2 +- .../parser/expression/lambda_expression.cpp | 6 +- .../parser/parsed_data/create_index_info.cpp | 2 +- src/duckdb/src/parser/parsed_expression.cpp | 2 +- .../src/parser/parsed_expression_iterator.cpp | 2 +- .../src/parser/query_node/select_node.cpp | 4 +- .../src/parser/statement/delete_statement.cpp | 5 +- .../src/parser/statement/insert_statement.cpp | 7 +- .../src/parser/statement/update_statement.cpp | 5 +- src/duckdb/src/parser/tableref/pivotref.cpp | 4 +- .../expression/transform_array_access.cpp | 2 +- .../expression/transform_bool_expr.cpp | 10 +-- .../expression/transform_columnref.cpp | 2 +- .../expression/transform_constant.cpp | 8 +- .../expression/transform_expression.cpp | 4 +- .../expression/transform_function.cpp | 2 +- .../expression/transform_operator.cpp | 2 +- .../expression/transform_subquery.cpp | 2 +- .../transform/helpers/transform_groupby.cpp | 2 +- .../transform/helpers/transform_sample.cpp | 4 +- .../statement/transform_comment_on.cpp | 2 +- .../statement/transform_create_function.cpp | 10 +-- .../transform/statement/transform_pragma.cpp | 6 +- .../transform/statement/transform_prepare.cpp | 8 +- .../transform/statement/transform_set.cpp | 4 +- .../transform/tableref/transform_pivot.cpp | 13 +-- src/duckdb/src/parser/transformer.cpp | 4 +- src/duckdb/src/planner/bind_context.cpp | 10 +-- src/duckdb/src/planner/binder.cpp | 4 +- .../expression/bind_aggregate_expression.cpp | 6 +- .../expression/bind_between_expression.cpp | 6 +- .../expression/bind_columnref_expression.cpp | 26 +++--- .../expression/bind_comparison_expression.cpp | 8 +- .../bind_conjunction_expression.cpp | 2 +- .../expression/bind_function_expression.cpp | 10 +-- .../planner/binder/expression/bind_lambda.cpp | 20 ++--- .../expression/bind_macro_expression.cpp | 2 +- .../expression/bind_operator_expression.cpp | 26 +++--- .../expression/bind_parameter_expression.cpp | 2 +- .../expression/bind_star_expression.cpp | 26 +++--- .../expression/bind_subquery_expression.cpp | 2 +- .../expression/bind_unnest_expression.cpp | 8 +- .../expression/bind_window_expression.cpp | 28 +++--- .../binder/query_node/bind_select_node.cpp | 36 ++++---- .../planner/binder/query_node/plan_setop.cpp | 6 +- .../binder/query_node/plan_subquery.cpp | 4 +- .../planner/binder/statement/bind_create.cpp | 2 +- .../planner/binder/statement/bind_execute.cpp | 2 +- .../planner/binder/statement/bind_insert.cpp | 10 +-- .../binder/statement/bind_summarize.cpp | 2 +- .../planner/binder/statement/bind_update.cpp | 2 +- .../planner/binder/tableref/bind_pivot.cpp | 48 +++++------ .../planner/binder/tableref/bind_showref.cpp | 2 +- .../binder/tableref/bind_table_function.cpp | 15 ++-- .../planner/binder/tableref/plan_joinref.cpp | 27 +++--- .../src/planner/bound_parameter_map.cpp | 2 +- src/duckdb/src/planner/expression.cpp | 2 +- .../expression/bound_cast_expression.cpp | 10 +-- .../planner/expression/bound_expression.cpp | 2 +- .../expression/bound_parameter_expression.cpp | 4 +- src/duckdb/src/planner/expression_binder.cpp | 14 +-- .../expression_binder/aggregate_binder.cpp | 2 +- .../expression_binder/base_select_binder.cpp | 4 +- .../expression_binder/group_binder.cpp | 4 +- .../expression_binder/index_binder.cpp | 2 +- .../expression_binder/lateral_binder.cpp | 6 +- .../expression_binder/order_binder.cpp | 16 ++-- .../expression_binder/relation_binder.cpp | 2 +- .../expression_binder/select_bind_state.cpp | 4 +- .../table_function_binder.cpp | 2 +- .../expression_binder/update_binder.cpp | 2 +- .../src/planner/expression_iterator.cpp | 2 +- src/duckdb/src/planner/joinside.cpp | 6 +- .../src/planner/operator/logical_filter.cpp | 2 +- .../src/planner/operator/logical_join.cpp | 2 +- .../subquery/flatten_dependent_join.cpp | 4 +- .../rewrite_correlated_expressions.cpp | 4 +- src/duckdb/src/planner/table_binding.cpp | 14 +-- .../src/storage/compression/bitpacking.cpp | 1 - .../compression/dictionary/compression.cpp | 1 - src/duckdb/src/storage/compression/fsst.cpp | 1 - src/duckdb/src/storage/compression/rle.cpp | 1 - .../storage/compression/roaring/compress.cpp | 1 - src/duckdb/src/storage/compression/zstd.cpp | 3 +- .../storage/table/column_checkpoint_state.cpp | 12 +-- src/duckdb/src/storage/table/column_data.cpp | 10 +-- .../src/storage/table/column_segment.cpp | 16 +++- .../prepared_statement_verifier.cpp | 8 +- 197 files changed, 707 insertions(+), 617 deletions(-) diff --git a/src/duckdb/extension/core_functions/scalar/generic/alias.cpp b/src/duckdb/extension/core_functions/scalar/generic/alias.cpp index 88378778..4edadcaa 100644 --- a/src/duckdb/extension/core_functions/scalar/generic/alias.cpp +++ b/src/duckdb/extension/core_functions/scalar/generic/alias.cpp @@ -5,7 +5,7 @@ namespace duckdb { static void AliasFunction(DataChunk &args, ExpressionState &state, Vector &result) { auto &func_expr = state.expr.Cast(); - Value v(state.expr.alias.empty() ? func_expr.children[0]->GetName() : state.expr.alias); + Value v(state.expr.GetAlias().empty() ? func_expr.children[0]->GetName() : state.expr.GetAlias()); result.Reference(v); } diff --git a/src/duckdb/extension/core_functions/scalar/generic/least.cpp b/src/duckdb/extension/core_functions/scalar/generic/least.cpp index e9df9872..40a94310 100644 --- a/src/duckdb/extension/core_functions/scalar/generic/least.cpp +++ b/src/duckdb/extension/core_functions/scalar/generic/least.cpp @@ -179,7 +179,7 @@ unique_ptr BindLeastGreatest(ClientContext &context, ScalarFunctio for (idx_t i = 1; i < arguments.size(); i++) { auto arg_type = ExpressionBinder::GetExpressionReturnType(*arguments[i]); if (!LogicalType::TryGetMaxLogicalType(context, child_type, arg_type, child_type)) { - throw BinderException(arguments[i]->query_location, + throw BinderException(arguments[i]->GetQueryLocation(), "Cannot combine types of %s and %s - an explicit cast is required", child_type.ToString(), arg_type.ToString()); } diff --git a/src/duckdb/extension/core_functions/scalar/list/list_filter.cpp b/src/duckdb/extension/core_functions/scalar/list/list_filter.cpp index d8ab7cdd..30ac79db 100644 --- a/src/duckdb/extension/core_functions/scalar/list/list_filter.cpp +++ b/src/duckdb/extension/core_functions/scalar/list/list_filter.cpp @@ -10,7 +10,7 @@ static unique_ptr ListFilterBind(ClientContext &context, ScalarFun // the list column and the bound lambda expression D_ASSERT(arguments.size() == 2); - if (arguments[1]->expression_class != ExpressionClass::BOUND_LAMBDA) { + if (arguments[1]->GetExpressionClass() != ExpressionClass::BOUND_LAMBDA) { throw BinderException("Invalid lambda expression!"); } diff --git a/src/duckdb/extension/core_functions/scalar/list/list_reduce.cpp b/src/duckdb/extension/core_functions/scalar/list/list_reduce.cpp index 7a0ac4c5..f8758515 100644 --- a/src/duckdb/extension/core_functions/scalar/list/list_reduce.cpp +++ b/src/duckdb/extension/core_functions/scalar/list/list_reduce.cpp @@ -184,7 +184,7 @@ static unique_ptr ListReduceBind(ClientContext &context, ScalarFun // the list column and the bound lambda expression D_ASSERT(arguments.size() == 2); - if (arguments[1]->expression_class != ExpressionClass::BOUND_LAMBDA) { + if (arguments[1]->GetExpressionClass() != ExpressionClass::BOUND_LAMBDA) { throw BinderException("Invalid lambda expression!"); } diff --git a/src/duckdb/extension/core_functions/scalar/list/list_transform.cpp b/src/duckdb/extension/core_functions/scalar/list/list_transform.cpp index 69c8e5cc..26c6ad4b 100644 --- a/src/duckdb/extension/core_functions/scalar/list/list_transform.cpp +++ b/src/duckdb/extension/core_functions/scalar/list/list_transform.cpp @@ -10,7 +10,7 @@ static unique_ptr ListTransformBind(ClientContext &context, Scalar // the list column and the bound lambda expression D_ASSERT(arguments.size() == 2); - if (arguments[1]->expression_class != ExpressionClass::BOUND_LAMBDA) { + if (arguments[1]->GetExpressionClass() != ExpressionClass::BOUND_LAMBDA) { throw BinderException("Invalid lambda expression!"); } diff --git a/src/duckdb/extension/core_functions/scalar/list/list_value.cpp b/src/duckdb/extension/core_functions/scalar/list/list_value.cpp index 6600d7eb..01b342ec 100644 --- a/src/duckdb/extension/core_functions/scalar/list/list_value.cpp +++ b/src/duckdb/extension/core_functions/scalar/list/list_value.cpp @@ -156,10 +156,10 @@ static unique_ptr ListValueBind(ClientContext &context, ScalarFunc auto error = StringUtil::Format("Cannot unpivot columns of types %s and %s - an explicit cast is required", child_type.ToString(), arg_type.ToString()); - throw BinderException(arguments[i]->query_location, + throw BinderException(arguments[i]->GetQueryLocation(), QueryErrorContext::Format(list_arguments, error, error_index, false)); } else { - throw BinderException(arguments[i]->query_location, + throw BinderException(arguments[i]->GetQueryLocation(), "Cannot create a list of types %s and %s - an explicit cast is required", child_type.ToString(), arg_type.ToString()); } diff --git a/src/duckdb/extension/core_functions/scalar/struct/struct_insert.cpp b/src/duckdb/extension/core_functions/scalar/struct/struct_insert.cpp index e69c5f81..c83a83e3 100644 --- a/src/duckdb/extension/core_functions/scalar/struct/struct_insert.cpp +++ b/src/duckdb/extension/core_functions/scalar/struct/struct_insert.cpp @@ -58,14 +58,14 @@ static unique_ptr StructInsertBind(ClientContext &context, ScalarF // Loop through the additional arguments (name/value pairs) for (idx_t i = 1; i < arguments.size(); i++) { auto &child = arguments[i]; - if (child->alias.empty()) { + if (child->GetAlias().empty()) { throw BinderException("Need named argument for struct insert, e.g., a := b"); } - if (name_collision_set.find(child->alias) != name_collision_set.end()) { - throw BinderException("Duplicate struct entry name \"%s\"", child->alias); + if (name_collision_set.find(child->GetAlias()) != name_collision_set.end()) { + throw BinderException("Duplicate struct entry name \"%s\"", child->GetAlias()); } - name_collision_set.insert(child->alias); - new_children.push_back(make_pair(child->alias, arguments[i]->return_type)); + name_collision_set.insert(child->GetAlias()); + new_children.push_back(make_pair(child->GetAlias(), arguments[i]->return_type)); } bound_function.return_type = LogicalType::STRUCT(new_children); diff --git a/src/duckdb/extension/core_functions/scalar/union/union_value.cpp b/src/duckdb/extension/core_functions/scalar/union/union_value.cpp index 106b86dc..655003da 100644 --- a/src/duckdb/extension/core_functions/scalar/union/union_value.cpp +++ b/src/duckdb/extension/core_functions/scalar/union/union_value.cpp @@ -44,13 +44,13 @@ static unique_ptr UnionValueBind(ClientContext &context, ScalarFun } auto &child = arguments[0]; - if (child->alias.empty()) { + if (child->GetAlias().empty()) { throw BinderException("Need named argument for union tag, e.g. UNION_VALUE(a := b)"); } child_list_t union_members; - union_members.push_back(make_pair(child->alias, child->return_type)); + union_members.push_back(make_pair(child->GetAlias(), child->return_type)); bound_function.return_type = LogicalType::UNION(std::move(union_members)); return make_uniq(bound_function.return_type); diff --git a/src/duckdb/extension/json/json_functions/copy_json.cpp b/src/duckdb/extension/json/json_functions/copy_json.cpp index d6cdb847..cdd464d0 100644 --- a/src/duckdb/extension/json/json_functions/copy_json.cpp +++ b/src/duckdb/extension/json/json_functions/copy_json.cpp @@ -91,7 +91,7 @@ static BoundStatement CopyToJSONPlan(Binder &binder, CopyStatement &stmt) { strftime_children.emplace_back(make_uniq(timestamp_format)); column = make_uniq("strftime", std::move(strftime_children)); } - column->alias = name; + column->SetAlias(name); select_list.emplace_back(std::move(column)); } diff --git a/src/duckdb/extension/json/json_functions/json_serialize_plan.cpp b/src/duckdb/extension/json/json_functions/json_serialize_plan.cpp index 1fe6c8cf..7b14d679 100644 --- a/src/duckdb/extension/json/json_functions/json_serialize_plan.cpp +++ b/src/duckdb/extension/json/json_functions/json_serialize_plan.cpp @@ -63,33 +63,34 @@ static unique_ptr JsonSerializePlanBind(ClientContext &context, Sc if (!arg->IsFoldable()) { throw BinderException("json_serialize_plan: arguments must be constant"); } - if (arg->alias == "skip_null") { + auto &alias = arg->GetAlias(); + if (alias == "skip_null") { if (arg->return_type.id() != LogicalTypeId::BOOLEAN) { throw BinderException("json_serialize_plan: 'skip_null' argument must be a boolean"); } skip_if_null = BooleanValue::Get(ExpressionExecutor::EvaluateScalar(context, *arg)); - } else if (arg->alias == "skip_empty") { + } else if (alias == "skip_empty") { if (arg->return_type.id() != LogicalTypeId::BOOLEAN) { throw BinderException("json_serialize_plan: 'skip_empty' argument must be a boolean"); } skip_if_empty = BooleanValue::Get(ExpressionExecutor::EvaluateScalar(context, *arg)); - } else if (arg->alias == "skip_default") { + } else if (alias == "skip_default") { if (arg->return_type.id() != LogicalTypeId::BOOLEAN) { throw BinderException("json_serialize_plan: 'skip_default' argument must be a boolean"); } skip_if_default = BooleanValue::Get(ExpressionExecutor::EvaluateScalar(context, *arg)); - } else if (arg->alias == "format") { + } else if (alias == "format") { if (arg->return_type.id() != LogicalTypeId::BOOLEAN) { throw BinderException("json_serialize_plan: 'format' argument must be a boolean"); } format = BooleanValue::Get(ExpressionExecutor::EvaluateScalar(context, *arg)); - } else if (arg->alias == "optimize") { + } else if (alias == "optimize") { if (arg->return_type.id() != LogicalTypeId::BOOLEAN) { throw BinderException("json_serialize_plan: 'optimize' argument must be a boolean"); } optimize = BooleanValue::Get(ExpressionExecutor::EvaluateScalar(context, *arg)); } else { - throw BinderException(StringUtil::Format("json_serialize_plan: Unknown argument '%s'", arg->alias.c_str())); + throw BinderException(StringUtil::Format("json_serialize_plan: Unknown argument '%s'", alias)); } } return make_uniq(skip_if_null, skip_if_empty, skip_if_default, format, optimize); diff --git a/src/duckdb/extension/json/json_functions/json_serialize_sql.cpp b/src/duckdb/extension/json/json_functions/json_serialize_sql.cpp index 2873eba3..11a1b999 100644 --- a/src/duckdb/extension/json/json_functions/json_serialize_sql.cpp +++ b/src/duckdb/extension/json/json_functions/json_serialize_sql.cpp @@ -54,28 +54,29 @@ static unique_ptr JsonSerializeBind(ClientContext &context, Scalar if (!arg->IsFoldable()) { throw BinderException("json_serialize_sql: arguments must be constant"); } - if (arg->alias == "skip_null") { + auto &alias = arg->GetAlias(); + if (alias == "skip_null") { if (arg->return_type.id() != LogicalTypeId::BOOLEAN) { throw BinderException("json_serialize_sql: 'skip_null' argument must be a boolean"); } skip_if_null = BooleanValue::Get(ExpressionExecutor::EvaluateScalar(context, *arg)); - } else if (arg->alias == "skip_empty") { + } else if (alias == "skip_empty") { if (arg->return_type.id() != LogicalTypeId::BOOLEAN) { throw BinderException("json_serialize_sql: 'skip_empty' argument must be a boolean"); } skip_if_empty = BooleanValue::Get(ExpressionExecutor::EvaluateScalar(context, *arg)); - } else if (arg->alias == "format") { + } else if (alias == "format") { if (arg->return_type.id() != LogicalTypeId::BOOLEAN) { throw BinderException("json_serialize_sql: 'format' argument must be a boolean"); } format = BooleanValue::Get(ExpressionExecutor::EvaluateScalar(context, *arg)); - } else if (arg->alias == "skip_default") { + } else if (alias == "skip_default") { if (arg->return_type.id() != LogicalTypeId::BOOLEAN) { throw BinderException("json_serialize_sql: 'skip_default' argument must be a boolean"); } skip_if_default = BooleanValue::Get(ExpressionExecutor::EvaluateScalar(context, *arg)); } else { - throw BinderException(StringUtil::Format("json_serialize_sql: Unknown argument '%s'", arg->alias)); + throw BinderException(StringUtil::Format("json_serialize_sql: Unknown argument '%s'", alias)); } } return make_uniq(skip_if_null, skip_if_empty, skip_if_default, format); diff --git a/src/duckdb/extension/parquet/parquet_extension.cpp b/src/duckdb/extension/parquet/parquet_extension.cpp index 96e64793..1c9c09ec 100644 --- a/src/duckdb/extension/parquet/parquet_extension.cpp +++ b/src/duckdb/extension/parquet/parquet_extension.cpp @@ -1586,7 +1586,7 @@ static vector> ParquetWriteSelect(CopyToSelectInput &inpu for (auto &expr : input.select_list) { const auto &type = expr->return_type; - const auto &name = expr->alias; + const auto &name = expr->GetAlias(); // Spatial types need to be encoded into WKB when writing GeoParquet. // But dont perform this conversion if this is a EXPORT DATABASE statement @@ -1597,7 +1597,7 @@ static vector> ParquetWriteSelect(CopyToSelectInput &inpu wkb_blob_type.SetAlias("WKB_BLOB"); auto cast_expr = BoundCastExpression::AddCastToType(context, std::move(expr), wkb_blob_type, false); - cast_expr->alias = name; + cast_expr->SetAlias(name); result.push_back(std::move(cast_expr)); any_change = true; } @@ -1609,7 +1609,7 @@ static vector> ParquetWriteSelect(CopyToSelectInput &inpu // Cast the column to the new type auto cast_expr = BoundCastExpression::AddCastToType(context, std::move(expr), new_type, false); - cast_expr->alias = name; + cast_expr->SetAlias(name); result.push_back(std::move(cast_expr)); any_change = true; } @@ -1622,7 +1622,7 @@ static vector> ParquetWriteSelect(CopyToSelectInput &inpu }); auto cast_expr = BoundCastExpression::AddCastToType(context, std::move(expr), new_type, false); - cast_expr->alias = name; + cast_expr->SetAlias(name); result.push_back(std::move(cast_expr)); any_change = true; } diff --git a/src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp b/src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp index 6b7f72c5..4983710d 100644 --- a/src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp +++ b/src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp @@ -243,7 +243,7 @@ void DuckTableEntry::UndoAlter(ClientContext &context, AlterInfo &info) { } static void RenameExpression(ParsedExpression &expr, RenameColumnInfo &info) { - if (expr.type == ExpressionType::COLUMN_REF) { + if (expr.GetExpressionType() == ExpressionType::COLUMN_REF) { auto &colref = expr.Cast(); if (colref.column_names.back() == info.old_name) { colref.column_names.back() = info.new_name; diff --git a/src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp b/src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp index 4be35415..3070b2e3 100644 --- a/src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp +++ b/src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp @@ -148,7 +148,7 @@ string TableCatalogEntry::ColumnsToSQL(const ColumnList &columns, const vector(); D_ASSERT(cast_expr.cast_type.id() == column_type.id()); generated_expression = *cast_expr.child; diff --git a/src/duckdb/src/common/error_data.cpp b/src/duckdb/src/common/error_data.cpp index 59557efc..9cca3264 100644 --- a/src/duckdb/src/common/error_data.cpp +++ b/src/duckdb/src/common/error_data.cpp @@ -137,7 +137,7 @@ void ErrorData::AddQueryLocation(QueryErrorContext error_context) { } void ErrorData::AddQueryLocation(const ParsedExpression &ref) { - AddQueryLocation(ref.query_location); + AddQueryLocation(ref.GetQueryLocation()); } void ErrorData::AddQueryLocation(const TableRef &ref) { diff --git a/src/duckdb/src/common/exception.cpp b/src/duckdb/src/common/exception.cpp index 18722d6d..9b30eedb 100644 --- a/src/duckdb/src/common/exception.cpp +++ b/src/duckdb/src/common/exception.cpp @@ -169,11 +169,11 @@ ExceptionType Exception::StringToExceptionType(const string &type) { } unordered_map Exception::InitializeExtraInfo(const Expression &expr) { - return InitializeExtraInfo(expr.query_location); + return InitializeExtraInfo(expr.GetQueryLocation()); } unordered_map Exception::InitializeExtraInfo(const ParsedExpression &expr) { - return InitializeExtraInfo(expr.query_location); + return InitializeExtraInfo(expr.GetQueryLocation()); } unordered_map Exception::InitializeExtraInfo(const QueryErrorContext &error_context) { diff --git a/src/duckdb/src/common/exception/binder_exception.cpp b/src/duckdb/src/common/exception/binder_exception.cpp index 55db8386..cc4e0872 100644 --- a/src/duckdb/src/common/exception/binder_exception.cpp +++ b/src/duckdb/src/common/exception/binder_exception.cpp @@ -45,7 +45,7 @@ BinderException BinderException::NoMatchingFunction(const string &name, const ve } BinderException BinderException::Unsupported(ParsedExpression &expr, const string &message) { - auto extra_info = Exception::InitializeExtraInfo("UNSUPPORTED", expr.query_location); + auto extra_info = Exception::InitializeExtraInfo("UNSUPPORTED", expr.GetQueryLocation()); return BinderException(message, extra_info); } diff --git a/src/duckdb/src/common/hive_partitioning.cpp b/src/duckdb/src/common/hive_partitioning.cpp index 8ae9b685..c84d0505 100644 --- a/src/duckdb/src/common/hive_partitioning.cpp +++ b/src/duckdb/src/common/hive_partitioning.cpp @@ -51,7 +51,7 @@ GetKnownColumnValues(const string &filename, const HivePartitioningFilterInfo &f static void ConvertKnownColRefToConstants(ClientContext &context, unique_ptr &expr, const unordered_map &known_column_values, idx_t table_index) { - if (expr->type == ExpressionType::BOUND_COLUMN_REF) { + if (expr->GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { auto &bound_colref = expr->Cast(); // This bound column ref is for another table diff --git a/src/duckdb/src/execution/aggregate_hashtable.cpp b/src/duckdb/src/execution/aggregate_hashtable.cpp index 589fe4fb..8a2dd448 100644 --- a/src/duckdb/src/execution/aggregate_hashtable.cpp +++ b/src/duckdb/src/execution/aggregate_hashtable.cpp @@ -627,10 +627,17 @@ idx_t GroupedAggregateHashTable::FindOrCreateGroupsInternal(DataChunk &groups, V // and precompute the hash salts for faster comparison below const auto ht_offsets = FlatVector::GetData(state.ht_offsets); const auto hash_salts = FlatVector::GetData(state.hash_salts); + + // We also compute the occupied count, which is essentially useless. + // However, this loop is branchless, while the main lookup loop below is not. + // So, by doing the lookups here, we better amortize cache misses. + idx_t occupied_count = 0; for (idx_t r = 0; r < chunk_size; r++) { const auto &hash = hashes[r]; - ht_offsets[r] = ApplyBitMask(hash); - D_ASSERT(ht_offsets[r] == hash % capacity); + auto &ht_offset = ht_offsets[r]; + ht_offset = ApplyBitMask(hash); + occupied_count += entries[ht_offset].IsOccupied(); // Lookup + D_ASSERT(ht_offset == hash % capacity); hash_salts[r] = ht_entry_t::ExtractSalt(hash); } @@ -671,6 +678,13 @@ idx_t GroupedAggregateHashTable::FindOrCreateGroupsInternal(DataChunk &groups, V } } + if (DUCKDB_UNLIKELY(occupied_count > new_entry_count + need_compare_count)) { + // We use the useless occupied_count we summed above here so the variable is used, + // and the compiler cannot optimize away the vectorized lookups above. This should never be triggered. + throw InternalException("Internal validation failed in GroupedAggregateHashTable"); + } + occupied_count = 0; // Have to set to 0 for next iterations + if (new_entry_count != 0) { // Append everything that belongs to an empty group optional_ptr data; diff --git a/src/duckdb/src/execution/column_binding_resolver.cpp b/src/duckdb/src/execution/column_binding_resolver.cpp index 56838150..3a931a3f 100644 --- a/src/duckdb/src/execution/column_binding_resolver.cpp +++ b/src/duckdb/src/execution/column_binding_resolver.cpp @@ -156,13 +156,13 @@ unique_ptr ColumnBindingResolver::VisitReplace(BoundColumnRefExpress // in verification mode return nullptr; } - return make_uniq(expr.alias, expr.return_type, i); + return make_uniq(expr.GetAlias(), expr.return_type, i); } } // LCOV_EXCL_START // could not bind the column reference, this should never happen and indicates a bug in the code // generate an error message - throw InternalException("Failed to bind column reference \"%s\" [%d.%d] (bindings: %s)", expr.alias, + throw InternalException("Failed to bind column reference \"%s\" [%d.%d] (bindings: %s)", expr.GetAlias(), expr.binding.table_index, expr.binding.column_index, LogicalOperator::ColumnBindingsToString(bindings)); // LCOV_EXCL_STOP diff --git a/src/duckdb/src/execution/expression_executor.cpp b/src/duckdb/src/execution/expression_executor.cpp index 63a24f47..567deb32 100644 --- a/src/duckdb/src/execution/expression_executor.cpp +++ b/src/duckdb/src/execution/expression_executor.cpp @@ -141,7 +141,7 @@ void ExpressionExecutor::Verify(const Expression &expr, Vector &vector, idx_t co unique_ptr ExpressionExecutor::InitializeState(const Expression &expr, ExpressionExecutorState &state) { - switch (expr.expression_class) { + switch (expr.GetExpressionClass()) { case ExpressionClass::BOUND_REF: return InitializeState(expr.Cast(), state); case ExpressionClass::BOUND_BETWEEN: @@ -191,7 +191,7 @@ void ExpressionExecutor::Execute(const Expression &expr, ExpressionState *state, "ExpressionExecutor::Execute called with a result vector of type %s that does not match expression type %s", result.GetType(), expr.return_type); } - switch (expr.expression_class) { + switch (expr.GetExpressionClass()) { case ExpressionClass::BOUND_BETWEEN: Execute(expr.Cast(), state, sel, count, result); break; @@ -235,7 +235,7 @@ idx_t ExpressionExecutor::Select(const Expression &expr, ExpressionState *state, } D_ASSERT(true_sel || false_sel); D_ASSERT(expr.return_type.id() == LogicalTypeId::BOOLEAN); - switch (expr.expression_class) { + switch (expr.GetExpressionClass()) { #ifndef DUCKDB_SMALLER_BINARY case ExpressionClass::BOUND_BETWEEN: return Select(expr.Cast(), state, sel, count, true_sel, false_sel); diff --git a/src/duckdb/src/execution/expression_executor/execute_cast.cpp b/src/duckdb/src/execution/expression_executor/execute_cast.cpp index eb3a93fc..0627dcf5 100644 --- a/src/duckdb/src/execution/expression_executor/execute_cast.cpp +++ b/src/duckdb/src/execution/expression_executor/execute_cast.cpp @@ -33,13 +33,13 @@ void ExpressionExecutor::Execute(const BoundCastExpression &expr, ExpressionStat if (expr.try_cast) { string error_message; CastParameters parameters(expr.bound_cast.cast_data.get(), false, &error_message, lstate); - parameters.query_location = expr.query_location; + parameters.query_location = expr.GetQueryLocation(); expr.bound_cast.function(child, result, count, parameters); } else { // cast it to the type specified by the cast expression D_ASSERT(result.GetType() == expr.return_type); CastParameters parameters(expr.bound_cast.cast_data.get(), false, nullptr, lstate); - parameters.query_location = expr.query_location; + parameters.query_location = expr.GetQueryLocation(); expr.bound_cast.function(child, result, count, parameters); } } diff --git a/src/duckdb/src/execution/expression_executor/execute_comparison.cpp b/src/duckdb/src/execution/expression_executor/execute_comparison.cpp index 949bc7ab..6e78de49 100644 --- a/src/duckdb/src/execution/expression_executor/execute_comparison.cpp +++ b/src/duckdb/src/execution/expression_executor/execute_comparison.cpp @@ -29,7 +29,7 @@ void ExpressionExecutor::Execute(const BoundComparisonExpression &expr, Expressi Execute(*expr.left, state->child_states[0].get(), sel, count, left); Execute(*expr.right, state->child_states[1].get(), sel, count, right); - switch (expr.type) { + switch (expr.GetExpressionType()) { case ExpressionType::COMPARE_EQUAL: VectorOperations::Equals(left, right, result, count); break; @@ -357,7 +357,7 @@ idx_t ExpressionExecutor::Select(const BoundComparisonExpression &expr, Expressi Execute(*expr.left, state->child_states[0].get(), sel, count, left); Execute(*expr.right, state->child_states[1].get(), sel, count, right); - switch (expr.type) { + switch (expr.GetExpressionType()) { case ExpressionType::COMPARE_EQUAL: return VectorOperations::Equals(left, right, sel, count, true_sel, false_sel); case ExpressionType::COMPARE_NOTEQUAL: diff --git a/src/duckdb/src/execution/expression_executor/execute_conjunction.cpp b/src/duckdb/src/execution/expression_executor/execute_conjunction.cpp index 8ea55d63..1b2bc3a4 100644 --- a/src/duckdb/src/execution/expression_executor/execute_conjunction.cpp +++ b/src/duckdb/src/execution/expression_executor/execute_conjunction.cpp @@ -38,7 +38,7 @@ void ExpressionExecutor::Execute(const BoundConjunctionExpression &expr, Express } else { Vector intermediate(LogicalType::BOOLEAN); // AND/OR together - switch (expr.type) { + switch (expr.GetExpressionType()) { case ExpressionType::CONJUNCTION_AND: VectorOperations::And(current_result, result, intermediate, count); break; @@ -58,7 +58,7 @@ idx_t ExpressionExecutor::Select(const BoundConjunctionExpression &expr, Express SelectionVector *false_sel) { auto &state = state_p->Cast(); - if (expr.type == ExpressionType::CONJUNCTION_AND) { + if (expr.GetExpressionType() == ExpressionType::CONJUNCTION_AND) { // get runtime statistics auto filter_state = state.adaptive_filter->BeginFilter(); const SelectionVector *current_sel = sel; diff --git a/src/duckdb/src/execution/expression_executor/execute_operator.cpp b/src/duckdb/src/execution/expression_executor/execute_operator.cpp index 7db87478..b543679e 100644 --- a/src/duckdb/src/execution/expression_executor/execute_operator.cpp +++ b/src/duckdb/src/execution/expression_executor/execute_operator.cpp @@ -19,7 +19,8 @@ void ExpressionExecutor::Execute(const BoundOperatorExpression &expr, Expression const SelectionVector *sel, idx_t count, Vector &result) { // special handling for special snowflake 'IN' // IN has n children - if (expr.type == ExpressionType::COMPARE_IN || expr.type == ExpressionType::COMPARE_NOT_IN) { + if (expr.GetExpressionType() == ExpressionType::COMPARE_IN || + expr.GetExpressionType() == ExpressionType::COMPARE_NOT_IN) { if (expr.children.size() < 2) { throw InvalidInputException("IN needs at least two children"); } @@ -53,14 +54,14 @@ void ExpressionExecutor::Execute(const BoundOperatorExpression &expr, Expression intermediate.Reference(new_result); } } - if (expr.type == ExpressionType::COMPARE_NOT_IN) { + if (expr.GetExpressionType() == ExpressionType::COMPARE_NOT_IN) { // NOT IN: invert result VectorOperations::Not(intermediate, result, count); } else { // directly use the result result.Reference(intermediate); } - } else if (expr.type == ExpressionType::OPERATOR_COALESCE) { + } else if (expr.GetExpressionType() == ExpressionType::OPERATOR_COALESCE) { SelectionVector sel_a(count); SelectionVector sel_b(count); SelectionVector slice_sel(count); @@ -115,7 +116,7 @@ void ExpressionExecutor::Execute(const BoundOperatorExpression &expr, Expression auto &child = state->intermediate_chunk.data[0]; Execute(*expr.children[0], state->child_states[0].get(), sel, count, child); - switch (expr.type) { + switch (expr.GetExpressionType()) { case ExpressionType::OPERATOR_NOT: { VectorOperations::Not(child, result, count); break; diff --git a/src/duckdb/src/execution/index/art/art.cpp b/src/duckdb/src/execution/index/art/art.cpp index 4848c48f..1a3cada7 100644 --- a/src/duckdb/src/execution/index/art/art.cpp +++ b/src/duckdb/src/execution/index/art/art.cpp @@ -155,9 +155,9 @@ unique_ptr ART::TryInitializeScan(const Expression &expr, const // bindings[2] = the constant auto &comparison = bindings[0].get().Cast(); auto constant_value = bindings[2].get().Cast().value; - auto comparison_type = comparison.type; + auto comparison_type = comparison.GetExpressionType(); - if (comparison.left->type == ExpressionType::VALUE_CONSTANT) { + if (comparison.left->GetExpressionType() == ExpressionType::VALUE_CONSTANT) { // The expression is on the right side, we flip the comparison expression. comparison_type = FlipComparisonExpression(comparison_type); } @@ -176,15 +176,15 @@ unique_ptr ART::TryInitializeScan(const Expression &expr, const high_comparison_type = comparison_type; } - } else if (filter_expr.type == ExpressionType::COMPARE_BETWEEN) { + } else if (filter_expr.GetExpressionType() == ExpressionType::COMPARE_BETWEEN) { auto &between = filter_expr.Cast(); if (!between.input->Equals(expr)) { // The expression does not match the index expression. return nullptr; } - if (between.lower->type != ExpressionType::VALUE_CONSTANT || - between.upper->type != ExpressionType::VALUE_CONSTANT) { + if (between.lower->GetExpressionType() != ExpressionType::VALUE_CONSTANT || + between.upper->GetExpressionType() != ExpressionType::VALUE_CONSTANT) { // Not a constant expression. return nullptr; } diff --git a/src/duckdb/src/execution/index/bound_index.cpp b/src/duckdb/src/execution/index/bound_index.cpp index 2437e3d4..199cc4bd 100644 --- a/src/duckdb/src/execution/index/bound_index.cpp +++ b/src/duckdb/src/execution/index/bound_index.cpp @@ -110,7 +110,7 @@ void BoundIndex::ExecuteExpressions(DataChunk &input, DataChunk &result) { } unique_ptr BoundIndex::BindExpression(unique_ptr expr) { - if (expr->type == ExpressionType::BOUND_COLUMN_REF) { + if (expr->GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { auto &bound_colref = expr->Cast(); return make_uniq(expr->return_type, column_ids[bound_colref.binding.column_index]); } diff --git a/src/duckdb/src/execution/operator/aggregate/grouped_aggregate_data.cpp b/src/duckdb/src/execution/operator/aggregate/grouped_aggregate_data.cpp index d0b52a60..088a0f59 100644 --- a/src/duckdb/src/execution/operator/aggregate/grouped_aggregate_data.cpp +++ b/src/duckdb/src/execution/operator/aggregate/grouped_aggregate_data.cpp @@ -20,7 +20,7 @@ void GroupedAggregateData::InitializeGroupby(vector> grou filter_count = 0; for (auto &expr : expressions) { - D_ASSERT(expr->expression_class == ExpressionClass::BOUND_AGGREGATE); + D_ASSERT(expr->GetExpressionClass() == ExpressionClass::BOUND_AGGREGATE); D_ASSERT(expr->IsAggregate()); auto &aggr = expr->Cast(); bindings.push_back(&aggr); diff --git a/src/duckdb/src/execution/operator/aggregate/physical_hash_aggregate.cpp b/src/duckdb/src/execution/operator/aggregate/physical_hash_aggregate.cpp index 5459674b..6636389e 100644 --- a/src/duckdb/src/execution/operator/aggregate/physical_hash_aggregate.cpp +++ b/src/duckdb/src/execution/operator/aggregate/physical_hash_aggregate.cpp @@ -75,7 +75,7 @@ static vector CreateGroupChunkTypes(vector> } for (auto &group : groups) { - D_ASSERT(group->type == ExpressionType::BOUND_REF); + D_ASSERT(group->GetExpressionType() == ExpressionType::BOUND_REF); auto &bound_ref = group->Cast(); group_indices.insert(bound_ref.index); } @@ -366,7 +366,7 @@ SinkResultType PhysicalHashAggregate::Sink(ExecutionContext &context, DataChunk for (auto &aggregate : aggregates) { auto &aggr = aggregate->Cast(); for (auto &child_expr : aggr.children) { - D_ASSERT(child_expr->type == ExpressionType::BOUND_REF); + D_ASSERT(child_expr->GetExpressionType() == ExpressionType::BOUND_REF); auto &bound_ref_expr = child_expr->Cast(); D_ASSERT(bound_ref_expr.index < chunk.data.size()); aggregate_input_chunk.data[aggregate_input_idx++].Reference(chunk.data[bound_ref_expr.index]); diff --git a/src/duckdb/src/execution/operator/aggregate/physical_perfecthash_aggregate.cpp b/src/duckdb/src/execution/operator/aggregate/physical_perfecthash_aggregate.cpp index 778e5e67..d00b6fd9 100644 --- a/src/duckdb/src/execution/operator/aggregate/physical_perfecthash_aggregate.cpp +++ b/src/duckdb/src/execution/operator/aggregate/physical_perfecthash_aggregate.cpp @@ -29,7 +29,7 @@ PhysicalPerfectHashAggregate::PhysicalPerfectHashAggregate(ClientContext &contex vector bindings; vector payload_types_filters; for (auto &expr : aggregates) { - D_ASSERT(expr->expression_class == ExpressionClass::BOUND_AGGREGATE); + D_ASSERT(expr->GetExpressionClass() == ExpressionClass::BOUND_AGGREGATE); D_ASSERT(expr->IsAggregate()); auto &aggr = expr->Cast(); bindings.push_back(&aggr); @@ -122,7 +122,7 @@ SinkResultType PhysicalPerfectHashAggregate::Sink(ExecutionContext &context, Dat for (idx_t group_idx = 0; group_idx < groups.size(); group_idx++) { auto &group = groups[group_idx]; - D_ASSERT(group->type == ExpressionType::BOUND_REF); + D_ASSERT(group->GetExpressionType() == ExpressionType::BOUND_REF); auto &bound_ref_expr = group->Cast(); group_chunk.data[group_idx].Reference(chunk.data[bound_ref_expr.index]); } @@ -130,7 +130,7 @@ SinkResultType PhysicalPerfectHashAggregate::Sink(ExecutionContext &context, Dat for (auto &aggregate : aggregates) { auto &aggr = aggregate->Cast(); for (auto &child_expr : aggr.children) { - D_ASSERT(child_expr->type == ExpressionType::BOUND_REF); + D_ASSERT(child_expr->GetExpressionType() == ExpressionType::BOUND_REF); auto &bound_ref_expr = child_expr->Cast(); aggregate_input_chunk.data[aggregate_input_idx++].Reference(chunk.data[bound_ref_expr.index]); } diff --git a/src/duckdb/src/execution/operator/aggregate/physical_streaming_window.cpp b/src/duckdb/src/execution/operator/aggregate/physical_streaming_window.cpp index 903247e7..c9c8141d 100644 --- a/src/duckdb/src/execution/operator/aggregate/physical_streaming_window.cpp +++ b/src/duckdb/src/execution/operator/aggregate/physical_streaming_window.cpp @@ -129,7 +129,7 @@ class StreamingWindowState : public OperatorState { } // We can only support LEAD and LAG values within one standard vector - if (wexpr.type == ExpressionType::WINDOW_LEAD) { + if (wexpr.GetExpressionType() == ExpressionType::WINDOW_LEAD) { offset = -offset; } return idx_t(std::abs(offset)) < MAX_BUFFER; @@ -336,7 +336,7 @@ bool PhysicalStreamingWindow::IsStreamingFunction(ClientContext &context, unique wexpr.exclude_clause != WindowExcludeMode::NO_OTHER) { return false; } - switch (wexpr.type) { + switch (wexpr.GetExpressionType()) { // TODO: add more expression types here? case ExpressionType::WINDOW_AGGREGATE: // We can stream aggregates if they are "running totals" diff --git a/src/duckdb/src/execution/operator/aggregate/physical_window.cpp b/src/duckdb/src/execution/operator/aggregate/physical_window.cpp index 4beef863..a85b74a4 100644 --- a/src/duckdb/src/execution/operator/aggregate/physical_window.cpp +++ b/src/duckdb/src/execution/operator/aggregate/physical_window.cpp @@ -190,7 +190,7 @@ PhysicalWindow::PhysicalWindow(vector types, vectorexpression_class == ExpressionClass::BOUND_WINDOW); + D_ASSERT(expr->GetExpressionClass() == ExpressionClass::BOUND_WINDOW); auto &bound_window = expr->Cast(); if (bound_window.partitions.empty() && bound_window.orders.empty()) { is_order_dependent = true; @@ -205,7 +205,7 @@ PhysicalWindow::PhysicalWindow(vector types, vector WindowExecutorFactory(BoundWindowExpression &wexpr, ClientContext &context, WindowSharedExpressions &shared, WindowAggregationMode mode) { - switch (wexpr.type) { + switch (wexpr.GetExpressionType()) { case ExpressionType::WINDOW_AGGREGATE: return make_uniq(wexpr, context, shared, mode); case ExpressionType::WINDOW_ROW_NUMBER: @@ -231,7 +231,7 @@ static unique_ptr WindowExecutorFactory(BoundWindowExpression &w return make_uniq(wexpr, context, shared); break; default: - throw InternalException("Window aggregate type %s", ExpressionTypeToString(wexpr.type)); + throw InternalException("Window aggregate type %s", ExpressionTypeToString(wexpr.GetExpressionType())); } } diff --git a/src/duckdb/src/execution/operator/persistent/physical_update.cpp b/src/duckdb/src/execution/operator/persistent/physical_update.cpp index fadb1514..88d30c5e 100644 --- a/src/duckdb/src/execution/operator/persistent/physical_update.cpp +++ b/src/duckdb/src/execution/operator/persistent/physical_update.cpp @@ -117,12 +117,12 @@ SinkResultType PhysicalUpdate::Sink(ExecutionContext &context, DataChunk &chunk, for (idx_t i = 0; i < expressions.size(); i++) { // Default expression, set to the default value of the column. - if (expressions[i]->type == ExpressionType::VALUE_DEFAULT) { + if (expressions[i]->GetExpressionType() == ExpressionType::VALUE_DEFAULT) { l_state.default_executor.ExecuteExpression(columns[i].index, update_chunk.data[i]); continue; } - D_ASSERT(expressions[i]->type == ExpressionType::BOUND_REF); + D_ASSERT(expressions[i]->GetExpressionType() == ExpressionType::BOUND_REF); auto &binding = expressions[i]->Cast(); update_chunk.data[i].Reference(chunk.data[binding.index]); } @@ -174,6 +174,7 @@ SinkResultType PhysicalUpdate::Sink(ExecutionContext &context, DataChunk &chunk, } auto &delete_chunk = index_update ? l_state.delete_chunk : l_state.mock_chunk; + delete_chunk.Reset(); delete_chunk.SetCardinality(update_count); if (index_update) { diff --git a/src/duckdb/src/execution/operator/projection/physical_unnest.cpp b/src/duckdb/src/execution/operator/projection/physical_unnest.cpp index b964d91f..4f32fd29 100644 --- a/src/duckdb/src/execution/operator/projection/physical_unnest.cpp +++ b/src/duckdb/src/execution/operator/projection/physical_unnest.cpp @@ -19,7 +19,7 @@ class UnnestOperatorState : public OperatorState { // and set the return type in the list_data chunk, which will contain the evaluated expression results vector list_data_types; for (auto &exp : select_list) { - D_ASSERT(exp->type == ExpressionType::BOUND_UNNEST); + D_ASSERT(exp->GetExpressionType() == ExpressionType::BOUND_UNNEST); auto &bue = exp->Cast(); list_data_types.push_back(bue.child->return_type); executor.AddExpression(*bue.child.get()); diff --git a/src/duckdb/src/execution/physical_plan/plan_aggregate.cpp b/src/duckdb/src/execution/physical_plan/plan_aggregate.cpp index e0ce831c..c61781a3 100644 --- a/src/duckdb/src/execution/physical_plan/plan_aggregate.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_aggregate.cpp @@ -46,7 +46,7 @@ static bool CanUsePartitionedAggregate(ClientContext &context, LogicalAggregate // figure out the columns we are grouping by for (auto &group_expr : op.groups) { // only support bound reference here - if (group_expr->type != ExpressionType::BOUND_REF) { + if (group_expr->GetExpressionType() != ExpressionType::BOUND_REF) { return false; } auto &ref = group_expr->Cast(); @@ -64,7 +64,7 @@ static bool CanUsePartitionedAggregate(ClientContext &context, LogicalAggregate for (auto &partition_col : partition_columns) { // we only support bound reference here auto &expr = projection.select_list[partition_col]; - if (expr->type != ExpressionType::BOUND_REF) { + if (expr->GetExpressionType() != ExpressionType::BOUND_REF) { return false; } auto &ref = expr->Cast(); diff --git a/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp b/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp index 8d1117c9..e8d31051 100644 --- a/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp @@ -18,7 +18,7 @@ namespace duckdb { static void RewriteJoinCondition(Expression &expr, idx_t offset) { - if (expr.type == ExpressionType::BOUND_REF) { + if (expr.GetExpressionType() == ExpressionType::BOUND_REF) { auto &ref = expr.Cast(); ref.index += offset; } diff --git a/src/duckdb/src/execution/physical_plan/plan_delete.cpp b/src/duckdb/src/execution/physical_plan/plan_delete.cpp index 7550da08..d6afee80 100644 --- a/src/duckdb/src/execution/physical_plan/plan_delete.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_delete.cpp @@ -21,7 +21,7 @@ unique_ptr DuckCatalog::PlanDelete(ClientContext &context, Log unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalDelete &op) { D_ASSERT(op.children.size() == 1); D_ASSERT(op.expressions.size() == 1); - D_ASSERT(op.expressions[0]->type == ExpressionType::BOUND_REF); + D_ASSERT(op.expressions[0]->GetExpressionType() == ExpressionType::BOUND_REF); auto plan = CreatePlan(*op.children[0]); diff --git a/src/duckdb/src/execution/physical_plan/plan_delim_join.cpp b/src/duckdb/src/execution/physical_plan/plan_delim_join.cpp index e545586c..9755f833 100644 --- a/src/duckdb/src/execution/physical_plan/plan_delim_join.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_delim_join.cpp @@ -42,7 +42,7 @@ unique_ptr PhysicalPlanGenerator::PlanDelimJoin(LogicalCompari vector delim_types; vector> distinct_groups, distinct_expressions; for (auto &delim_expr : op.duplicate_eliminated_columns) { - D_ASSERT(delim_expr->type == ExpressionType::BOUND_REF); + D_ASSERT(delim_expr->GetExpressionType() == ExpressionType::BOUND_REF); auto &bound_ref = delim_expr->Cast(); delim_types.push_back(bound_ref.return_type); distinct_groups.push_back(make_uniq(bound_ref.return_type, bound_ref.index)); diff --git a/src/duckdb/src/execution/physical_plan/plan_distinct.cpp b/src/duckdb/src/execution/physical_plan/plan_distinct.cpp index 1eee79c8..60fdb658 100644 --- a/src/duckdb/src/execution/physical_plan/plan_distinct.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_distinct.cpp @@ -25,7 +25,7 @@ unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalDistinct & // creates one group per distinct_target for (idx_t i = 0; i < distinct_targets.size(); i++) { auto &target = distinct_targets[i]; - if (target->type == ExpressionType::BOUND_REF) { + if (target->GetExpressionType() == ExpressionType::BOUND_REF) { auto &bound_ref = target->Cast(); group_by_references[bound_ref.index] = i; } @@ -69,7 +69,7 @@ unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalDistinct & auto new_expr = OrderedAggregateOptimizer::Apply(context, *first_aggregate, groups, changes_made); if (new_expr) { D_ASSERT(new_expr->return_type == first_aggregate->return_type); - D_ASSERT(new_expr->type == ExpressionType::BOUND_AGGREGATE); + D_ASSERT(new_expr->GetExpressionType() == ExpressionType::BOUND_AGGREGATE); first_aggregate = unique_ptr_cast(std::move(new_expr)); } } diff --git a/src/duckdb/src/execution/physical_plan/plan_projection.cpp b/src/duckdb/src/execution/physical_plan/plan_projection.cpp index 76fb36df..f5f262f5 100644 --- a/src/duckdb/src/execution/physical_plan/plan_projection.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_projection.cpp @@ -21,7 +21,7 @@ unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalProjection // e.g. PROJECTION(#0, #1, #2, #3, ...) bool omit_projection = true; for (idx_t i = 0; i < op.types.size(); i++) { - if (op.expressions[i]->type == ExpressionType::BOUND_REF) { + if (op.expressions[i]->GetExpressionType() == ExpressionType::BOUND_REF) { auto &bound_ref = op.expressions[i]->Cast(); if (bound_ref.index == i) { continue; diff --git a/src/duckdb/src/execution/radix_partitioned_hashtable.cpp b/src/duckdb/src/execution/radix_partitioned_hashtable.cpp index cfd92655..cf6038fa 100644 --- a/src/duckdb/src/execution/radix_partitioned_hashtable.cpp +++ b/src/duckdb/src/execution/radix_partitioned_hashtable.cpp @@ -365,7 +365,7 @@ void RadixPartitionedHashTable::PopulateGroupChunk(DataChunk &group_chunk, DataC for (auto &group_idx : grouping_set) { // Retrieve the expression containing the index in the input chunk auto &group = op.groups[group_idx]; - D_ASSERT(group->type == ExpressionType::BOUND_REF); + D_ASSERT(group->GetExpressionType() == ExpressionType::BOUND_REF); auto &bound_ref_expr = group->Cast(); // Reference from input_chunk[group.index] -> group_chunk[chunk_index] group_chunk.data[chunk_index++].Reference(input_chunk.data[bound_ref_expr.index]); diff --git a/src/duckdb/src/function/macro_function.cpp b/src/duckdb/src/function/macro_function.cpp index cb9313b0..d70150c8 100644 --- a/src/duckdb/src/function/macro_function.cpp +++ b/src/duckdb/src/function/macro_function.cpp @@ -43,12 +43,12 @@ MacroBindResult MacroFunction::BindMacroFunction(const vector> &defaults) { // separate positional and default arguments for (auto &arg : function_expr.children) { - if (!arg->alias.empty()) { + if (!arg->GetAlias().empty()) { // default argument - if (defaults.count(arg->alias)) { - return MacroBindResult(StringUtil::Format("Duplicate default parameters %s!", arg->alias)); + if (defaults.count(arg->GetAlias())) { + return MacroBindResult(StringUtil::Format("Duplicate default parameters %s!", arg->GetAlias())); } - defaults[arg->alias] = std::move(arg); + defaults[arg->GetAlias()] = std::move(arg); } else if (!defaults.empty()) { return MacroBindResult("Positional parameters cannot come after parameters with a default value!"); } else { diff --git a/src/duckdb/src/function/scalar/struct/struct_pack.cpp b/src/duckdb/src/function/scalar/struct/struct_pack.cpp index 1cc0c637..51a3e34c 100644 --- a/src/duckdb/src/function/scalar/struct/struct_pack.cpp +++ b/src/duckdb/src/function/scalar/struct/struct_pack.cpp @@ -43,10 +43,10 @@ static unique_ptr StructPackBind(ClientContext &context, ScalarFun auto &child = arguments[i]; string alias; if (IS_STRUCT_PACK) { - if (child->alias.empty()) { + if (child->GetAlias().empty()) { throw BinderException("Need named argument for struct pack, e.g. STRUCT_PACK(a := b)"); } - alias = child->alias; + alias = child->GetAlias(); if (name_collision_set.find(alias) != name_collision_set.end()) { throw BinderException("Duplicate struct entry name \"%s\"", alias); } diff --git a/src/duckdb/src/function/scalar/system/aggregate_export.cpp b/src/duckdb/src/function/scalar/system/aggregate_export.cpp index 90d94dcb..64fee3e8 100644 --- a/src/duckdb/src/function/scalar/system/aggregate_export.cpp +++ b/src/duckdb/src/function/scalar/system/aggregate_export.cpp @@ -267,7 +267,7 @@ static void ExportAggregateFinalize(Vector &state, AggregateInputData &aggr_inpu } ExportAggregateFunctionBindData::ExportAggregateFunctionBindData(unique_ptr aggregate_p) { - D_ASSERT(aggregate_p->type == ExpressionType::BOUND_AGGREGATE); + D_ASSERT(aggregate_p->GetExpressionType() == ExpressionType::BOUND_AGGREGATE); aggregate = unique_ptr_cast(std::move(aggregate_p)); } diff --git a/src/duckdb/src/function/table/system/duckdb_functions.cpp b/src/duckdb/src/function/table/system/duckdb_functions.cpp index 2fef5c55..4ed87e52 100644 --- a/src/duckdb/src/function/table/system/duckdb_functions.cpp +++ b/src/duckdb/src/function/table/system/duckdb_functions.cpp @@ -248,7 +248,7 @@ struct MacroExtractor { vector results; auto ¯o_entry = *entry.macros[offset]; for (auto ¶m : macro_entry.parameters) { - D_ASSERT(param->type == ExpressionType::COLUMN_REF); + D_ASSERT(param->GetExpressionType() == ExpressionType::COLUMN_REF); auto &colref = param->Cast(); results.emplace_back(colref.GetColumnName()); } @@ -319,7 +319,7 @@ struct TableMacroExtractor { vector results; auto ¯o_entry = *entry.macros[offset]; for (auto ¶m : macro_entry.parameters) { - D_ASSERT(param->type == ExpressionType::COLUMN_REF); + D_ASSERT(param->GetExpressionType() == ExpressionType::COLUMN_REF); auto &colref = param->Cast(); results.emplace_back(colref.GetColumnName()); } diff --git a/src/duckdb/src/function/table/table_scan.cpp b/src/duckdb/src/function/table/table_scan.cpp index de0bf4a1..30f809a8 100644 --- a/src/duckdb/src/function/table/table_scan.cpp +++ b/src/duckdb/src/function/table/table_scan.cpp @@ -295,7 +295,7 @@ static void IndexScanFunction(ClientContext &context, TableFunctionInput &data_p } static void RewriteIndexExpression(Index &index, LogicalGet &get, Expression &expr, bool &rewrite_possible) { - if (expr.type == ExpressionType::BOUND_COLUMN_REF) { + if (expr.GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { auto &bound_colref = expr.Cast(); // bound column ref: rewrite to fit in the current set of bound column ids bound_colref.binding.table_index = get.table_index; diff --git a/src/duckdb/src/function/table/version/pragma_version.cpp b/src/duckdb/src/function/table/version/pragma_version.cpp index db108455..088c82dd 100644 --- a/src/duckdb/src/function/table/version/pragma_version.cpp +++ b/src/duckdb/src/function/table/version/pragma_version.cpp @@ -1,5 +1,5 @@ #ifndef DUCKDB_PATCH_VERSION -#define DUCKDB_PATCH_VERSION "4-dev3637" +#define DUCKDB_PATCH_VERSION "4-dev3666" #endif #ifndef DUCKDB_MINOR_VERSION #define DUCKDB_MINOR_VERSION 1 @@ -8,10 +8,10 @@ #define DUCKDB_MAJOR_VERSION 1 #endif #ifndef DUCKDB_VERSION -#define DUCKDB_VERSION "v1.1.4-dev3637" +#define DUCKDB_VERSION "v1.1.4-dev3666" #endif #ifndef DUCKDB_SOURCE_ID -#define DUCKDB_SOURCE_ID "98a26e9ea1" +#define DUCKDB_SOURCE_ID "35939c850f" #endif #include "duckdb/function/table/system_functions.hpp" #include "duckdb/main/database.hpp" diff --git a/src/duckdb/src/function/window/window_boundaries_state.cpp b/src/duckdb/src/function/window/window_boundaries_state.cpp index 915bc85f..f0f65bbe 100644 --- a/src/duckdb/src/function/window/window_boundaries_state.cpp +++ b/src/duckdb/src/function/window/window_boundaries_state.cpp @@ -299,7 +299,7 @@ WindowBoundsSet WindowBoundariesState::GetWindowBounds(const BoundWindowExpressi const auto order_count = wexpr.orders.size(); WindowBoundsSet result; - switch (wexpr.type) { + switch (wexpr.GetExpressionType()) { case ExpressionType::WINDOW_ROW_NUMBER: result.insert(PARTITION_BEGIN); break; @@ -377,7 +377,7 @@ WindowBoundsSet WindowBoundariesState::GetWindowBounds(const BoundWindowExpressi } break; default: - throw InternalException("Window aggregate type %s", ExpressionTypeToString(wexpr.type)); + throw InternalException("Window aggregate type %s", ExpressionTypeToString(wexpr.GetExpressionType())); } // Internal dependencies @@ -405,9 +405,9 @@ WindowBoundsSet WindowBoundariesState::GetWindowBounds(const BoundWindowExpressi } WindowBoundariesState::WindowBoundariesState(const BoundWindowExpression &wexpr, const idx_t input_size) - : required(GetWindowBounds(wexpr)), type(wexpr.type), input_size(input_size), start_boundary(wexpr.start), - end_boundary(wexpr.end), partition_count(wexpr.partitions.size()), order_count(wexpr.orders.size()), - range_sense(wexpr.orders.empty() ? OrderType::INVALID : wexpr.orders[0].type), + : required(GetWindowBounds(wexpr)), type(wexpr.GetExpressionType()), input_size(input_size), + start_boundary(wexpr.start), end_boundary(wexpr.end), partition_count(wexpr.partitions.size()), + order_count(wexpr.orders.size()), range_sense(wexpr.orders.empty() ? OrderType::INVALID : wexpr.orders[0].type), has_preceding_range(HasPrecedingRange(wexpr)), has_following_range(HasFollowingRange(wexpr)) { } diff --git a/src/duckdb/src/function/window/window_value_function.cpp b/src/duckdb/src/function/window/window_value_function.cpp index 0c064283..ca506ee4 100644 --- a/src/duckdb/src/function/window/window_value_function.cpp +++ b/src/duckdb/src/function/window/window_value_function.cpp @@ -266,7 +266,7 @@ void WindowLeadLagExecutor::EvaluateInternal(WindowExecutorGlobalState &gstate, offset = leadlag_offset.GetCell(i); } int64_t val_idx = (int64_t)row_idx; - if (wexpr.type == ExpressionType::WINDOW_LEAD) { + if (wexpr.GetExpressionType() == ExpressionType::WINDOW_LEAD) { val_idx = AddOperatorOverflowCheck::Operation(val_idx, offset); } else { val_idx = SubtractOperatorOverflowCheck::Operation(val_idx, offset); diff --git a/src/duckdb/src/include/duckdb/function/table/read_csv.hpp b/src/duckdb/src/include/duckdb/function/table/read_csv.hpp index de60ed4d..67ab686b 100644 --- a/src/duckdb/src/include/duckdb/function/table/read_csv.hpp +++ b/src/duckdb/src/include/duckdb/function/table/read_csv.hpp @@ -35,8 +35,8 @@ struct BaseCSVData : public TableFunctionData { //! The CSV reader options CSVReaderOptions options; //! Offsets for generated columns - idx_t filename_col_idx; - idx_t hive_partition_col_idx; + idx_t filename_col_idx {}; + idx_t hive_partition_col_idx {}; void Finalize(); }; diff --git a/src/duckdb/src/include/duckdb/optimizer/expression_heuristics.hpp b/src/duckdb/src/include/duckdb/optimizer/expression_heuristics.hpp index 94c88e85..12512a32 100644 --- a/src/duckdb/src/include/duckdb/optimizer/expression_heuristics.hpp +++ b/src/duckdb/src/include/duckdb/optimizer/expression_heuristics.hpp @@ -47,7 +47,7 @@ class ExpressionHeuristics : public LogicalOperatorVisitor { idx_t ExpressionCost(BoundComparisonExpression &expr); idx_t ExpressionCost(BoundConjunctionExpression &expr); idx_t ExpressionCost(BoundFunctionExpression &expr); - idx_t ExpressionCost(BoundOperatorExpression &expr, ExpressionType &expr_type); + idx_t ExpressionCost(BoundOperatorExpression &expr, ExpressionType expr_type); idx_t ExpressionCost(PhysicalType return_type, idx_t multiplier); }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/parser/base_expression.hpp b/src/duckdb/src/include/duckdb/parser/base_expression.hpp index a64baf72..7e339e2b 100644 --- a/src/duckdb/src/include/duckdb/parser/base_expression.hpp +++ b/src/duckdb/src/include/duckdb/parser/base_expression.hpp @@ -26,21 +26,69 @@ class BaseExpression { virtual ~BaseExpression() { } + //! Returns the class of the expression + ExpressionClass GetExpressionClass() const { + return expression_class; + } + //! Returns the type of the expression ExpressionType GetExpressionType() const { return type; } - //! Returns the class of the expression - ExpressionClass GetExpressionClass() const { - return expression_class; + + //! Sets the type of the expression unsafely. In general expressions are immutable and should not be changed after + //! creation. Only use this if you know what you are doing. + void SetExpressionTypeUnsafe(ExpressionType new_type) { + type = new_type; + } + + //! Returns the location in the query (if any) + optional_idx GetQueryLocation() const { + return query_location; } + //! Sets the location in the query + void SetQueryLocation(optional_idx location) { + query_location = location; + } + + //! Returns true if the expression has a non-empty alias + bool HasAlias() const { + return !alias.empty(); + } + + //! Returns the alias of the expression + const string &GetAlias() const { + return alias; + } + + //! Sets the alias of the expression + void SetAlias(const string &alias_p) { + alias = alias_p; + } + + //! Sets the alias of the expression + void SetAlias(string &&alias_p) { + alias = std::move(alias_p); + } + + //! Clears the alias of the expression + void ClearAlias() { + alias.clear(); + } + + // TODO: Make the following protected + // protected: + //! Type of the expression ExpressionType type; + //! The expression class of the node ExpressionClass expression_class; + //! The alias of the expression, string alias; + //! The location in the query (if any) optional_idx query_location; diff --git a/src/duckdb/src/include/duckdb/parser/expression/comparison_expression.hpp b/src/duckdb/src/include/duckdb/parser/expression/comparison_expression.hpp index 9c9a82e0..01371f5f 100644 --- a/src/duckdb/src/include/duckdb/parser/expression/comparison_expression.hpp +++ b/src/duckdb/src/include/duckdb/parser/expression/comparison_expression.hpp @@ -37,8 +37,8 @@ class ComparisonExpression : public ParsedExpression { public: template static string ToString(const T &entry) { - return StringUtil::Format("(%s %s %s)", entry.left->ToString(), ExpressionTypeToOperator(entry.type), - entry.right->ToString()); + return StringUtil::Format("(%s %s %s)", entry.left->ToString(), + ExpressionTypeToOperator(entry.GetExpressionType()), entry.right->ToString()); } private: diff --git a/src/duckdb/src/include/duckdb/parser/expression/conjunction_expression.hpp b/src/duckdb/src/include/duckdb/parser/expression/conjunction_expression.hpp index 748bcb01..3e343df9 100644 --- a/src/duckdb/src/include/duckdb/parser/expression/conjunction_expression.hpp +++ b/src/duckdb/src/include/duckdb/parser/expression/conjunction_expression.hpp @@ -43,7 +43,7 @@ class ConjunctionExpression : public ParsedExpression { static string ToString(const T &entry) { string result = "(" + entry.children[0]->ToString(); for (idx_t i = 1; i < entry.children.size(); i++) { - result += " " + ExpressionTypeToOperator(entry.type) + " " + entry.children[i]->ToString(); + result += " " + ExpressionTypeToOperator(entry.GetExpressionType()) + " " + entry.children[i]->ToString(); } return result + ")"; } diff --git a/src/duckdb/src/include/duckdb/parser/expression/function_expression.hpp b/src/duckdb/src/include/duckdb/parser/expression/function_expression.hpp index d131fceb..4fc29275 100644 --- a/src/duckdb/src/include/duckdb/parser/expression/function_expression.hpp +++ b/src/duckdb/src/include/duckdb/parser/expression/function_expression.hpp @@ -98,9 +98,9 @@ class FunctionExpression : public ParsedExpression { result += "DISTINCT "; } result += StringUtil::Join(entry.children, entry.children.size(), ", ", [&](const unique_ptr &child) { - return child->alias.empty() || !add_alias + return child->GetAlias().empty() || !add_alias ? child->ToString() - : StringUtil::Format("%s := %s", SQLIdentifier(child->alias), child->ToString()); + : StringUtil::Format("%s := %s", SQLIdentifier(child->GetAlias()), child->ToString()); }); // ordered aggregate if (order_bys && !order_bys->orders.empty()) { diff --git a/src/duckdb/src/include/duckdb/parser/expression/operator_expression.hpp b/src/duckdb/src/include/duckdb/parser/expression/operator_expression.hpp index 5867860e..3bcf3814 100644 --- a/src/duckdb/src/include/duckdb/parser/expression/operator_expression.hpp +++ b/src/duckdb/src/include/duckdb/parser/expression/operator_expression.hpp @@ -40,16 +40,16 @@ class OperatorExpression : public ParsedExpression { public: template static string ToString(const T &entry) { - auto op = ExpressionTypeToOperator(entry.type); + auto op = ExpressionTypeToOperator(entry.GetExpressionType()); if (!op.empty()) { // use the operator string to represent the operator D_ASSERT(entry.children.size() == 2); return entry.children[0]->ToString() + " " + op + " " + entry.children[1]->ToString(); } - switch (entry.type) { + switch (entry.GetExpressionType()) { case ExpressionType::COMPARE_IN: case ExpressionType::COMPARE_NOT_IN: { - string op_type = entry.type == ExpressionType::COMPARE_IN ? " IN " : " NOT IN "; + string op_type = entry.GetExpressionType() == ExpressionType::COMPARE_IN ? " IN " : " NOT IN "; string in_child = entry.children[0]->ToString(); string child_list = "("; for (idx_t i = 1; i < entry.children.size(); i++) { @@ -63,7 +63,7 @@ class OperatorExpression : public ParsedExpression { } case ExpressionType::OPERATOR_NOT: { string result = "("; - result += ExpressionTypeToString(entry.type); + result += ExpressionTypeToString(entry.GetExpressionType()); result += " "; result += StringUtil::Join(entry.children, entry.children.size(), ", ", [](const unique_ptr &child) { return child->ToString(); }); @@ -72,7 +72,7 @@ class OperatorExpression : public ParsedExpression { } case ExpressionType::GROUPING_FUNCTION: case ExpressionType::OPERATOR_COALESCE: { - string result = ExpressionTypeToString(entry.type); + string result = ExpressionTypeToString(entry.GetExpressionType()); result += "("; result += StringUtil::Join(entry.children, entry.children.size(), ", ", [](const unique_ptr &child) { return child->ToString(); }); @@ -105,7 +105,7 @@ class OperatorExpression : public ParsedExpression { return entry.children[0]->ToString() + "[" + begin + ":" + end + "]"; } case ExpressionType::STRUCT_EXTRACT: { - if (entry.children[1]->type != ExpressionType::VALUE_CONSTANT) { + if (entry.children[1]->GetExpressionType() != ExpressionType::VALUE_CONSTANT) { return string(); } auto child_string = entry.children[1]->ToString(); diff --git a/src/duckdb/src/include/duckdb/storage/compression/alp/alp_compress.hpp b/src/duckdb/src/include/duckdb/storage/compression/alp/alp_compress.hpp index 167022df..2fad8577 100644 --- a/src/duckdb/src/include/duckdb/storage/compression/alp/alp_compress.hpp +++ b/src/duckdb/src/include/duckdb/storage/compression/alp/alp_compress.hpp @@ -96,7 +96,6 @@ struct AlpCompressionState : public CompressionState { auto compressed_segment = ColumnSegment::CreateTransientSegment(db, function, type, row_start, info.GetBlockSize(), info.GetBlockSize()); current_segment = std::move(compressed_segment); - current_segment->function = function; auto &buffer_manager = BufferManager::GetBufferManager(current_segment->db); handle = buffer_manager.Pin(current_segment->block); diff --git a/src/duckdb/src/include/duckdb/storage/compression/alprd/alprd_compress.hpp b/src/duckdb/src/include/duckdb/storage/compression/alprd/alprd_compress.hpp index 5bd1b7d0..e5e8043d 100644 --- a/src/duckdb/src/include/duckdb/storage/compression/alprd/alprd_compress.hpp +++ b/src/duckdb/src/include/duckdb/storage/compression/alprd/alprd_compress.hpp @@ -105,7 +105,6 @@ struct AlpRDCompressionState : public CompressionState { auto compressed_segment = ColumnSegment::CreateTransientSegment(db, function, type, row_start, info.GetBlockSize(), info.GetBlockSize()); - compressed_segment->function = function; current_segment = std::move(compressed_segment); auto &buffer_manager = BufferManager::GetBufferManager(db); diff --git a/src/duckdb/src/include/duckdb/storage/table/column_data.hpp b/src/duckdb/src/include/duckdb/storage/table/column_data.hpp index cc40d857..28af47d4 100644 --- a/src/duckdb/src/include/duckdb/storage/table/column_data.hpp +++ b/src/duckdb/src/include/duckdb/storage/table/column_data.hpp @@ -202,7 +202,7 @@ class ColumnData { idx_t GetVectorCount(idx_t vector_index) const; private: - void UpdateCompressionFunction(SegmentLock &l, CompressionFunction &function); + void UpdateCompressionFunction(SegmentLock &l, const CompressionFunction &function); protected: //! The segments holding the data of this column segment @@ -219,7 +219,7 @@ class ColumnData { idx_t allocation_size; //! The compression function used by the ColumnData //! This is empty if the segments have mixed compression or the ColumnData is empty - optional_ptr compression; + optional_ptr compression; }; struct PersistentColumnData { diff --git a/src/duckdb/src/include/duckdb/storage/table/column_segment.hpp b/src/duckdb/src/include/duckdb/storage/table/column_segment.hpp index 686af1e1..45d2db0c 100644 --- a/src/duckdb/src/include/duckdb/storage/table/column_segment.hpp +++ b/src/duckdb/src/include/duckdb/storage/table/column_segment.hpp @@ -38,23 +38,18 @@ enum class ColumnSegmentType : uint8_t { TRANSIENT, PERSISTENT }; class ColumnSegment : public SegmentBase { public: + //! Construct a column segment. + ColumnSegment(DatabaseInstance &db, shared_ptr block, const LogicalType &type, + const ColumnSegmentType segment_type, const idx_t start, const idx_t count, + CompressionFunction &function_p, BaseStatistics statistics, const block_id_t block_id_p, + const idx_t offset, const idx_t segment_size_p, + unique_ptr segment_state_p = nullptr); + //! Construct a column segment from another column segment. + //! The other column segment becomes invalid (std::move). + ColumnSegment(ColumnSegment &other, const idx_t start); ~ColumnSegment(); - //! The database instance - DatabaseInstance &db; - //! The type stored in the column - LogicalType type; - //! The size of the type - idx_t type_size; - //! The column segment type (transient or persistent) - ColumnSegmentType segment_type; - //! The compression function - reference function; - //! The statistics for the segment - SegmentStatistics stats; - //! The block that this segment relates to - shared_ptr block; - +public: static unique_ptr CreatePersistentSegment(DatabaseInstance &db, BlockManager &block_manager, block_id_t id, idx_t offset, const LogicalType &type_p, idx_t start, idx_t count, CompressionType compression_type, @@ -87,6 +82,7 @@ class ColumnSegment : public SegmentBase { idx_t SegmentSize() const; //! Resize the block void Resize(idx_t segment_size); + const CompressionFunction &GetCompressionFunction(); //! Initialize an append of this segment. Appends are only supported on transient segments. void InitializeAppend(ColumnAppendState &state); @@ -137,22 +133,27 @@ class ColumnSegment : public SegmentBase { void CommitDropSegment(); -public: - //! Construct a column segment. - ColumnSegment(DatabaseInstance &db, shared_ptr block, const LogicalType &type, - const ColumnSegmentType segment_type, const idx_t start, const idx_t count, - CompressionFunction &function_p, BaseStatistics statistics, const block_id_t block_id_p, - const idx_t offset, const idx_t segment_size_p, - unique_ptr segment_state_p = nullptr); - //! Construct a column segment from another column segment. - //! The other column segment becomes invalid (std::move). - ColumnSegment(ColumnSegment &other, const idx_t start); - private: void Scan(ColumnScanState &state, idx_t scan_count, Vector &result); void ScanPartial(ColumnScanState &state, idx_t scan_count, Vector &result, idx_t result_offset); +public: + //! The database instance + DatabaseInstance &db; + //! The type stored in the column + LogicalType type; + //! The size of the type + idx_t type_size; + //! The column segment type (transient or persistent) + ColumnSegmentType segment_type; + //! The statistics for the segment + SegmentStatistics stats; + //! The block that this segment relates to + shared_ptr block; + private: + //! The compression function + reference function; //! The block id that this segment relates to (persistent segment only) block_id_t block_id; //! The offset into the block (persistent segment only) diff --git a/src/duckdb/src/main/relation.cpp b/src/duckdb/src/main/relation.cpp index e43e55c5..9a28349e 100644 --- a/src/duckdb/src/main/relation.cpp +++ b/src/duckdb/src/main/relation.cpp @@ -136,11 +136,11 @@ shared_ptr Relation::Join(const shared_ptr &other, const str shared_ptr Relation::Join(const shared_ptr &other, vector> expression_list, JoinType type, JoinRefType ref_type) { - if (expression_list.size() > 1 || expression_list[0]->type == ExpressionType::COLUMN_REF) { + if (expression_list.size() > 1 || expression_list[0]->GetExpressionType() == ExpressionType::COLUMN_REF) { // multiple columns or single column ref: the condition is a USING list vector using_columns; for (auto &expr : expression_list) { - if (expr->type != ExpressionType::COLUMN_REF) { + if (expr->GetExpressionType() != ExpressionType::COLUMN_REF) { throw ParserException("Expected a single expression as join condition"); } auto &colref = expr->Cast(); diff --git a/src/duckdb/src/main/relation/projection_relation.cpp b/src/duckdb/src/main/relation/projection_relation.cpp index 651bbd99..0577ce73 100644 --- a/src/duckdb/src/main/relation/projection_relation.cpp +++ b/src/duckdb/src/main/relation/projection_relation.cpp @@ -14,7 +14,7 @@ ProjectionRelation::ProjectionRelation(shared_ptr child_p, throw ParserException("Aliases list length must match expression list length!"); } for (idx_t i = 0; i < aliases.size(); i++) { - expressions[i]->alias = aliases[i]; + expressions[i]->SetAlias(aliases[i]); } } // bind the expressions @@ -60,7 +60,7 @@ string ProjectionRelation::ToString(idx_t depth) { if (i != 0) { str += ", "; } - str += expressions[i]->ToString() + " as " + expressions[i]->alias; + str += expressions[i]->ToString() + " as " + expressions[i]->GetAlias(); } str += "]\n"; return str + child->ToString(depth + 1); diff --git a/src/duckdb/src/optimizer/column_binding_replacer.cpp b/src/duckdb/src/optimizer/column_binding_replacer.cpp index 2450b926..f5652ad2 100644 --- a/src/duckdb/src/optimizer/column_binding_replacer.cpp +++ b/src/duckdb/src/optimizer/column_binding_replacer.cpp @@ -25,7 +25,7 @@ void ColumnBindingReplacer::VisitOperator(LogicalOperator &op) { void ColumnBindingReplacer::VisitExpression(unique_ptr *expression) { auto &expr = *expression; - if (expr->expression_class == ExpressionClass::BOUND_COLUMN_REF) { + if (expr->GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF) { auto &bound_column_ref = expr->Cast(); for (const auto &replace_binding : replacement_bindings) { if (bound_column_ref.binding == replace_binding.old_binding) { diff --git a/src/duckdb/src/optimizer/column_lifetime_analyzer.cpp b/src/duckdb/src/optimizer/column_lifetime_analyzer.cpp index f84225ea..efb3e684 100644 --- a/src/duckdb/src/optimizer/column_lifetime_analyzer.cpp +++ b/src/duckdb/src/optimizer/column_lifetime_analyzer.cpp @@ -48,7 +48,7 @@ void ColumnLifetimeAnalyzer::StandardVisitOperator(LogicalOperator &op) { } void ExtractColumnBindings(Expression &expr, vector &bindings) { - if (expr.type == ExpressionType::BOUND_COLUMN_REF) { + if (expr.GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { auto &bound_ref = expr.Cast(); bindings.push_back(bound_ref.binding); } diff --git a/src/duckdb/src/optimizer/compressed_materialization/compress_aggregate.cpp b/src/duckdb/src/optimizer/compressed_materialization/compress_aggregate.cpp index beea67d4..ae4a7e8f 100644 --- a/src/duckdb/src/optimizer/compressed_materialization/compress_aggregate.cpp +++ b/src/duckdb/src/optimizer/compressed_materialization/compress_aggregate.cpp @@ -13,7 +13,7 @@ void CompressedMaterialization::CompressAggregate(unique_ptr &o auto &groups = aggregate.groups; column_binding_set_t group_binding_set; for (const auto &group : groups) { - if (group->type != ExpressionType::BOUND_COLUMN_REF) { + if (group->GetExpressionType() != ExpressionType::BOUND_COLUMN_REF) { continue; } auto &colref = group->Cast(); @@ -67,7 +67,7 @@ void CompressedMaterialization::CompressAggregate(unique_ptr &o // Anything referenced in the aggregate functions is also excluded for (idx_t expr_idx = 0; expr_idx < aggregate.expressions.size(); expr_idx++) { const auto &expr = *aggregate.expressions[expr_idx]; - D_ASSERT(expr.type == ExpressionType::BOUND_AGGREGATE); + D_ASSERT(expr.GetExpressionType() == ExpressionType::BOUND_AGGREGATE); const auto &aggr_expr = expr.Cast(); for (const auto &child : aggr_expr.children) { GetReferencedBindings(*child, referenced_bindings); @@ -78,7 +78,7 @@ void CompressedMaterialization::CompressAggregate(unique_ptr &o if (aggr_expr.order_bys) { for (const auto &order : aggr_expr.order_bys->orders) { const auto &order_expr = *order.expression; - if (order_expr.type != ExpressionType::BOUND_COLUMN_REF) { + if (order_expr.GetExpressionType() != ExpressionType::BOUND_COLUMN_REF) { GetReferencedBindings(order_expr, referenced_bindings); } } diff --git a/src/duckdb/src/optimizer/compressed_materialization/compress_distinct.cpp b/src/duckdb/src/optimizer/compressed_materialization/compress_distinct.cpp index 3dd1f536..e533bfaa 100644 --- a/src/duckdb/src/optimizer/compressed_materialization/compress_distinct.cpp +++ b/src/duckdb/src/optimizer/compressed_materialization/compress_distinct.cpp @@ -10,14 +10,14 @@ void CompressedMaterialization::CompressDistinct(unique_ptr &op column_binding_set_t referenced_bindings; for (auto &target : distinct_targets) { - if (target->type != ExpressionType::BOUND_COLUMN_REF) { // LCOV_EXCL_START + if (target->GetExpressionType() != ExpressionType::BOUND_COLUMN_REF) { // LCOV_EXCL_START GetReferencedBindings(*target, referenced_bindings); } // LCOV_EXCL_STOP } if (distinct.order_by) { for (auto &order : distinct.order_by->orders) { - if (order.expression->type != ExpressionType::BOUND_COLUMN_REF) { // LCOV_EXCL_START + if (order.expression->GetExpressionType() != ExpressionType::BOUND_COLUMN_REF) { // LCOV_EXCL_START GetReferencedBindings(*order.expression, referenced_bindings); } // LCOV_EXCL_STOP } diff --git a/src/duckdb/src/optimizer/cse_optimizer.cpp b/src/duckdb/src/optimizer/cse_optimizer.cpp index 12034f07..cde7aeb4 100644 --- a/src/duckdb/src/optimizer/cse_optimizer.cpp +++ b/src/duckdb/src/optimizer/cse_optimizer.cpp @@ -47,7 +47,7 @@ void CommonSubExpressionOptimizer::VisitOperator(LogicalOperator &op) { void CommonSubExpressionOptimizer::CountExpressions(Expression &expr, CSEReplacementState &state) { // we only consider expressions with children for CSE elimination - switch (expr.expression_class) { + switch (expr.GetExpressionClass()) { case ExpressionClass::BOUND_COLUMN_REF: case ExpressionClass::BOUND_CONSTANT: case ExpressionClass::BOUND_PARAMETER: @@ -58,7 +58,7 @@ void CommonSubExpressionOptimizer::CountExpressions(Expression &expr, CSEReplace default: break; } - if (expr.expression_class != ExpressionClass::BOUND_AGGREGATE && !expr.IsVolatile()) { + if (expr.GetExpressionClass() != ExpressionClass::BOUND_AGGREGATE && !expr.IsVolatile()) { // we can't move aggregates to a projection, so we only consider the children of the aggregate auto node = state.expression_count.find(expr); if (node == state.expression_count.end()) { @@ -75,7 +75,7 @@ void CommonSubExpressionOptimizer::CountExpressions(Expression &expr, CSEReplace void CommonSubExpressionOptimizer::PerformCSEReplacement(unique_ptr &expr_ptr, CSEReplacementState &state) { Expression &expr = *expr_ptr; - if (expr.expression_class == ExpressionClass::BOUND_COLUMN_REF) { + if (expr.GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF) { auto &bound_column_ref = expr.Cast(); // bound column ref, check if this one has already been recorded in the expression list auto column_entry = state.column_map.find(bound_column_ref.binding); @@ -84,7 +84,7 @@ void CommonSubExpressionOptimizer::PerformCSEReplacement(unique_ptr idx_t new_column_index = state.expressions.size(); state.column_map[bound_column_ref.binding] = new_column_index; state.expressions.push_back(make_uniq( - bound_column_ref.alias, bound_column_ref.return_type, bound_column_ref.binding)); + bound_column_ref.GetAlias(), bound_column_ref.return_type, bound_column_ref.binding)); bound_column_ref.binding = ColumnBinding(state.projection_index, new_column_index); } else { // else: just update the column binding! @@ -93,14 +93,14 @@ void CommonSubExpressionOptimizer::PerformCSEReplacement(unique_ptr return; } // check if this child is eligible for CSE elimination - bool can_cse = expr.expression_class != ExpressionClass::BOUND_CONJUNCTION && - expr.expression_class != ExpressionClass::BOUND_CASE; + bool can_cse = expr.GetExpressionClass() != ExpressionClass::BOUND_CONJUNCTION && + expr.GetExpressionClass() != ExpressionClass::BOUND_CASE; if (can_cse && state.expression_count.find(expr) != state.expression_count.end()) { auto &node = state.expression_count[expr]; if (node.count > 1) { // this expression occurs more than once! push it into the projection // check if it has already been pushed into the projection - auto alias = expr.alias; + auto alias = expr.GetAlias(); auto type = expr.return_type; if (!node.column_index.IsValid()) { // has not been pushed yet: push it diff --git a/src/duckdb/src/optimizer/deliminator.cpp b/src/duckdb/src/optimizer/deliminator.cpp index 805e5660..254a5702 100644 --- a/src/duckdb/src/optimizer/deliminator.cpp +++ b/src/duckdb/src/optimizer/deliminator.cpp @@ -206,8 +206,8 @@ bool Deliminator::RemoveJoinWithDelimGet(LogicalComparisonJoin &delim_join, cons all_equality_conditions = all_equality_conditions && IsEqualityJoinCondition(cond); auto &delim_side = delim_idx == 0 ? *cond.left : *cond.right; auto &other_side = delim_idx == 0 ? *cond.right : *cond.left; - if (delim_side.type != ExpressionType::BOUND_COLUMN_REF || - other_side.type != ExpressionType::BOUND_COLUMN_REF) { + if (delim_side.GetExpressionType() != ExpressionType::BOUND_COLUMN_REF || + other_side.GetExpressionType() != ExpressionType::BOUND_COLUMN_REF) { return false; } auto &delim_colref = delim_side.Cast(); @@ -257,7 +257,8 @@ bool FindAndReplaceBindings(vector &traced_bindings, const vector } } - if (current_idx == expressions.size() || expressions[current_idx]->type != ExpressionType::BOUND_COLUMN_REF) { + if (current_idx == expressions.size() || + expressions[current_idx]->GetExpressionType() != ExpressionType::BOUND_COLUMN_REF) { return false; // Didn't find / can't deal with non-colref } @@ -293,7 +294,7 @@ bool Deliminator::RemoveInequalityJoinWithDelimGet(LogicalComparisonJoin &delim_ // We only support colref's vector traced_bindings; for (const auto &cond : delim_conditions) { - if (cond.right->type != ExpressionType::BOUND_COLUMN_REF) { + if (cond.right->GetExpressionType() != ExpressionType::BOUND_COLUMN_REF) { return false; } auto &colref = cond.right->Cast(); @@ -367,7 +368,7 @@ void Deliminator::TrySwitchSingleToLeft(LogicalComparisonJoin &delim_join) { if (!IsEqualityJoinCondition(cond)) { return; } - if (cond.right->type != ExpressionType::BOUND_COLUMN_REF) { + if (cond.right->GetExpressionType() != ExpressionType::BOUND_COLUMN_REF) { return; } auto &colref = cond.right->Cast(); diff --git a/src/duckdb/src/optimizer/expression_heuristics.cpp b/src/duckdb/src/optimizer/expression_heuristics.cpp index 72ae34b8..e6103b6d 100644 --- a/src/duckdb/src/optimizer/expression_heuristics.cpp +++ b/src/duckdb/src/optimizer/expression_heuristics.cpp @@ -125,7 +125,7 @@ idx_t ExpressionHeuristics::ExpressionCost(BoundFunctionExpression &expr) { } } -idx_t ExpressionHeuristics::ExpressionCost(BoundOperatorExpression &expr, ExpressionType &expr_type) { +idx_t ExpressionHeuristics::ExpressionCost(BoundOperatorExpression &expr, ExpressionType expr_type) { idx_t sum = 0; for (auto &child : expr.children) { sum += Cost(*child); @@ -159,7 +159,7 @@ idx_t ExpressionHeuristics::ExpressionCost(PhysicalType return_type, idx_t multi } idx_t ExpressionHeuristics::Cost(Expression &expr) { - switch (expr.expression_class) { + switch (expr.GetExpressionClass()) { case ExpressionClass::BOUND_CASE: { auto &case_expr = expr.Cast(); return ExpressionCost(case_expr); @@ -186,7 +186,7 @@ idx_t ExpressionHeuristics::Cost(Expression &expr) { } case ExpressionClass::BOUND_OPERATOR: { auto &op_expr = expr.Cast(); - return ExpressionCost(op_expr, expr.type); + return ExpressionCost(op_expr, expr.GetExpressionType()); } case ExpressionClass::BOUND_COLUMN_REF: { auto &col_expr = expr.Cast(); diff --git a/src/duckdb/src/optimizer/filter_combiner.cpp b/src/duckdb/src/optimizer/filter_combiner.cpp index 821f3c42..2b360c9c 100644 --- a/src/duckdb/src/optimizer/filter_combiner.cpp +++ b/src/duckdb/src/optimizer/filter_combiner.cpp @@ -402,7 +402,7 @@ bool FilterCombiner::HasFilters() { // Try to extract a column index from a bound column ref expression, or a column ref recursively nested // inside of a struct_extract call. If the expression is not a column ref (or nested column ref), return false. static bool TryGetBoundColumnIndex(const vector &column_ids, const Expression &expr, ColumnIndex &result) { - switch (expr.type) { + switch (expr.GetExpressionType()) { case ExpressionType::BOUND_COLUMN_REF: { auto &ref = expr.Cast(); result = column_ids[ref.binding.column_index]; @@ -424,7 +424,7 @@ static bool TryGetBoundColumnIndex(const vector &column_ids, const // Try to push down a filter into a expression by recursively wrapping any nested expressions in StructFilters. // If the expression is not a struct_extract, return the inner_filter unchanged. static unique_ptr PushDownFilterIntoExpr(const Expression &expr, unique_ptr inner_filter) { - if (expr.type == ExpressionType::BOUND_FUNCTION) { + if (expr.GetExpressionType() == ExpressionType::BOUND_FUNCTION) { auto &func = expr.Cast(); auto &child_expr = func.children[0]; auto child_value = func.children[1]->Cast().value; @@ -524,11 +524,11 @@ TableFilterSet FilterCombiner::GenerateTableScanFilters(const vectorexpression_class == ExpressionClass::BOUND_FUNCTION) { + if (remaining_filter->GetExpressionClass() == ExpressionClass::BOUND_FUNCTION) { auto &func = remaining_filter->Cast(); if (func.function.name == "prefix" && - func.children[0]->expression_class == ExpressionClass::BOUND_COLUMN_REF && - func.children[1]->type == ExpressionType::VALUE_CONSTANT) { + func.children[0]->GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF && + func.children[1]->GetExpressionType() == ExpressionType::VALUE_CONSTANT) { //! This is a like function. auto &column_ref = func.children[0]->Cast(); auto &constant_value_expr = func.children[1]->Cast(); @@ -545,8 +545,9 @@ TableFilterSet FilterCombiner::GenerateTableScanFilters(const vectorexpression_class == ExpressionClass::BOUND_COLUMN_REF && - func.children[1]->type == ExpressionType::VALUE_CONSTANT) { + if (func.function.name == "~~" && + func.children[0]->GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF && + func.children[1]->GetExpressionType() == ExpressionType::VALUE_CONSTANT) { //! This is a like function. auto &column_ref = func.children[0]->Cast(); auto &constant_value_expr = func.children[1]->Cast(); @@ -586,10 +587,10 @@ TableFilterSet FilterCombiner::GenerateTableScanFilters(const vectortype == ExpressionType::COMPARE_IN) { + } else if (remaining_filter->GetExpressionType() == ExpressionType::COMPARE_IN) { auto &func = remaining_filter->Cast(); D_ASSERT(func.children.size() > 1); - if (func.children[0]->expression_class != ExpressionClass::BOUND_COLUMN_REF) { + if (func.children[0]->GetExpressionClass() != ExpressionClass::BOUND_COLUMN_REF) { continue; } auto &column_ref = func.children[0]->Cast(); @@ -600,7 +601,7 @@ TableFilterSet FilterCombiner::GenerateTableScanFilters(const vectortype != ExpressionType::VALUE_CONSTANT) { + if (func.children[i]->GetExpressionType() != ExpressionType::VALUE_CONSTANT) { children_constant = false; break; } @@ -657,9 +658,9 @@ TableFilterSet FilterCombiner::GenerateTableScanFilters(const vectorexpression_class == ExpressionClass::BOUND_CONJUNCTION) { + if (remaining_filter->GetExpressionClass() == ExpressionClass::BOUND_CONJUNCTION) { auto &conj = remaining_filter->Cast(); - if (conj.type == ExpressionType::CONJUNCTION_OR) { + if (conj.GetExpressionType() == ExpressionType::CONJUNCTION_OR) { optional_idx column_id; auto optional_filter = make_uniq(); auto conj_filter = make_uniq(); @@ -672,12 +673,12 @@ TableFilterSet FilterCombiner::GenerateTableScanFilters(const vector const_val; auto &comp = child->Cast(); bool invert = false; - if (comp.left->expression_class == ExpressionClass::BOUND_COLUMN_REF && - comp.right->expression_class == ExpressionClass::BOUND_CONSTANT) { + if (comp.left->GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF && + comp.right->GetExpressionClass() == ExpressionClass::BOUND_CONSTANT) { column_ref = comp.left->Cast(); const_val = comp.right->Cast(); - } else if (comp.left->expression_class == ExpressionClass::BOUND_CONSTANT && - comp.right->expression_class == ExpressionClass::BOUND_COLUMN_REF) { + } else if (comp.left->GetExpressionClass() == ExpressionClass::BOUND_CONSTANT && + comp.right->GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF) { column_ref = comp.right->Cast(); const_val = comp.left->Cast(); invert = true; @@ -702,7 +703,8 @@ TableFilterSet FilterCombiner::GenerateTableScanFilters(const vector(comparison_type, const_val->value); conj_filter->child_filters.push_back(std::move(const_filter)); } @@ -729,11 +731,12 @@ static bool IsLessThan(ExpressionType type) { FilterResult FilterCombiner::AddBoundComparisonFilter(Expression &expr) { auto &comparison = expr.Cast(); - if (comparison.type != ExpressionType::COMPARE_LESSTHAN && - comparison.type != ExpressionType::COMPARE_LESSTHANOREQUALTO && - comparison.type != ExpressionType::COMPARE_GREATERTHAN && - comparison.type != ExpressionType::COMPARE_GREATERTHANOREQUALTO && - comparison.type != ExpressionType::COMPARE_EQUAL && comparison.type != ExpressionType::COMPARE_NOTEQUAL) { + if (comparison.GetExpressionType() != ExpressionType::COMPARE_LESSTHAN && + comparison.GetExpressionType() != ExpressionType::COMPARE_LESSTHANOREQUALTO && + comparison.GetExpressionType() != ExpressionType::COMPARE_GREATERTHAN && + comparison.GetExpressionType() != ExpressionType::COMPARE_GREATERTHANOREQUALTO && + comparison.GetExpressionType() != ExpressionType::COMPARE_EQUAL && + comparison.GetExpressionType() != ExpressionType::COMPARE_NOTEQUAL) { // only support [>, >=, <, <=, ==, !=] expressions return FilterResult::UNSUPPORTED; } @@ -756,7 +759,8 @@ FilterResult FilterCombiner::AddBoundComparisonFilter(Expression &expr) { // create the ExpressionValueInformation ExpressionValueInformation info; - info.comparison_type = left_is_scalar ? FlipComparisonExpression(comparison.type) : comparison.type; + info.comparison_type = + left_is_scalar ? FlipComparisonExpression(comparison.GetExpressionType()) : comparison.GetExpressionType(); info.constant = constant_value; // get the current bucket of constant values @@ -782,7 +786,7 @@ FilterResult FilterCombiner::AddBoundComparisonFilter(Expression &expr) { } else { // comparison between two non-scalars // only handle comparisons for now - if (expr.type != ExpressionType::COMPARE_EQUAL) { + if (expr.GetExpressionType() != ExpressionType::COMPARE_EQUAL) { return FilterResult::UNSUPPORTED; } // get the LHS and RHS nodes @@ -936,7 +940,7 @@ FilterResult FilterCombiner::AddFilter(Expression &expr) { * It's missing to create another method to add transitive filters from scalar filters, e.g, i > 10 */ FilterResult FilterCombiner::AddTransitiveFilters(BoundComparisonExpression &comparison, bool is_root) { - if (!IsGreaterThan(comparison.type) && !IsLessThan(comparison.type)) { + if (!IsGreaterThan(comparison.GetExpressionType()) && !IsLessThan(comparison.GetExpressionType())) { return FilterResult::UNSUPPORTED; } // get the LHS and RHS nodes @@ -944,20 +948,20 @@ FilterResult FilterCombiner::AddTransitiveFilters(BoundComparisonExpression &com reference right_node = GetNode(*comparison.right); // In case with filters like CAST(i) = j and i = 5 we replace the COLUMN_REF i with the constant 5 do { - if (right_node.get().type != ExpressionType::OPERATOR_CAST) { + if (right_node.get().GetExpressionType() != ExpressionType::OPERATOR_CAST) { break; } auto &bound_cast_expr = right_node.get().Cast(); - if (bound_cast_expr.child->type != ExpressionType::BOUND_COLUMN_REF) { + if (bound_cast_expr.child->GetExpressionType() != ExpressionType::BOUND_COLUMN_REF) { break; } auto &col_ref = bound_cast_expr.child->Cast(); for (auto &stored_exp : stored_expressions) { reference expr = stored_exp.first; - if (expr.get().type == ExpressionType::OPERATOR_CAST) { + if (expr.get().GetExpressionType() == ExpressionType::OPERATOR_CAST) { expr = *(right_node.get().Cast().child); } - if (expr.get().type != ExpressionType::BOUND_COLUMN_REF) { + if (expr.get().GetExpressionType() != ExpressionType::BOUND_COLUMN_REF) { continue; } auto &st_col_ref = expr.get().Cast(); @@ -1000,33 +1004,33 @@ FilterResult FilterCombiner::AddTransitiveFilters(BoundComparisonExpression &com // suppose the new comparison is j >= i and we have already a filter i = 10, // then we create a new filter j >= 10 // and the filter j >= i can be pruned by not adding it into the remaining filters - info.comparison_type = comparison.type; - } else if ((comparison.type == ExpressionType::COMPARE_GREATERTHANOREQUALTO && + info.comparison_type = comparison.GetExpressionType(); + } else if ((comparison.GetExpressionType() == ExpressionType::COMPARE_GREATERTHANOREQUALTO && IsGreaterThan(right_constant.comparison_type)) || - (comparison.type == ExpressionType::COMPARE_LESSTHANOREQUALTO && + (comparison.GetExpressionType() == ExpressionType::COMPARE_LESSTHANOREQUALTO && IsLessThan(right_constant.comparison_type))) { // filters (j >= i AND i [>, >=] 10) OR (j <= i AND i [<, <=] 10) // create filter j [>, >=] 10 and add the filter j [>=, <=] i into the remaining filters info.comparison_type = right_constant.comparison_type; // create filter j [>, >=, <, <=] 10 if (!is_inserted) { // Add the filter j >= i in the remaing filters - auto filter = make_uniq(comparison.type, comparison.left->Copy(), - comparison.right->Copy()); + auto filter = make_uniq(comparison.GetExpressionType(), + comparison.left->Copy(), comparison.right->Copy()); remaining_filters.push_back(std::move(filter)); is_inserted = true; } - } else if ((comparison.type == ExpressionType::COMPARE_GREATERTHAN && + } else if ((comparison.GetExpressionType() == ExpressionType::COMPARE_GREATERTHAN && IsGreaterThan(right_constant.comparison_type)) || - (comparison.type == ExpressionType::COMPARE_LESSTHAN && + (comparison.GetExpressionType() == ExpressionType::COMPARE_LESSTHAN && IsLessThan(right_constant.comparison_type))) { // filters (j > i AND i [>, >=] 10) OR j < i AND i [<, <=] 10 // create filter j [>, <] 10 and add the filter j [>, <] i into the remaining filters // the comparisons j > i and j < i are more restrictive - info.comparison_type = comparison.type; + info.comparison_type = comparison.GetExpressionType(); if (!is_inserted) { // Add the filter j [>, <] i - auto filter = make_uniq(comparison.type, comparison.left->Copy(), - comparison.right->Copy()); + auto filter = make_uniq(comparison.GetExpressionType(), + comparison.left->Copy(), comparison.right->Copy()); remaining_filters.push_back(std::move(filter)); is_inserted = true; } @@ -1066,13 +1070,13 @@ FilterResult FilterCombiner::AddTransitiveFilters(BoundComparisonExpression &com */ unique_ptr FilterCombiner::FindTransitiveFilter(Expression &expr) { // We only check for bound column ref - if (expr.type != ExpressionType::BOUND_COLUMN_REF) { + if (expr.GetExpressionType() != ExpressionType::BOUND_COLUMN_REF) { return nullptr; } for (idx_t i = 0; i < remaining_filters.size(); i++) { if (remaining_filters[i]->GetExpressionClass() == ExpressionClass::BOUND_COMPARISON) { auto &comparison = remaining_filters[i]->Cast(); - if (expr.Equals(*comparison.right) && comparison.type != ExpressionType::COMPARE_NOTEQUAL) { + if (expr.Equals(*comparison.right) && comparison.GetExpressionType() != ExpressionType::COMPARE_NOTEQUAL) { auto filter = std::move(remaining_filters[i]); remaining_filters.erase_at(i); return filter; diff --git a/src/duckdb/src/optimizer/filter_pushdown.cpp b/src/duckdb/src/optimizer/filter_pushdown.cpp index 3440e657..c7962b71 100644 --- a/src/duckdb/src/optimizer/filter_pushdown.cpp +++ b/src/duckdb/src/optimizer/filter_pushdown.cpp @@ -40,7 +40,7 @@ void FilterPushdown::CheckMarkToSemi(LogicalOperator &op, unordered_set & auto &expr = proj.expressions.at(col_index); vector bindings_to_keep; ExpressionIterator::EnumerateExpression(expr, [&](Expression &child) { - if (child.expression_class == ExpressionClass::BOUND_COLUMN_REF) { + if (child.GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF) { auto &col_ref = child.Cast(); bindings_to_keep.push_back(col_ref.binding); } diff --git a/src/duckdb/src/optimizer/in_clause_rewriter.cpp b/src/duckdb/src/optimizer/in_clause_rewriter.cpp index 260179af..62f34c1a 100644 --- a/src/duckdb/src/optimizer/in_clause_rewriter.cpp +++ b/src/duckdb/src/optimizer/in_clause_rewriter.cpp @@ -33,12 +33,13 @@ unique_ptr InClauseRewriter::Rewrite(unique_ptr InClauseRewriter::VisitReplace(BoundOperatorExpression &expr, unique_ptr *expr_ptr) { - if (expr.type != ExpressionType::COMPARE_IN && expr.type != ExpressionType::COMPARE_NOT_IN) { + if (expr.GetExpressionType() != ExpressionType::COMPARE_IN && + expr.GetExpressionType() != ExpressionType::COMPARE_NOT_IN) { return nullptr; } D_ASSERT(root); auto in_type = expr.children[0]->return_type; - bool is_regular_in = expr.type == ExpressionType::COMPARE_IN; + bool is_regular_in = expr.GetExpressionType() == ExpressionType::COMPARE_IN; bool all_scalar = true; // IN clause with many children: try to generate a mark join that replaces this IN expression // we can only do this if the expressions in the expression list are scalar diff --git a/src/duckdb/src/optimizer/join_filter_pushdown_optimizer.cpp b/src/duckdb/src/optimizer/join_filter_pushdown_optimizer.cpp index 8a68c9ca..6187d3f8 100644 --- a/src/duckdb/src/optimizer/join_filter_pushdown_optimizer.cpp +++ b/src/duckdb/src/optimizer/join_filter_pushdown_optimizer.cpp @@ -20,7 +20,7 @@ JoinFilterPushdownOptimizer::JoinFilterPushdownOptimizer(Optimizer &optimizer) : } bool PushdownJoinFilterExpression(Expression &expr, JoinFilterPushdownColumn &filter) { - if (expr.type != ExpressionType::BOUND_COLUMN_REF) { + if (expr.GetExpressionType() != ExpressionType::BOUND_COLUMN_REF) { // not a simple column ref - bail-out return false; } @@ -174,7 +174,7 @@ void JoinFilterPushdownOptimizer::GenerateJoinFilters(LogicalComparisonJoin &joi // only equality supported for now continue; } - if (cond.left->type != ExpressionType::BOUND_COLUMN_REF) { + if (cond.left->GetExpressionType() != ExpressionType::BOUND_COLUMN_REF) { // only bound column ref supported for now continue; } diff --git a/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp b/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp index 07cbf1dc..4b5e22ad 100644 --- a/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp +++ b/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp @@ -219,14 +219,15 @@ double CardinalityEstimator::CalculateUpdatedDenom(Subgraph2Denominator left, Su bool set = false; ExpressionType comparison_type = ExpressionType::COMPARE_EQUAL; ExpressionIterator::EnumerateExpression(filter.filter_info->filter, [&](Expression &expr) { - if (expr.expression_class == ExpressionClass::BOUND_COMPARISON) { - comparison_type = expr.type; + if (expr.GetExpressionClass() == ExpressionClass::BOUND_COMPARISON) { + comparison_type = expr.GetExpressionType(); set = true; return; } }); if (!set) { - new_denom *= filter.has_tdom_hll ? (double)filter.tdom_hll : (double)filter.tdom_no_hll; + new_denom *= + filter.has_tdom_hll ? static_cast(filter.tdom_hll) : static_cast(filter.tdom_no_hll); // no comparison is taking place, so the denominator is just the product of the left and right return new_denom; } diff --git a/src/duckdb/src/optimizer/join_order/query_graph_manager.cpp b/src/duckdb/src/optimizer/join_order/query_graph_manager.cpp index 3a5214d2..6850508a 100644 --- a/src/duckdb/src/optimizer/join_order/query_graph_manager.cpp +++ b/src/duckdb/src/optimizer/join_order/query_graph_manager.cpp @@ -36,7 +36,7 @@ bool QueryGraphManager::Build(JoinOrderOptimizer &optimizer, LogicalOperator &op } void QueryGraphManager::GetColumnBinding(Expression &expression, ColumnBinding &binding) { - if (expression.type == ExpressionType::BOUND_COLUMN_REF) { + if (expression.GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { // Here you have a filter on a single column in a table. Return a binding for the column // being filtered on so the filter estimator knows what HLL count to pull auto &colref = expression.Cast(); @@ -114,8 +114,8 @@ void QueryGraphManager::CreateHyperGraphEdges() { } } else if (filter->GetExpressionClass() == ExpressionClass::BOUND_CONJUNCTION) { auto &conjunction = filter->Cast(); - if (conjunction.type == ExpressionType::CONJUNCTION_OR || filter_info->join_type == JoinType::INNER || - filter_info->join_type == JoinType::INVALID) { + if (conjunction.GetExpressionType() == ExpressionType::CONJUNCTION_OR || + filter_info->join_type == JoinType::INNER || filter_info->join_type == JoinType::INVALID) { // Currently we do not interpret Conjunction expressions as INNER joins // for hyper graph edges. These are most likely OR conjunctions, and // will be pushed down into a join later in the optimizer. @@ -127,7 +127,7 @@ void QueryGraphManager::CreateHyperGraphEdges() { D_ASSERT(filter_info->right_set); D_ASSERT(filter_info->join_type == JoinType::SEMI || filter_info->join_type == JoinType::ANTI); for (auto &child_comp : conjunction.children) { - if (child_comp->expression_class != ExpressionClass::BOUND_COMPARISON) { + if (child_comp->GetExpressionClass() != ExpressionClass::BOUND_COMPARISON) { continue; } auto &comparison = child_comp->Cast(); @@ -226,7 +226,7 @@ static JoinCondition MaybeInvertConditions(unique_ptr condition, boo JoinCondition cond; cond.left = !invert ? std::move(comparison.left) : std::move(comparison.right); cond.right = !invert ? std::move(comparison.right) : std::move(comparison.left); - cond.comparison = condition->type; + cond.comparison = condition->GetExpressionType(); if (invert) { // reverse comparison expression if we reverse the order of the children cond.comparison = FlipComparisonExpression(cond.comparison); @@ -368,10 +368,10 @@ GenerateJoinRelation QueryGraphManager::GenerateJoins(vector &bindings) { - if (expression.type == ExpressionType::BOUND_COLUMN_REF) { + if (expression.GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { auto &colref = expression.Cast(); D_ASSERT(colref.depth == 0); D_ASSERT(colref.binding.table_index != DConstants::INVALID_INDEX); // map the base table index to the relation index used by the JoinOrderOptimizer - if (expression.alias == "SUBQUERY" && + if (expression.GetAlias() == "SUBQUERY" && relation_mapping.find(colref.binding.table_index) == relation_mapping.end()) { // most likely a BoundSubqueryExpression that was created from an uncorrelated subquery // Here we return true and don't fill the bindings, the expression can be reordered. @@ -455,12 +455,12 @@ bool RelationManager::ExtractBindings(Expression &expression, unordered_set(); @@ -332,7 +332,7 @@ RelationStats RelationStatisticsHelper::ExtractAggregationStats(LogicalAggregate double new_card = -1; for (auto &g_set : aggr.grouping_sets) { for (auto &ind : g_set) { - if (aggr.groups[ind]->expression_class != ExpressionClass::BOUND_COLUMN_REF) { + if (aggr.groups[ind]->GetExpressionClass() != ExpressionClass::BOUND_COLUMN_REF) { continue; } auto bound_col = &aggr.groups[ind]->Cast(); diff --git a/src/duckdb/src/optimizer/matcher/expression_matcher.cpp b/src/duckdb/src/optimizer/matcher/expression_matcher.cpp index e7fe3a6b..499daa59 100644 --- a/src/duckdb/src/optimizer/matcher/expression_matcher.cpp +++ b/src/duckdb/src/optimizer/matcher/expression_matcher.cpp @@ -8,7 +8,7 @@ bool ExpressionMatcher::Match(Expression &expr, vector> &b if (type && !type->Match(expr.return_type)) { return false; } - if (expr_type && !expr_type->Match(expr.type)) { + if (expr_type && !expr_type->Match(expr.GetExpressionType())) { return false; } if (expr_class != ExpressionClass::INVALID && expr_class != expr.GetExpressionClass()) { @@ -60,7 +60,8 @@ bool InClauseExpressionMatcher::Match(Expression &expr_p, vector(); - if (expr.type != ExpressionType::COMPARE_IN || expr.type == ExpressionType::COMPARE_NOT_IN) { + if (expr.GetExpressionType() != ExpressionType::COMPARE_IN || + expr.GetExpressionType() == ExpressionType::COMPARE_NOT_IN) { return false; } return SetMatcher::Match(matchers, expr.children, bindings, policy); diff --git a/src/duckdb/src/optimizer/pullup/pullup_projection.cpp b/src/duckdb/src/optimizer/pullup/pullup_projection.cpp index f2fd71b7..0149fbcf 100644 --- a/src/duckdb/src/optimizer/pullup/pullup_projection.cpp +++ b/src/duckdb/src/optimizer/pullup/pullup_projection.cpp @@ -19,13 +19,13 @@ static void RevertFilterPullup(LogicalProjection &proj, vector> &proj_expressions, Expression &expr, idx_t proj_table_idx) { - if (expr.type == ExpressionType::BOUND_COLUMN_REF) { + if (expr.GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { bool found_proj_col = false; BoundColumnRefExpression &colref = expr.Cast(); // find the corresponding column index in the projection expressions for (idx_t proj_idx = 0; proj_idx < proj_expressions.size(); proj_idx++) { auto &proj_expr = *proj_expressions[proj_idx]; - if (proj_expr.type == ExpressionType::BOUND_COLUMN_REF) { + if (proj_expr.GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { if (colref.Equals(proj_expr)) { colref.binding.table_index = proj_table_idx; colref.binding.column_index = proj_idx; diff --git a/src/duckdb/src/optimizer/pullup/pullup_set_operation.cpp b/src/duckdb/src/optimizer/pullup/pullup_set_operation.cpp index 8d7b3c1d..00f642ca 100644 --- a/src/duckdb/src/optimizer/pullup/pullup_set_operation.cpp +++ b/src/duckdb/src/optimizer/pullup/pullup_set_operation.cpp @@ -6,7 +6,7 @@ namespace duckdb { static void ReplaceFilterTableIndex(Expression &expr, LogicalSetOperation &setop) { - if (expr.type == ExpressionType::BOUND_COLUMN_REF) { + if (expr.GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { auto &colref = expr.Cast(); D_ASSERT(colref.depth == 0); diff --git a/src/duckdb/src/optimizer/pushdown/pushdown_aggregate.cpp b/src/duckdb/src/optimizer/pushdown/pushdown_aggregate.cpp index bd664a26..eb5f803b 100644 --- a/src/duckdb/src/optimizer/pushdown/pushdown_aggregate.cpp +++ b/src/duckdb/src/optimizer/pushdown/pushdown_aggregate.cpp @@ -10,7 +10,7 @@ namespace duckdb { using Filter = FilterPushdown::Filter; static unique_ptr ReplaceGroupBindings(LogicalAggregate &proj, unique_ptr expr) { - if (expr->type == ExpressionType::BOUND_COLUMN_REF) { + if (expr->GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { auto &colref = expr->Cast(); D_ASSERT(colref.binding.table_index == proj.group_index); D_ASSERT(colref.binding.column_index < proj.groups.size()); @@ -24,7 +24,7 @@ static unique_ptr ReplaceGroupBindings(LogicalAggregate &proj, uniqu } void FilterPushdown::ExtractFilterBindings(Expression &expr, vector &bindings) { - if (expr.type == ExpressionType::BOUND_COLUMN_REF) { + if (expr.GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { auto &colref = expr.Cast(); bindings.push_back(colref.binding); } diff --git a/src/duckdb/src/optimizer/pushdown/pushdown_left_join.cpp b/src/duckdb/src/optimizer/pushdown/pushdown_left_join.cpp index e142a1d7..814adadc 100644 --- a/src/duckdb/src/optimizer/pushdown/pushdown_left_join.cpp +++ b/src/duckdb/src/optimizer/pushdown/pushdown_left_join.cpp @@ -13,7 +13,7 @@ namespace duckdb { using Filter = FilterPushdown::Filter; static unique_ptr ReplaceColRefWithNull(unique_ptr expr, unordered_set &right_bindings) { - if (expr->type == ExpressionType::BOUND_COLUMN_REF) { + if (expr->GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { auto &bound_colref = expr->Cast(); if (right_bindings.find(bound_colref.binding.table_index) != right_bindings.end()) { // bound colref belongs to RHS diff --git a/src/duckdb/src/optimizer/pushdown/pushdown_mark_join.cpp b/src/duckdb/src/optimizer/pushdown/pushdown_mark_join.cpp index 172d8414..8958bb88 100644 --- a/src/duckdb/src/optimizer/pushdown/pushdown_mark_join.cpp +++ b/src/duckdb/src/optimizer/pushdown/pushdown_mark_join.cpp @@ -36,7 +36,7 @@ unique_ptr FilterPushdown::PushdownMarkJoin(unique_ptrfilter->type == ExpressionType::BOUND_COLUMN_REF && convert_mark_joins && + if (filters[i]->filter->GetExpressionType() == ExpressionType::BOUND_COLUMN_REF && convert_mark_joins && comp_join.convert_mark_to_semi) { // filter just references the marker: turn into semi join #ifdef DEBUG @@ -51,9 +51,9 @@ unique_ptr FilterPushdown::PushdownMarkJoin(unique_ptrfilter->type == ExpressionType::OPERATOR_NOT) { + if (filters[i]->filter->GetExpressionType() == ExpressionType::OPERATOR_NOT) { auto &op_expr = filters[i]->filter->Cast(); - if (op_expr.children[0]->type == ExpressionType::BOUND_COLUMN_REF) { + if (op_expr.children[0]->GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { // the filter is NOT(marker), check the join conditions bool all_null_values_are_equal = true; for (auto &cond : comp_join.conditions) { diff --git a/src/duckdb/src/optimizer/pushdown/pushdown_projection.cpp b/src/duckdb/src/optimizer/pushdown/pushdown_projection.cpp index f66ce66f..b10b60ae 100644 --- a/src/duckdb/src/optimizer/pushdown/pushdown_projection.cpp +++ b/src/duckdb/src/optimizer/pushdown/pushdown_projection.cpp @@ -9,7 +9,7 @@ namespace duckdb { static bool IsVolatile(LogicalProjection &proj, const unique_ptr &expr) { - if (expr->type == ExpressionType::BOUND_COLUMN_REF) { + if (expr->GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { auto &colref = expr->Cast(); D_ASSERT(colref.binding.table_index == proj.table_index); D_ASSERT(colref.binding.column_index < proj.expressions.size()); @@ -26,7 +26,7 @@ static bool IsVolatile(LogicalProjection &proj, const unique_ptr &ex } static unique_ptr ReplaceProjectionBindings(LogicalProjection &proj, unique_ptr expr) { - if (expr->type == ExpressionType::BOUND_COLUMN_REF) { + if (expr->GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { auto &colref = expr->Cast(); D_ASSERT(colref.binding.table_index == proj.table_index); D_ASSERT(colref.binding.column_index < proj.expressions.size()); diff --git a/src/duckdb/src/optimizer/pushdown/pushdown_set_operation.cpp b/src/duckdb/src/optimizer/pushdown/pushdown_set_operation.cpp index 5d3dce97..64f9fe18 100644 --- a/src/duckdb/src/optimizer/pushdown/pushdown_set_operation.cpp +++ b/src/duckdb/src/optimizer/pushdown/pushdown_set_operation.cpp @@ -13,7 +13,7 @@ using Filter = FilterPushdown::Filter; static void ReplaceSetOpBindings(vector &bindings, Filter &filter, Expression &expr, LogicalSetOperation &setop) { - if (expr.type == ExpressionType::BOUND_COLUMN_REF) { + if (expr.GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { auto &colref = expr.Cast(); D_ASSERT(colref.binding.table_index == setop.table_index); D_ASSERT(colref.depth == 0); diff --git a/src/duckdb/src/optimizer/pushdown/pushdown_window.cpp b/src/duckdb/src/optimizer/pushdown/pushdown_window.cpp index 5b02983e..a193b1e9 100644 --- a/src/duckdb/src/optimizer/pushdown/pushdown_window.cpp +++ b/src/duckdb/src/optimizer/pushdown/pushdown_window.cpp @@ -39,7 +39,7 @@ unique_ptr FilterPushdown::PushdownWindow(unique_ptr window_exprs_partition_bindings; for (auto &expr : window.expressions) { - if (expr->expression_class != ExpressionClass::BOUND_WINDOW) { + if (expr->GetExpressionClass() != ExpressionClass::BOUND_WINDOW) { continue; } auto &window_expr = expr->Cast(); @@ -53,7 +53,7 @@ unique_ptr FilterPushdown::PushdownWindow(unique_ptrtype) { + switch (partition_expr->GetExpressionType()) { // TODO: Add expressions for function expressions like FLOOR, CEIL etc. case ExpressionType::BOUND_COLUMN_REF: { auto &partition_col = partition_expr->Cast(); diff --git a/src/duckdb/src/optimizer/regex_range_filter.cpp b/src/duckdb/src/optimizer/regex_range_filter.cpp index 19d0e059..fd9f98fe 100644 --- a/src/duckdb/src/optimizer/regex_range_filter.cpp +++ b/src/duckdb/src/optimizer/regex_range_filter.cpp @@ -28,7 +28,7 @@ unique_ptr RegexRangeFilter::Rewrite(unique_ptr(); for (auto &expr : op->expressions) { - if (expr->type == ExpressionType::BOUND_FUNCTION) { + if (expr->GetExpressionType() == ExpressionType::BOUND_FUNCTION) { auto &func = expr->Cast(); if (func.function.name != "regexp_full_match" || func.children.size() != 2) { continue; diff --git a/src/duckdb/src/optimizer/remove_duplicate_groups.cpp b/src/duckdb/src/optimizer/remove_duplicate_groups.cpp index 3ab3dca6..dd09c2f3 100644 --- a/src/duckdb/src/optimizer/remove_duplicate_groups.cpp +++ b/src/duckdb/src/optimizer/remove_duplicate_groups.cpp @@ -29,7 +29,7 @@ void RemoveDuplicateGroups::VisitAggregate(LogicalAggregate &aggr) { vector> duplicates; for (idx_t group_idx = 0; group_idx < groups.size(); group_idx++) { const auto &group = groups[group_idx]; - if (group->type != ExpressionType::BOUND_COLUMN_REF) { + if (group->GetExpressionType() != ExpressionType::BOUND_COLUMN_REF) { continue; } const auto &colref = group->Cast(); diff --git a/src/duckdb/src/optimizer/remove_unused_columns.cpp b/src/duckdb/src/optimizer/remove_unused_columns.cpp index 8a21f70a..3a867bdf 100644 --- a/src/duckdb/src/optimizer/remove_unused_columns.cpp +++ b/src/duckdb/src/optimizer/remove_unused_columns.cpp @@ -89,8 +89,8 @@ void RemoveUnusedColumns::VisitOperator(LogicalOperator &op) { // this reduces the amount of columns we need to extract from the join hash table for (auto &cond : comp_join.conditions) { if (cond.comparison == ExpressionType::COMPARE_EQUAL) { - if (cond.left->expression_class == ExpressionClass::BOUND_COLUMN_REF && - cond.right->expression_class == ExpressionClass::BOUND_COLUMN_REF) { + if (cond.left->GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF && + cond.right->GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF) { // comparison join between two bound column refs // we can replace any reference to the RHS (build-side) with a reference to the LHS (probe-side) auto &lhs_col = cond.left->Cast(); diff --git a/src/duckdb/src/optimizer/rule/comparison_simplification.cpp b/src/duckdb/src/optimizer/rule/comparison_simplification.cpp index 026228da..1e377528 100644 --- a/src/duckdb/src/optimizer/rule/comparison_simplification.cpp +++ b/src/duckdb/src/optimizer/rule/comparison_simplification.cpp @@ -29,12 +29,12 @@ unique_ptr ComparisonSimplificationRule::Apply(LogicalOperator &op, if (!ExpressionExecutor::TryEvaluateScalar(GetContext(), constant_expr, constant_value)) { return nullptr; } - if (constant_value.IsNull() && !(expr.type == ExpressionType::COMPARE_NOT_DISTINCT_FROM || - expr.type == ExpressionType::COMPARE_DISTINCT_FROM)) { + if (constant_value.IsNull() && !(expr.GetExpressionType() == ExpressionType::COMPARE_NOT_DISTINCT_FROM || + expr.GetExpressionType() == ExpressionType::COMPARE_DISTINCT_FROM)) { // comparison with constant NULL, return NULL return make_uniq(Value(LogicalType::BOOLEAN)); } - if (column_ref_expr->expression_class == ExpressionClass::BOUND_CAST) { + if (column_ref_expr->GetExpressionClass() == ExpressionClass::BOUND_CAST) { //! Here we check if we can apply the expression on the constant side //! We can do this if the cast itself is invertible and casting the constant is //! invertible in practice. diff --git a/src/duckdb/src/optimizer/rule/conjunction_simplification.cpp b/src/duckdb/src/optimizer/rule/conjunction_simplification.cpp index 14fd80a9..f1d5838d 100644 --- a/src/duckdb/src/optimizer/rule/conjunction_simplification.cpp +++ b/src/duckdb/src/optimizer/rule/conjunction_simplification.cpp @@ -48,7 +48,7 @@ unique_ptr ConjunctionSimplificationRule::Apply(LogicalOperator &op, // we can't simplify conjunctions with a constant NULL return nullptr; } - if (conjunction.type == ExpressionType::CONJUNCTION_AND) { + if (conjunction.GetExpressionType() == ExpressionType::CONJUNCTION_AND) { if (!BooleanValue::Get(constant_value)) { // FALSE in AND, result of expression is false return make_uniq(Value::BOOLEAN(false)); @@ -57,7 +57,7 @@ unique_ptr ConjunctionSimplificationRule::Apply(LogicalOperator &op, return RemoveExpression(conjunction, constant_expr); } } else { - D_ASSERT(conjunction.type == ExpressionType::CONJUNCTION_OR); + D_ASSERT(conjunction.GetExpressionType() == ExpressionType::CONJUNCTION_OR); if (!BooleanValue::Get(constant_value)) { // FALSE in OR, remove the expression from the set return RemoveExpression(conjunction, constant_expr); diff --git a/src/duckdb/src/optimizer/rule/constant_folding.cpp b/src/duckdb/src/optimizer/rule/constant_folding.cpp index 7702b460..6dba91d2 100644 --- a/src/duckdb/src/optimizer/rule/constant_folding.cpp +++ b/src/duckdb/src/optimizer/rule/constant_folding.cpp @@ -13,7 +13,7 @@ class ConstantFoldingExpressionMatcher : public FoldableConstantMatcher { public: bool Match(Expression &expr, vector> &bindings) override { // we also do not match on ConstantExpressions, because we cannot fold those any further - if (expr.type == ExpressionType::VALUE_CONSTANT) { + if (expr.GetExpressionType() == ExpressionType::VALUE_CONSTANT) { return false; } return FoldableConstantMatcher::Match(expr, bindings); @@ -29,7 +29,7 @@ unique_ptr ConstantFoldingRule::Apply(LogicalOperator &op, vector(); for (auto &child : and_expr.children) { set.insert(*child); @@ -29,7 +29,7 @@ unique_ptr DistributivityRule::ExtractExpression(BoundConjunctionExp Expression &expr) { auto &child = conj.children[idx]; unique_ptr result; - if (child->type == ExpressionType::CONJUNCTION_AND) { + if (child->GetExpressionType() == ExpressionType::CONJUNCTION_AND) { // AND, remove expression from the list auto &and_expr = child->Cast(); for (idx_t i = 0; i < and_expr.children.size(); i++) { diff --git a/src/duckdb/src/optimizer/rule/enum_comparison.cpp b/src/duckdb/src/optimizer/rule/enum_comparison.cpp index aeb5e224..5dfcfaf3 100644 --- a/src/duckdb/src/optimizer/rule/enum_comparison.cpp +++ b/src/duckdb/src/optimizer/rule/enum_comparison.cpp @@ -65,7 +65,8 @@ unique_ptr EnumComparisonRule::Apply(LogicalOperator &op, vectorreturn_type, true); - return make_uniq(root.type, std::move(cast_left_to_right), std::move(right_child.child)); + return make_uniq(root.GetExpressionType(), std::move(cast_left_to_right), + std::move(right_child.child)); } } // namespace duckdb diff --git a/src/duckdb/src/optimizer/rule/equal_or_null_simplification.cpp b/src/duckdb/src/optimizer/rule/equal_or_null_simplification.cpp index 7062dcd7..c3053b38 100644 --- a/src/duckdb/src/optimizer/rule/equal_or_null_simplification.cpp +++ b/src/duckdb/src/optimizer/rule/equal_or_null_simplification.cpp @@ -38,7 +38,8 @@ EqualOrNullSimplification::EqualOrNullSimplification(ExpressionRewriter &rewrite // a=b OR (a IS NULL AND b IS NULL) to a IS NOT DISTINCT FROM b static unique_ptr TryRewriteEqualOrIsNull(Expression &equal_expr, Expression &and_expr) { - if (equal_expr.type != ExpressionType::COMPARE_EQUAL || and_expr.type != ExpressionType::CONJUNCTION_AND) { + if (equal_expr.GetExpressionType() != ExpressionType::COMPARE_EQUAL || + and_expr.GetExpressionType() != ExpressionType::CONJUNCTION_AND) { return nullptr; } @@ -58,7 +59,7 @@ static unique_ptr TryRewriteEqualOrIsNull(Expression &equal_expr, Ex for (const auto &item : and_cast.children) { auto &next_exp = *item; - if (next_exp.type == ExpressionType::OPERATOR_IS_NULL) { + if (next_exp.GetExpressionType() == ExpressionType::OPERATOR_IS_NULL) { auto &next_exp_cast = next_exp.Cast(); auto &child = *next_exp_cast.children[0]; @@ -85,7 +86,7 @@ unique_ptr EqualOrNullSimplification::Apply(LogicalOperator &op, vec bool &changes_made, bool is_root) { const Expression &or_exp = bindings[0].get(); - if (or_exp.type != ExpressionType::CONJUNCTION_OR) { + if (or_exp.GetExpressionType() != ExpressionType::CONJUNCTION_OR) { return nullptr; } diff --git a/src/duckdb/src/optimizer/rule/in_clause_simplification_rule.cpp b/src/duckdb/src/optimizer/rule/in_clause_simplification_rule.cpp index c17b0ea3..d54d98cc 100644 --- a/src/duckdb/src/optimizer/rule/in_clause_simplification_rule.cpp +++ b/src/duckdb/src/optimizer/rule/in_clause_simplification_rule.cpp @@ -16,11 +16,11 @@ InClauseSimplificationRule::InClauseSimplificationRule(ExpressionRewriter &rewri unique_ptr InClauseSimplificationRule::Apply(LogicalOperator &op, vector> &bindings, bool &changes_made, bool is_root) { auto &expr = bindings[0].get().Cast(); - if (expr.children[0]->expression_class != ExpressionClass::BOUND_CAST) { + if (expr.children[0]->GetExpressionClass() != ExpressionClass::BOUND_CAST) { return nullptr; } auto &cast_expression = expr.children[0]->Cast(); - if (cast_expression.child->expression_class != ExpressionClass::BOUND_COLUMN_REF) { + if (cast_expression.child->GetExpressionClass() != ExpressionClass::BOUND_COLUMN_REF) { return nullptr; } //! The goal here is to remove the cast from the probe expression @@ -34,7 +34,7 @@ unique_ptr InClauseSimplificationRule::Apply(LogicalOperator &op, ve vector> cast_list; //! First check if we can cast all children for (size_t i = 1; i < expr.children.size(); i++) { - if (expr.children[i]->expression_class != ExpressionClass::BOUND_CONSTANT) { + if (expr.children[i]->GetExpressionClass() != ExpressionClass::BOUND_CONSTANT) { return nullptr; } D_ASSERT(expr.children[i]->IsFoldable()); diff --git a/src/duckdb/src/optimizer/rule/move_constants.cpp b/src/duckdb/src/optimizer/rule/move_constants.cpp index 29404164..b2be74a0 100644 --- a/src/duckdb/src/optimizer/rule/move_constants.cpp +++ b/src/duckdb/src/optimizer/rule/move_constants.cpp @@ -41,8 +41,8 @@ unique_ptr MoveConstantsRule::Apply(LogicalOperator &op, vectorreturn_type.IsIntegral()); if (inner_constant.value.IsNull() || outer_constant.value.IsNull()) { - if (comparison.type == ExpressionType::COMPARE_DISTINCT_FROM || - comparison.type == ExpressionType::COMPARE_NOT_DISTINCT_FROM) { + if (comparison.GetExpressionType() == ExpressionType::COMPARE_DISTINCT_FROM || + comparison.GetExpressionType() == ExpressionType::COMPARE_NOT_DISTINCT_FROM) { return nullptr; } return make_uniq(Value(comparison.return_type)); @@ -62,7 +62,7 @@ unique_ptr MoveConstantsRule::Apply(LogicalOperator &op, vector MoveConstantsRule::Apply(LogicalOperator &op, vector MoveConstantsRule::Apply(LogicalOperator &op, vector MoveConstantsRule::Apply(LogicalOperator &op, vector 2] - comparison.type = FlipComparisonExpression(comparison.type); + comparison.SetExpressionTypeUnsafe(FlipComparisonExpression(comparison.GetExpressionType())); } } else { D_ASSERT(op_type == "*"); @@ -126,8 +126,8 @@ unique_ptr MoveConstantsRule::Apply(LogicalOperator &op, vector::Minimum() && inner_value == -1) || outer_value % inner_value != 0) { - bool is_equality = comparison.type == ExpressionType::COMPARE_EQUAL; - bool is_inequality = comparison.type == ExpressionType::COMPARE_NOTEQUAL; + bool is_equality = comparison.GetExpressionType() == ExpressionType::COMPARE_EQUAL; + bool is_inequality = comparison.GetExpressionType() == ExpressionType::COMPARE_NOTEQUAL; if (is_equality || is_inequality) { // we know the values are not equal // the result will be either FALSE or NULL (if COMPARE_EQUAL) @@ -141,7 +141,7 @@ unique_ptr MoveConstantsRule::Apply(LogicalOperator &op, vector StatisticsPropagator::PropagateExpression(BoundCompar return nullptr; } // propagate the statistics of the comparison operator - auto propagate_result = PropagateComparison(*left_stats, *right_stats, expr.type); + auto propagate_result = PropagateComparison(*left_stats, *right_stats, expr.GetExpressionType()); switch (propagate_result) { case FilterPropagateResult::FILTER_ALWAYS_TRUE: expr_ptr = make_uniq(Value::BOOLEAN(true)); diff --git a/src/duckdb/src/optimizer/statistics/expression/propagate_conjunction.cpp b/src/duckdb/src/optimizer/statistics/expression/propagate_conjunction.cpp index d4431afa..31e415f1 100644 --- a/src/duckdb/src/optimizer/statistics/expression/propagate_conjunction.cpp +++ b/src/duckdb/src/optimizer/statistics/expression/propagate_conjunction.cpp @@ -9,7 +9,7 @@ namespace duckdb { unique_ptr StatisticsPropagator::PropagateExpression(BoundConjunctionExpression &expr, unique_ptr &expr_ptr) { - auto is_and = expr.type == ExpressionType::CONJUNCTION_AND; + auto is_and = expr.GetExpressionType() == ExpressionType::CONJUNCTION_AND; for (idx_t expr_idx = 0; expr_idx < expr.children.size(); expr_idx++) { auto &child = expr.children[expr_idx]; auto stats = PropagateExpression(child); diff --git a/src/duckdb/src/optimizer/statistics/expression/propagate_operator.cpp b/src/duckdb/src/optimizer/statistics/expression/propagate_operator.cpp index 0733fc74..23445947 100644 --- a/src/duckdb/src/optimizer/statistics/expression/propagate_operator.cpp +++ b/src/duckdb/src/optimizer/statistics/expression/propagate_operator.cpp @@ -19,7 +19,7 @@ unique_ptr StatisticsPropagator::PropagateExpression(BoundOperat if (!all_have_stats) { return nullptr; } - switch (expr.type) { + switch (expr.GetExpressionType()) { case ExpressionType::OPERATOR_COALESCE: // COALESCE, merge stats of all children for (idx_t i = 0; i < expr.children.size(); i++) { diff --git a/src/duckdb/src/optimizer/statistics/operator/propagate_aggregate.cpp b/src/duckdb/src/optimizer/statistics/operator/propagate_aggregate.cpp index 31ff7e63..811d01c9 100644 --- a/src/duckdb/src/optimizer/statistics/operator/propagate_aggregate.cpp +++ b/src/duckdb/src/optimizer/statistics/operator/propagate_aggregate.cpp @@ -29,7 +29,7 @@ void StatisticsPropagator::TryExecuteAggregates(LogicalAggregate &aggr, unique_p } // check if all aggregates are COUNT(*) for (auto &aggr_ref : aggr.expressions) { - if (aggr_ref->expression_class != ExpressionClass::BOUND_AGGREGATE) { + if (aggr_ref->GetExpressionClass() != ExpressionClass::BOUND_AGGREGATE) { // not an aggregate return; } @@ -59,7 +59,7 @@ void StatisticsPropagator::TryExecuteAggregates(LogicalAggregate &aggr, unique_p vector> count_results; for (idx_t aggregate_index = 0; aggregate_index < aggr.expressions.size(); ++aggregate_index) { auto count_result = make_uniq(Value::BIGINT(NumericCast(count))); - count_result->alias = aggr.expressions[aggregate_index]->GetName(); + count_result->SetAlias(aggr.expressions[aggregate_index]->GetName()); count_results.push_back(std::move(count_result)); types.push_back(LogicalType::BIGINT); diff --git a/src/duckdb/src/optimizer/statistics/operator/propagate_filter.cpp b/src/duckdb/src/optimizer/statistics/operator/propagate_filter.cpp index 1cb37da9..1c555be4 100644 --- a/src/duckdb/src/optimizer/statistics/operator/propagate_filter.cpp +++ b/src/duckdb/src/optimizer/statistics/operator/propagate_filter.cpp @@ -161,23 +161,26 @@ void StatisticsPropagator::UpdateFilterStatistics(Expression &left, Expression & // first check if either side is a bound column ref // any column ref involved in a comparison will not be null after the comparison bool compare_distinct = IsCompareDistinct(comparison_type); - if (!compare_distinct && left.type == ExpressionType::BOUND_COLUMN_REF) { + if (!compare_distinct && left.GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { SetStatisticsNotNull((left.Cast()).binding); } - if (!compare_distinct && right.type == ExpressionType::BOUND_COLUMN_REF) { + if (!compare_distinct && right.GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { SetStatisticsNotNull((right.Cast()).binding); } // check if this is a comparison between a constant and a column ref optional_ptr constant; optional_ptr columnref; - if (left.type == ExpressionType::VALUE_CONSTANT && right.type == ExpressionType::BOUND_COLUMN_REF) { + if (left.GetExpressionType() == ExpressionType::VALUE_CONSTANT && + right.GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { constant = &left.Cast(); columnref = &right.Cast(); comparison_type = FlipComparisonExpression(comparison_type); - } else if (left.type == ExpressionType::BOUND_COLUMN_REF && right.type == ExpressionType::VALUE_CONSTANT) { + } else if (left.GetExpressionType() == ExpressionType::BOUND_COLUMN_REF && + right.GetExpressionType() == ExpressionType::VALUE_CONSTANT) { columnref = &left.Cast(); constant = &right.Cast(); - } else if (left.type == ExpressionType::BOUND_COLUMN_REF && right.type == ExpressionType::BOUND_COLUMN_REF) { + } else if (left.GetExpressionType() == ExpressionType::BOUND_COLUMN_REF && + right.GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { // comparison between two column refs auto &left_column_ref = left.Cast(); auto &right_column_ref = right.Cast(); @@ -213,7 +216,7 @@ void StatisticsPropagator::UpdateFilterStatistics(Expression &condition) { } case ExpressionClass::BOUND_COMPARISON: { auto &comparison = condition.Cast(); - UpdateFilterStatistics(*comparison.left, *comparison.right, comparison.type); + UpdateFilterStatistics(*comparison.left, *comparison.right, comparison.GetExpressionType()); break; } default: diff --git a/src/duckdb/src/optimizer/statistics/operator/propagate_join.cpp b/src/duckdb/src/optimizer/statistics/operator/propagate_join.cpp index c3d0b0c6..1787a7f2 100644 --- a/src/duckdb/src/optimizer/statistics/operator/propagate_join.cpp +++ b/src/duckdb/src/optimizer/statistics/operator/propagate_join.cpp @@ -157,8 +157,8 @@ void StatisticsPropagator::PropagateStatistics(LogicalComparisonJoin &join, uniq // Try to push lhs stats down rhs and vice versa if (stats_left && stats_right && updated_stats_left && updated_stats_right && - condition.left->type == ExpressionType::BOUND_COLUMN_REF && - condition.right->type == ExpressionType::BOUND_COLUMN_REF) { + condition.left->GetExpressionType() == ExpressionType::BOUND_COLUMN_REF && + condition.right->GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { CreateFilterFromJoinStats(join.children[0], condition.left, *stats_left, *updated_stats_left); CreateFilterFromJoinStats(join.children[1], condition.right, *stats_right, *updated_stats_right); } @@ -324,7 +324,7 @@ void StatisticsPropagator::CreateFilterFromJoinStats(unique_ptr const BaseStatistics &stats_before, const BaseStatistics &stats_after) { // Only do this for integral colref's that have stats - if (expr->type != ExpressionType::BOUND_COLUMN_REF || !expr->return_type.IsIntegral() || + if (expr->GetExpressionType() != ExpressionType::BOUND_COLUMN_REF || !expr->return_type.IsIntegral() || !NumericStats::HasMinMax(stats_before) || !NumericStats::HasMinMax(stats_after)) { return; } diff --git a/src/duckdb/src/optimizer/sum_rewriter.cpp b/src/duckdb/src/optimizer/sum_rewriter.cpp index 3c73b506..58714411 100644 --- a/src/duckdb/src/optimizer/sum_rewriter.cpp +++ b/src/duckdb/src/optimizer/sum_rewriter.cpp @@ -109,7 +109,7 @@ void SumRewriterOptimizer::RewriteSums(unique_ptr &op) { // found SUM(x + C) auto &sum = bindings[0].get().Cast(); auto &addition = bindings[1].get().Cast(); - idx_t const_idx = addition.children[0]->type == ExpressionType::VALUE_CONSTANT ? 0 : 1; + idx_t const_idx = addition.children[0]->GetExpressionType() == ExpressionType::VALUE_CONSTANT ? 0 : 1; auto const_expr = std::move(addition.children[const_idx]); auto main_expr = std::move(addition.children[1 - const_idx]); diff --git a/src/duckdb/src/optimizer/topn_optimizer.cpp b/src/duckdb/src/optimizer/topn_optimizer.cpp index b700a49e..0bfd8119 100644 --- a/src/duckdb/src/optimizer/topn_optimizer.cpp +++ b/src/duckdb/src/optimizer/topn_optimizer.cpp @@ -51,7 +51,7 @@ void TopN::PushdownDynamicFilters(LogicalTopN &op) { // only supported for integral types currently return; } - if (op.orders[0].expression->type != ExpressionType::BOUND_COLUMN_REF) { + if (op.orders[0].expression->GetExpressionType() != ExpressionType::BOUND_COLUMN_REF) { // we can only pushdown on ORDER BY [col] currently return; } diff --git a/src/duckdb/src/optimizer/unnest_rewriter.cpp b/src/duckdb/src/optimizer/unnest_rewriter.cpp index e5f9ccf4..4c4207e2 100644 --- a/src/duckdb/src/optimizer/unnest_rewriter.cpp +++ b/src/duckdb/src/optimizer/unnest_rewriter.cpp @@ -19,7 +19,7 @@ void UnnestRewriterPlanUpdater::VisitOperator(LogicalOperator &op) { void UnnestRewriterPlanUpdater::VisitExpression(unique_ptr *expression) { auto &expr = *expression; - if (expr->expression_class == ExpressionClass::BOUND_COLUMN_REF) { + if (expr->GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF) { auto &bound_column_ref = expr->Cast(); for (idx_t i = 0; i < replace_bindings.size(); i++) { if (bound_column_ref.binding == replace_bindings[i].old_binding) { @@ -301,7 +301,7 @@ void UnnestRewriter::GetDelimColumns(LogicalOperator &op) { auto &delim_join = op.Cast(); for (idx_t i = 0; i < delim_join.duplicate_eliminated_columns.size(); i++) { auto &expr = *delim_join.duplicate_eliminated_columns[i]; - D_ASSERT(expr.type == ExpressionType::BOUND_COLUMN_REF); + D_ASSERT(expr.GetExpressionType() == ExpressionType::BOUND_COLUMN_REF); auto &bound_colref_expr = expr.Cast(); delim_columns.push_back(bound_colref_expr.binding); } @@ -326,7 +326,7 @@ void UnnestRewriter::GetLHSExpressions(LogicalOperator &op) { lhs_bindings.emplace_back(col_bindings[i], op.types[i]); if (set_alias) { auto &proj = op.Cast(); - lhs_bindings.back().alias = proj.expressions[i]->alias; + lhs_bindings.back().alias = proj.expressions[i]->GetAlias(); } } } diff --git a/src/duckdb/src/parser/column_definition.cpp b/src/duckdb/src/parser/column_definition.cpp index 245bcd47..4718c40c 100644 --- a/src/duckdb/src/parser/column_definition.cpp +++ b/src/duckdb/src/parser/column_definition.cpp @@ -123,7 +123,7 @@ bool ColumnDefinition::Generated() const { //===--------------------------------------------------------------------===// static void VerifyColumnRefs(ParsedExpression &expr) { - if (expr.type == ExpressionType::COLUMN_REF) { + if (expr.GetExpressionType() == ExpressionType::COLUMN_REF) { auto &column_ref = expr.Cast(); if (column_ref.IsQualified()) { throw ParserException( @@ -135,13 +135,13 @@ static void VerifyColumnRefs(ParsedExpression &expr) { } static void InnerGetListOfDependencies(ParsedExpression &expr, vector &dependencies) { - if (expr.type == ExpressionType::COLUMN_REF) { + if (expr.GetExpressionType() == ExpressionType::COLUMN_REF) { auto columnref = expr.Cast(); auto &name = columnref.GetColumnName(); dependencies.push_back(name); } ParsedExpressionIterator::EnumerateChildren(expr, [&](const ParsedExpression &child) { - if (expr.type == ExpressionType::LAMBDA) { + if (expr.GetExpressionType() == ExpressionType::LAMBDA) { throw NotImplementedException("Lambda functions are currently not supported in generated columns."); } InnerGetListOfDependencies((ParsedExpression &)child, dependencies); diff --git a/src/duckdb/src/parser/expression/conjunction_expression.cpp b/src/duckdb/src/parser/expression/conjunction_expression.cpp index 78a076bf..a11759b8 100644 --- a/src/duckdb/src/parser/expression/conjunction_expression.cpp +++ b/src/duckdb/src/parser/expression/conjunction_expression.cpp @@ -26,7 +26,7 @@ ConjunctionExpression::ConjunctionExpression(ExpressionType type, unique_ptr expr) { - if (expr->type == type) { + if (expr->GetExpressionType() == type) { // expr is a conjunction of the same type: merge the expression lists together auto &other = expr->Cast(); for (auto &child : other.children) { diff --git a/src/duckdb/src/parser/expression/function_expression.cpp b/src/duckdb/src/parser/expression/function_expression.cpp index 8cd5d4c7..a38b3024 100644 --- a/src/duckdb/src/parser/expression/function_expression.cpp +++ b/src/duckdb/src/parser/expression/function_expression.cpp @@ -102,7 +102,7 @@ bool FunctionExpression::IsLambdaFunction() const { } // Check the children for lambda expressions. for (auto &child : children) { - if (child->expression_class == ExpressionClass::LAMBDA) { + if (child->GetExpressionClass() == ExpressionClass::LAMBDA) { return true; } } diff --git a/src/duckdb/src/parser/expression/lambda_expression.cpp b/src/duckdb/src/parser/expression/lambda_expression.cpp index be503411..bdf32e6c 100644 --- a/src/duckdb/src/parser/expression/lambda_expression.cpp +++ b/src/duckdb/src/parser/expression/lambda_expression.cpp @@ -22,13 +22,13 @@ vector> LambdaExpression::ExtractColumnRefExpression // since we can't distinguish between a lambda function and the JSON operator yet vector> column_refs; - if (lhs->expression_class == ExpressionClass::COLUMN_REF) { + if (lhs->GetExpressionClass() == ExpressionClass::COLUMN_REF) { // single column reference column_refs.emplace_back(*lhs); return column_refs; } - if (lhs->expression_class == ExpressionClass::FUNCTION) { + if (lhs->GetExpressionClass() == ExpressionClass::FUNCTION) { // list of column references auto &func_expr = lhs->Cast(); if (func_expr.function_name != "row") { @@ -37,7 +37,7 @@ vector> LambdaExpression::ExtractColumnRefExpression } for (auto &child : func_expr.children) { - if (child->expression_class != ExpressionClass::COLUMN_REF) { + if (child->GetExpressionClass() != ExpressionClass::COLUMN_REF) { error_message = InvalidParametersErrorMessage(); return column_refs; } diff --git a/src/duckdb/src/parser/parsed_data/create_index_info.cpp b/src/duckdb/src/parser/parsed_data/create_index_info.cpp index 7fd3a220..1d062a70 100644 --- a/src/duckdb/src/parser/parsed_data/create_index_info.cpp +++ b/src/duckdb/src/parser/parsed_data/create_index_info.cpp @@ -40,7 +40,7 @@ vector CreateIndexInfo::ExpressionsToList() const { // We need to remove them to reproduce the original query. RemoveTableQualificationRecursive(copy, table); bool add_parenthesis = true; - if (copy->type == ExpressionType::COLUMN_REF) { + if (copy->GetExpressionType() == ExpressionType::COLUMN_REF) { auto &column_ref = copy->Cast(); if (!column_ref.IsQualified()) { // Only not qualified references like (col1, col2) don't need parenthesis. diff --git a/src/duckdb/src/parser/parsed_expression.cpp b/src/duckdb/src/parser/parsed_expression.cpp index 617d60a3..1ba33bfd 100644 --- a/src/duckdb/src/parser/parsed_expression.cpp +++ b/src/duckdb/src/parser/parsed_expression.cpp @@ -94,7 +94,7 @@ bool ParsedExpression::Equals(const BaseExpression &other) const { } hash_t ParsedExpression::Hash() const { - hash_t hash = duckdb::Hash((uint32_t)type); + hash_t hash = duckdb::Hash(static_cast(type)); ParsedExpressionIterator::EnumerateChildren( *this, [&](const ParsedExpression &child) { hash = CombineHash(child.Hash(), hash); }); return hash; diff --git a/src/duckdb/src/parser/parsed_expression_iterator.cpp b/src/duckdb/src/parser/parsed_expression_iterator.cpp index 2553ef00..ca1df3a6 100644 --- a/src/duckdb/src/parser/parsed_expression_iterator.cpp +++ b/src/duckdb/src/parser/parsed_expression_iterator.cpp @@ -28,7 +28,7 @@ void ParsedExpressionIterator::EnumerateChildren(ParsedExpression &expr, void ParsedExpressionIterator::EnumerateChildren( ParsedExpression &expr, const std::function &child)> &callback) { - switch (expr.expression_class) { + switch (expr.GetExpressionClass()) { case ExpressionClass::BETWEEN: { auto &cast_expr = expr.Cast(); callback(cast_expr.input); diff --git a/src/duckdb/src/parser/query_node/select_node.cpp b/src/duckdb/src/parser/query_node/select_node.cpp index f42dafdc..3c3e4537 100644 --- a/src/duckdb/src/parser/query_node/select_node.cpp +++ b/src/duckdb/src/parser/query_node/select_node.cpp @@ -41,8 +41,8 @@ string SelectNode::ToString() const { result += ", "; } result += select_list[i]->ToString(); - if (!select_list[i]->alias.empty()) { - result += StringUtil::Format(" AS %s", SQLIdentifier(select_list[i]->alias)); + if (!select_list[i]->GetAlias().empty()) { + result += StringUtil::Format(" AS %s", SQLIdentifier(select_list[i]->GetAlias())); } } if (from_table && from_table->type != TableReferenceType::EMPTY_FROM) { diff --git a/src/duckdb/src/parser/statement/delete_statement.cpp b/src/duckdb/src/parser/statement/delete_statement.cpp index 0d97068e..0c3293e2 100644 --- a/src/duckdb/src/parser/statement/delete_statement.cpp +++ b/src/duckdb/src/parser/statement/delete_statement.cpp @@ -44,8 +44,9 @@ string DeleteStatement::ToString() const { result += ", "; } auto column = returning_list[i]->ToString(); - if (!returning_list[i]->alias.empty()) { - column += StringUtil::Format(" AS %s", KeywordHelper::WriteOptionallyQuoted(returning_list[i]->alias)); + if (!returning_list[i]->GetAlias().empty()) { + column += + StringUtil::Format(" AS %s", KeywordHelper::WriteOptionallyQuoted(returning_list[i]->GetAlias())); } result += column; } diff --git a/src/duckdb/src/parser/statement/insert_statement.cpp b/src/duckdb/src/parser/statement/insert_statement.cpp index fc384232..f59a2ef3 100644 --- a/src/duckdb/src/parser/statement/insert_statement.cpp +++ b/src/duckdb/src/parser/statement/insert_statement.cpp @@ -157,8 +157,9 @@ string InsertStatement::ToString() const { result += ", "; } auto column = returning_list[i]->ToString(); - if (!returning_list[i]->alias.empty()) { - column += StringUtil::Format(" AS %s", KeywordHelper::WriteOptionallyQuoted(returning_list[i]->alias)); + if (!returning_list[i]->GetAlias().empty()) { + column += + StringUtil::Format(" AS %s", KeywordHelper::WriteOptionallyQuoted(returning_list[i]->GetAlias())); } result += column; } @@ -190,7 +191,7 @@ optional_ptr InsertStatement::GetValuesList() const { if (node.aggregate_handling != AggregateHandling::STANDARD_HANDLING) { return nullptr; } - if (node.select_list.size() != 1 || node.select_list[0]->type != ExpressionType::STAR) { + if (node.select_list.size() != 1 || node.select_list[0]->GetExpressionType() != ExpressionType::STAR) { return nullptr; } if (!node.from_table || node.from_table->type != TableReferenceType::EXPRESSION_LIST) { diff --git a/src/duckdb/src/parser/statement/update_statement.cpp b/src/duckdb/src/parser/statement/update_statement.cpp index 83520094..cabd1d36 100644 --- a/src/duckdb/src/parser/statement/update_statement.cpp +++ b/src/duckdb/src/parser/statement/update_statement.cpp @@ -66,8 +66,9 @@ string UpdateStatement::ToString() const { result += ", "; } auto column = returning_list[i]->ToString(); - if (!returning_list[i]->alias.empty()) { - column += StringUtil::Format(" AS %s", KeywordHelper::WriteOptionallyQuoted(returning_list[i]->alias)); + if (!returning_list[i]->GetAlias().empty()) { + column += + StringUtil::Format(" AS %s", KeywordHelper::WriteOptionallyQuoted(returning_list[i]->GetAlias())); } result += column; } diff --git a/src/duckdb/src/parser/tableref/pivotref.cpp b/src/duckdb/src/parser/tableref/pivotref.cpp index 341aa956..ffeef36f 100644 --- a/src/duckdb/src/parser/tableref/pivotref.cpp +++ b/src/duckdb/src/parser/tableref/pivotref.cpp @@ -143,8 +143,8 @@ string PivotRef::ToString() const { result += ", "; } result += aggregates[aggr_idx]->ToString(); - if (!aggregates[aggr_idx]->alias.empty()) { - result += " AS " + KeywordHelper::WriteOptionallyQuoted(aggregates[aggr_idx]->alias); + if (!aggregates[aggr_idx]->GetAlias().empty()) { + result += " AS " + KeywordHelper::WriteOptionallyQuoted(aggregates[aggr_idx]->GetAlias()); } } } else { diff --git a/src/duckdb/src/parser/transform/expression/transform_array_access.cpp b/src/duckdb/src/parser/transform/expression/transform_array_access.cpp index b5d149d5..447688c6 100644 --- a/src/duckdb/src/parser/transform/expression/transform_array_access.cpp +++ b/src/duckdb/src/parser/transform/expression/transform_array_access.cpp @@ -60,7 +60,7 @@ unique_ptr Transformer::TransformArrayAccess(duckdb_libpgquery case duckdb_libpgquery::T_PGFuncCall: { auto func = PGCast(*target.get()); auto function = TransformFuncCall(func); - if (function->type != ExpressionType::FUNCTION) { + if (function->GetExpressionType() != ExpressionType::FUNCTION) { throw ParserException("%s.%s() call must be a function", result->ToString(), function->ToString()); } auto &function_expr = function->Cast(); diff --git a/src/duckdb/src/parser/transform/expression/transform_bool_expr.cpp b/src/duckdb/src/parser/transform/expression/transform_bool_expr.cpp index 40a98ccb..76078f5e 100644 --- a/src/duckdb/src/parser/transform/expression/transform_bool_expr.cpp +++ b/src/duckdb/src/parser/transform/expression/transform_bool_expr.cpp @@ -29,15 +29,15 @@ unique_ptr Transformer::TransformBoolExpr(duckdb_libpgquery::P break; } case duckdb_libpgquery::PG_NOT_EXPR: { - if (next->type == ExpressionType::COMPARE_IN) { + if (next->GetExpressionType() == ExpressionType::COMPARE_IN) { // convert COMPARE_IN to COMPARE_NOT_IN - next->type = ExpressionType::COMPARE_NOT_IN; + next->SetExpressionTypeUnsafe(ExpressionType::COMPARE_NOT_IN); result = std::move(next); - } else if (next->type >= ExpressionType::COMPARE_EQUAL && - next->type <= ExpressionType::COMPARE_GREATERTHANOREQUALTO) { + } else if (next->GetExpressionType() >= ExpressionType::COMPARE_EQUAL && + next->GetExpressionType() <= ExpressionType::COMPARE_GREATERTHANOREQUALTO) { // NOT on a comparison: we can negate the comparison // e.g. NOT(x > y) is equivalent to x <= y - next->type = NegateComparisonExpression(next->type); + next->SetExpressionTypeUnsafe(NegateComparisonExpression(next->GetExpressionType())); result = std::move(next); } else { result = make_uniq(ExpressionType::OPERATOR_NOT, std::move(next)); diff --git a/src/duckdb/src/parser/transform/expression/transform_columnref.cpp b/src/duckdb/src/parser/transform/expression/transform_columnref.cpp index 5a8e0c90..a232219f 100644 --- a/src/duckdb/src/parser/transform/expression/transform_columnref.cpp +++ b/src/duckdb/src/parser/transform/expression/transform_columnref.cpp @@ -97,7 +97,7 @@ unique_ptr Transformer::TransformStarExpression(duckdb_libpgqu result->exclude_list = std::move(child_star.exclude_list); result->replace_list = std::move(child_star.replace_list); result->expr.reset(); - } else if (result->expr->type == ExpressionType::LAMBDA) { + } else if (result->expr->GetExpressionType() == ExpressionType::LAMBDA) { vector> children; children.push_back(make_uniq()); children.push_back(std::move(result->expr)); diff --git a/src/duckdb/src/parser/transform/expression/transform_constant.cpp b/src/duckdb/src/parser/transform/expression/transform_constant.cpp index c8c76c19..88fd295f 100644 --- a/src/duckdb/src/parser/transform/expression/transform_constant.cpp +++ b/src/duckdb/src/parser/transform/expression/transform_constant.cpp @@ -97,7 +97,7 @@ unique_ptr Transformer::TransformConstant(duckdb_libpgquery::P bool Transformer::ConstructConstantFromExpression(const ParsedExpression &expr, Value &value) { // We have to construct it like this because we don't have the ClientContext for binding/executing the expr here - switch (expr.type) { + switch (expr.GetExpressionType()) { case ExpressionType::FUNCTION: { auto &function = expr.Cast(); if (function.function_name == "struct_pack") { @@ -105,14 +105,14 @@ bool Transformer::ConstructConstantFromExpression(const ParsedExpression &expr, child_list_t values; values.reserve(function.children.size()); for (const auto &child : function.children) { - if (!unique_names.insert(child->alias).second) { - throw BinderException("Duplicate struct entry name \"%s\"", child->alias); + if (!unique_names.insert(child->GetAlias()).second) { + throw BinderException("Duplicate struct entry name \"%s\"", child->GetAlias()); } Value child_value; if (!ConstructConstantFromExpression(*child, child_value)) { return false; } - values.emplace_back(child->alias, std::move(child_value)); + values.emplace_back(child->GetAlias(), std::move(child_value)); } value = Value::STRUCT(std::move(values)); return true; diff --git a/src/duckdb/src/parser/transform/expression/transform_expression.cpp b/src/duckdb/src/parser/transform/expression/transform_expression.cpp index 9f7e7a89..1f64c8ed 100644 --- a/src/duckdb/src/parser/transform/expression/transform_expression.cpp +++ b/src/duckdb/src/parser/transform/expression/transform_expression.cpp @@ -10,7 +10,7 @@ unique_ptr Transformer::TransformResTarget(duckdb_libpgquery:: return nullptr; } if (root.name) { - expr->alias = string(root.name); + expr->SetAlias(root.name); } return expr; } @@ -19,7 +19,7 @@ unique_ptr Transformer::TransformNamedArg(duckdb_libpgquery::P auto expr = TransformExpression(PGPointerCast(root.arg)); if (root.name) { - expr->alias = string(root.name); + expr->SetAlias(root.name); } return expr; } diff --git a/src/duckdb/src/parser/transform/expression/transform_function.cpp b/src/duckdb/src/parser/transform/expression/transform_function.cpp index 5ce6e98a..951f1df6 100644 --- a/src/duckdb/src/parser/transform/expression/transform_function.cpp +++ b/src/duckdb/src/parser/transform/expression/transform_function.cpp @@ -90,7 +90,7 @@ void Transformer::TransformWindowFrame(duckdb_libpgquery::PGWindowDef &window_sp } bool Transformer::ExpressionIsEmptyStar(ParsedExpression &expr) { - if (expr.expression_class != ExpressionClass::STAR) { + if (expr.GetExpressionClass() != ExpressionClass::STAR) { return false; } auto &star = expr.Cast(); diff --git a/src/duckdb/src/parser/transform/expression/transform_operator.cpp b/src/duckdb/src/parser/transform/expression/transform_operator.cpp index fdc9393d..46a2d6c0 100644 --- a/src/duckdb/src/parser/transform/expression/transform_operator.cpp +++ b/src/duckdb/src/parser/transform/expression/transform_operator.cpp @@ -168,7 +168,7 @@ unique_ptr Transformer::TransformAExprInternal(duckdb_libpgque auto &similar_func = right_expr->Cast(); D_ASSERT(similar_func.function_name == "similar_escape"); D_ASSERT(similar_func.children.size() == 2); - if (similar_func.children[1]->type != ExpressionType::VALUE_CONSTANT) { + if (similar_func.children[1]->GetExpressionType() != ExpressionType::VALUE_CONSTANT) { throw NotImplementedException("Custom escape in SIMILAR TO"); } auto &constant = similar_func.children[1]->Cast(); diff --git a/src/duckdb/src/parser/transform/expression/transform_subquery.cpp b/src/duckdb/src/parser/transform/expression/transform_subquery.cpp index 194ee5e1..6f6d7420 100644 --- a/src/duckdb/src/parser/transform/expression/transform_subquery.cpp +++ b/src/duckdb/src/parser/transform/expression/transform_subquery.cpp @@ -109,7 +109,7 @@ unique_ptr Transformer::TransformSubquery(duckdb_libpgquery::P // transform constants (e.g. ORDER BY 1) into positional references (ORDER BY #1) if (aggr->order_bys) { for (auto &order : aggr->order_bys->orders) { - if (order.expression->type == ExpressionType::VALUE_CONSTANT) { + if (order.expression->GetExpressionType() == ExpressionType::VALUE_CONSTANT) { auto &constant_expr = order.expression->Cast(); Value bigint_value; string error; diff --git a/src/duckdb/src/parser/transform/helpers/transform_groupby.cpp b/src/duckdb/src/parser/transform/helpers/transform_groupby.cpp index c61071c4..2a8a95c9 100644 --- a/src/duckdb/src/parser/transform/helpers/transform_groupby.cpp +++ b/src/duckdb/src/parser/transform/helpers/transform_groupby.cpp @@ -40,7 +40,7 @@ static void MergeGroupingSet(GroupingSet &result, GroupingSet &other) { void Transformer::AddGroupByExpression(unique_ptr expression, GroupingExpressionMap &map, GroupByNode &result, vector &result_set) { - if (expression->type == ExpressionType::FUNCTION) { + if (expression->GetExpressionType() == ExpressionType::FUNCTION) { auto &func = expression->Cast(); if (func.function_name == "row") { for (auto &child : func.children) { diff --git a/src/duckdb/src/parser/transform/helpers/transform_sample.cpp b/src/duckdb/src/parser/transform/helpers/transform_sample.cpp index 65f66927..bd1cc75a 100644 --- a/src/duckdb/src/parser/transform/helpers/transform_sample.cpp +++ b/src/duckdb/src/parser/transform/helpers/transform_sample.cpp @@ -26,8 +26,8 @@ unique_ptr Transformer::TransformSampleOptions(optional_ptr(*options); auto &sample_size = *PGPointerCast(sample_options.sample_size); auto sample_expression = TransformExpression(sample_size.sample_size); - if (sample_expression->type != ExpressionType::VALUE_CONSTANT) { - throw ParserException(sample_expression->query_location, + if (sample_expression->GetExpressionType() != ExpressionType::VALUE_CONSTANT) { + throw ParserException(sample_expression->GetQueryLocation(), "Only constants are supported in sample clause currently"); } auto &const_expr = sample_expression->Cast(); diff --git a/src/duckdb/src/parser/transform/statement/transform_comment_on.cpp b/src/duckdb/src/parser/transform/statement/transform_comment_on.cpp index 097b0c27..6ab5d9e6 100644 --- a/src/duckdb/src/parser/transform/statement/transform_comment_on.cpp +++ b/src/duckdb/src/parser/transform/statement/transform_comment_on.cpp @@ -46,7 +46,7 @@ unique_ptr Transformer::TransformCommentOn(duckdb_libpgquery::PG unique_ptr info; auto expr = TransformExpression(stmt.value); - if (expr->expression_class != ExpressionClass::CONSTANT) { + if (expr->GetExpressionClass() != ExpressionClass::CONSTANT) { throw NotImplementedException("Can only use constants as comments"); } auto comment_value = expr->Cast().value; diff --git a/src/duckdb/src/parser/transform/statement/transform_create_function.cpp b/src/duckdb/src/parser/transform/statement/transform_create_function.cpp index 82917ee2..6fdb68aa 100644 --- a/src/duckdb/src/parser/transform/statement/transform_create_function.cpp +++ b/src/duckdb/src/parser/transform/statement/transform_create_function.cpp @@ -26,15 +26,15 @@ unique_ptr Transformer::TransformMacroFunction(duckdb_libpgquery: Value const_param; if (ConstructConstantFromExpression(*param, const_param)) { // parameters with default value (must have an alias) - if (param->alias.empty()) { + if (param->GetAlias().empty()) { throw ParserException("Invalid parameter: '%s'", param->ToString()); } - if (macro_func->default_parameters.find(param->alias) != macro_func->default_parameters.end()) { - throw ParserException("Duplicate default parameter: '%s'", param->alias); + if (macro_func->default_parameters.find(param->GetAlias()) != macro_func->default_parameters.end()) { + throw ParserException("Duplicate default parameter: '%s'", param->GetAlias()); } auto constructed_constant = make_uniq(std::move(const_param)); - constructed_constant->alias = param->alias; - macro_func->default_parameters[param->alias] = std::move(constructed_constant); + constructed_constant->SetAlias(param->GetAlias()); + macro_func->default_parameters[param->GetAlias()] = std::move(constructed_constant); } else if (param->GetExpressionClass() == ExpressionClass::COLUMN_REF) { // positional parameters if (!macro_func->default_parameters.empty()) { diff --git a/src/duckdb/src/parser/transform/statement/transform_pragma.cpp b/src/duckdb/src/parser/transform/statement/transform_pragma.cpp index 63a5c35d..c0ff7b8c 100644 --- a/src/duckdb/src/parser/transform/statement/transform_pragma.cpp +++ b/src/duckdb/src/parser/transform/statement/transform_pragma.cpp @@ -21,14 +21,14 @@ unique_ptr Transformer::TransformPragma(duckdb_libpgquery::PGPragm auto node = PGPointerCast(cell->data.ptr_value); auto expr = TransformExpression(node); - if (expr->type == ExpressionType::COMPARE_EQUAL) { + if (expr->GetExpressionType() == ExpressionType::COMPARE_EQUAL) { auto &comp = expr->Cast(); - if (comp.left->type != ExpressionType::COLUMN_REF) { + if (comp.left->GetExpressionType() != ExpressionType::COLUMN_REF) { throw ParserException("Named parameter requires a column reference on the LHS"); } auto &columnref = comp.left->Cast(); info.named_parameters.insert(make_pair(columnref.GetName(), std::move(comp.right))); - } else if (expr->type == ExpressionType::COLUMN_REF) { + } else if (expr->GetExpressionType() == ExpressionType::COLUMN_REF) { auto &colref = expr->Cast(); if (!colref.IsQualified()) { info.parameters.emplace_back(make_uniq(Value(colref.GetColumnName()))); diff --git a/src/duckdb/src/parser/transform/statement/transform_prepare.cpp b/src/duckdb/src/parser/transform/statement/transform_prepare.cpp index 54667312..9c1fc9ba 100644 --- a/src/duckdb/src/parser/transform/statement/transform_prepare.cpp +++ b/src/duckdb/src/parser/transform/statement/transform_prepare.cpp @@ -39,19 +39,19 @@ unique_ptr Transformer::TransformExecute(duckdb_libpgquery::PG if (!expr->IsScalar()) { throw InvalidInputException(NotAcceptedExpressionException()); } - if (!expr->alias.empty() && param_idx != 0) { + if (!expr->GetAlias().empty() && param_idx != 0) { // Found unnamed parameters mixed with named parameters throw NotImplementedException("Mixing named parameters and positional parameters is not supported yet"); } - auto param_name = expr->alias; - if (expr->alias.empty()) { + auto param_name = expr->GetAlias(); + if (expr->GetAlias().empty()) { param_name = std::to_string(param_idx + 1); if (param_idx != i) { throw NotImplementedException("Mixing named parameters and positional parameters is not supported yet"); } param_idx++; } - expr->alias.clear(); + expr->ClearAlias(); result->named_values[param_name] = std::move(expr); } intermediate_values.clear(); diff --git a/src/duckdb/src/parser/transform/statement/transform_set.cpp b/src/duckdb/src/parser/transform/statement/transform_set.cpp index 68dae931..6df82aec 100644 --- a/src/duckdb/src/parser/transform/statement/transform_set.cpp +++ b/src/duckdb/src/parser/transform/statement/transform_set.cpp @@ -52,7 +52,7 @@ unique_ptr Transformer::TransformSetVariable(duckdb_libpgquery::PG D_ASSERT(stmt.args->head && stmt.args->head->data.ptr_value); auto const_val = PGPointerCast(stmt.args->head->data.ptr_value); auto expr = TransformExpression(const_val); - if (expr->type == ExpressionType::COLUMN_REF) { + if (expr->GetExpressionType() == ExpressionType::COLUMN_REF) { auto &colref = expr->Cast(); Value val; if (!colref.IsQualified()) { @@ -62,7 +62,7 @@ unique_ptr Transformer::TransformSetVariable(duckdb_libpgquery::PG } expr = make_uniq(std::move(val)); } - if (expr->type == ExpressionType::VALUE_DEFAULT) { + if (expr->GetExpressionType() == ExpressionType::VALUE_DEFAULT) { // set to default = reset return make_uniq(std::move(name), scope); } diff --git a/src/duckdb/src/parser/transform/tableref/transform_pivot.cpp b/src/duckdb/src/parser/transform/tableref/transform_pivot.cpp index 62ca0e1b..3a51ba0f 100644 --- a/src/duckdb/src/parser/transform/tableref/transform_pivot.cpp +++ b/src/duckdb/src/parser/transform/tableref/transform_pivot.cpp @@ -8,11 +8,11 @@ namespace duckdb { bool Transformer::TransformPivotInList(unique_ptr &expr, PivotColumnEntry &entry, bool root_entry) { - switch (expr->type) { + switch (expr->GetExpressionType()) { case ExpressionType::COLUMN_REF: { auto &colref = expr->Cast(); if (colref.IsQualified()) { - throw ParserException(expr->query_location, "PIVOT IN list cannot contain qualified column references"); + throw ParserException(expr->GetQueryLocation(), "PIVOT IN list cannot contain qualified column references"); } entry.values.emplace_back(colref.GetColumnName()); return true; @@ -46,10 +46,11 @@ PivotColumn Transformer::TransformPivotColumn(duckdb_libpgquery::PGPivot &pivot, TransformExpressionList(*pivot.pivot_columns, col.pivot_expressions); for (auto &expr : col.pivot_expressions) { if (expr->IsScalar()) { - throw ParserException(expr->query_location, "Cannot pivot on constant value \"%s\"", expr->ToString()); + throw ParserException(expr->GetQueryLocation(), "Cannot pivot on constant value \"%s\"", + expr->ToString()); } if (expr->HasSubquery()) { - throw ParserException(expr->query_location, "Cannot pivot on subquery \"%s\"", expr->ToString()); + throw ParserException(expr->GetQueryLocation(), "Cannot pivot on subquery \"%s\"", expr->ToString()); } } } else if (pivot.unpivot_columns) { @@ -62,13 +63,13 @@ PivotColumn Transformer::TransformPivotColumn(duckdb_libpgquery::PGPivot &pivot, auto n = PGPointerCast(node->data.ptr_value); auto expr = TransformExpression(n); PivotColumnEntry entry; - entry.alias = expr->alias; + entry.alias = expr->GetAlias(); auto transformed = TransformPivotInList(expr, entry); if (!transformed) { // could not transform into list of constant values if (is_pivot) { // for pivot - throw an exception - throw ParserException(expr->query_location, + throw ParserException(expr->GetQueryLocation(), "PIVOT IN list must contain columns or lists of columns"); } else { // for unpivot - we can forward the expression immediately diff --git a/src/duckdb/src/parser/transformer.cpp b/src/duckdb/src/parser/transformer.cpp index 123a3b5f..c3b27dbc 100644 --- a/src/duckdb/src/parser/transformer.cpp +++ b/src/duckdb/src/parser/transformer.cpp @@ -259,14 +259,14 @@ void Transformer::SetQueryLocation(ParsedExpression &expr, int query_location) { if (query_location < 0) { return; } - expr.query_location = optional_idx(idx_t(query_location)); + expr.SetQueryLocation(optional_idx(static_cast(query_location))); } void Transformer::SetQueryLocation(TableRef &ref, int query_location) { if (query_location < 0) { return; } - ref.query_location = optional_idx(idx_t(query_location)); + ref.query_location = optional_idx(static_cast(query_location)); } } // namespace duckdb diff --git a/src/duckdb/src/planner/bind_context.cpp b/src/duckdb/src/planner/bind_context.cpp index bb7786f9..58ddbaac 100644 --- a/src/duckdb/src/planner/bind_context.cpp +++ b/src/duckdb/src/planner/bind_context.cpp @@ -187,7 +187,7 @@ vector> BindContext::GetMatchingBindings(const string &column unique_ptr BindContext::ExpandGeneratedColumn(TableBinding &table_binding, const string &column_name) { auto result = table_binding.ExpandGeneratedColumn(column_name); - result->alias = column_name; + result->SetAlias(column_name); return result; } @@ -246,7 +246,7 @@ unique_ptr BindContext::CreateColumnReference(const string &ca } else if (column_index < binding->names.size() && binding->names[column_index] != column_name) { // because of case insensitivity in the binder we rename the column to the original name // as it appears in the binding itself - result->alias = binding->names[column_index]; + result->SetAlias(binding->names[column_index]); } return std::move(result); } @@ -455,7 +455,7 @@ bool CheckExclusionList(StarExpression &expr, const QualifiedColumnName &qualifi auto entry = expr.replace_list.find(qualified_name.column); if (entry != expr.replace_list.end()) { auto new_entry = entry->second->Copy(); - new_entry->alias = entry->first; + new_entry->SetAlias(entry->first); info.excluded_columns.insert(entry->first); info.new_select_list.push_back(std::move(new_entry)); return true; @@ -466,7 +466,7 @@ bool CheckExclusionList(StarExpression &expr, const QualifiedColumnName &qualifi void HandleRename(StarExpression &expr, const QualifiedColumnName &qualified_name, ParsedExpression &new_expr) { auto rename_entry = expr.rename_list.find(qualified_name); if (rename_entry != expr.rename_list.end()) { - new_expr.alias = rename_entry->second; + new_expr.SetAlias(rename_entry->second); } } @@ -504,7 +504,7 @@ void BindContext::GenerateAllColumnExpressions(StarExpression &expr, for (auto &child_binding : using_binding.bindings) { coalesce->children.push_back(make_uniq(column_name, child_binding)); } - coalesce->alias = column_name; + coalesce->SetAlias(column_name); HandleRename(expr, qualified_column, *coalesce); new_select_list.push_back(std::move(coalesce)); } else { diff --git a/src/duckdb/src/planner/binder.cpp b/src/duckdb/src/planner/binder.cpp index d1f24003..7333ac39 100644 --- a/src/duckdb/src/planner/binder.cpp +++ b/src/duckdb/src/planner/binder.cpp @@ -211,7 +211,7 @@ void Binder::AddCTEMap(CommonTableExpressionMap &cte_map) { static void GetTableRefCountsNode(case_insensitive_map_t &cte_ref_counts, QueryNode &node); static void GetTableRefCountsExpr(case_insensitive_map_t &cte_ref_counts, ParsedExpression &expr) { - if (expr.type == ExpressionType::SUBQUERY) { + if (expr.GetExpressionType() == ExpressionType::SUBQUERY) { auto &subquery = expr.Cast(); GetTableRefCountsNode(cte_ref_counts, *subquery.subquery->node); } else { @@ -658,7 +658,7 @@ case_insensitive_map_t> &Binder::GetReplacementScans() { // FIXME: this is extremely naive void VerifyNotExcluded(ParsedExpression &expr) { - if (expr.type == ExpressionType::COLUMN_REF) { + if (expr.GetExpressionType() == ExpressionType::COLUMN_REF) { auto &column_ref = expr.Cast(); if (!column_ref.IsQualified()) { return; diff --git a/src/duckdb/src/planner/binder/expression/bind_aggregate_expression.cpp b/src/duckdb/src/planner/binder/expression/bind_aggregate_expression.cpp index 4ab4d1a7..beba67f8 100644 --- a/src/duckdb/src/planner/binder/expression/bind_aggregate_expression.cpp +++ b/src/duckdb/src/planner/binder/expression/bind_aggregate_expression.cpp @@ -90,7 +90,7 @@ static Value NegatePercentileValue(const Value &v, const bool desc) { static void NegatePercentileFractions(ClientContext &context, unique_ptr &fractions, bool desc) { D_ASSERT(fractions.get()); - D_ASSERT(fractions->expression_class == ExpressionClass::BOUND_EXPRESSION); + D_ASSERT(fractions->GetExpressionClass() == ExpressionClass::BOUND_EXPRESSION); auto &bound = BoundExpression::GetExpression(*fractions); if (!bound->IsFoldable()) { @@ -157,7 +157,7 @@ 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) { + if (order.expression->GetExpressionType() == ExpressionType::VALUE_CONSTANT) { auto &const_expr = order.expression->Cast(); if (!const_expr.value.type().IsIntegral()) { auto &config = ClientConfig::GetConfig(context); @@ -313,7 +313,7 @@ BindResult BaseSelectBinder::BindAggregate(FunctionExpression &aggr, AggregateFu // now create a column reference referring to the aggregate auto colref = make_uniq( - aggr.alias.empty() ? node.aggregates[aggr_index]->ToString() : aggr.alias, + aggr.GetAlias().empty() ? node.aggregates[aggr_index]->ToString() : aggr.GetAlias(), node.aggregates[aggr_index]->return_type, ColumnBinding(node.aggregate_index, aggr_index), depth); // move the aggregate expression into the set of bound aggregates return BindResult(std::move(colref)); diff --git a/src/duckdb/src/planner/binder/expression/bind_between_expression.cpp b/src/duckdb/src/planner/binder/expression/bind_between_expression.cpp index 6a0043fc..09c92dd4 100644 --- a/src/duckdb/src/planner/binder/expression/bind_between_expression.cpp +++ b/src/duckdb/src/planner/binder/expression/bind_between_expression.cpp @@ -30,13 +30,15 @@ BindResult ExpressionBinder::BindExpression(BetweenExpression &expr, idx_t depth // cast the input types to the same type // now obtain the result type of the input types LogicalType input_type; - if (!BoundComparisonExpression::TryBindComparison(context, input_sql_type, lower_sql_type, input_type, expr.type)) { + if (!BoundComparisonExpression::TryBindComparison(context, input_sql_type, lower_sql_type, input_type, + expr.GetExpressionType())) { throw BinderException(expr, "Cannot mix values of type %s and %s in BETWEEN clause - an explicit cast is required", input_sql_type.ToString(), lower_sql_type.ToString()); } - if (!BoundComparisonExpression::TryBindComparison(context, input_type, upper_sql_type, input_type, expr.type)) { + if (!BoundComparisonExpression::TryBindComparison(context, input_type, upper_sql_type, input_type, + expr.GetExpressionType())) { throw BinderException(expr, "Cannot mix values of type %s and %s in BETWEEN clause - an explicit cast is required", input_type.ToString(), upper_sql_type.ToString()); diff --git a/src/duckdb/src/planner/binder/expression/bind_columnref_expression.cpp b/src/duckdb/src/planner/binder/expression/bind_columnref_expression.cpp index 473bd213..1c9bc238 100644 --- a/src/duckdb/src/planner/binder/expression/bind_columnref_expression.cpp +++ b/src/duckdb/src/planner/binder/expression/bind_columnref_expression.cpp @@ -113,7 +113,7 @@ void ExpressionBinder::QualifyColumnNames(unique_ptr &expr, const bool within_function_expression) { bool next_within_function_expression = false; - switch (expr->type) { + switch (expr->GetExpressionType()) { case ExpressionType::COLUMN_REF: { auto &col_ref = expr->Cast(); @@ -126,28 +126,28 @@ void ExpressionBinder::QualifyColumnNames(unique_ptr &expr, auto new_expr = QualifyColumnName(col_ref, error); if (new_expr) { - if (!expr->alias.empty()) { + if (!expr->GetAlias().empty()) { // Pre-existing aliases are added to the qualified column reference - new_expr->alias = expr->alias; + new_expr->SetAlias(expr->GetAlias()); } else if (within_function_expression) { // Qualifying the column reference may add an alias, but this needs to be removed within function // expressions, because the alias here means a named parameter instead of a positional parameter - new_expr->alias = ""; + new_expr->ClearAlias(); } // replace the expression with the qualified column reference - new_expr->query_location = col_ref.query_location; + new_expr->SetQueryLocation(col_ref.GetQueryLocation()); expr = std::move(new_expr); } return; } case ExpressionType::POSITIONAL_REFERENCE: { auto &ref = expr->Cast(); - if (ref.alias.empty()) { + if (ref.GetAlias().empty()) { string table_name, column_name; auto error = binder.bind_context.BindColumn(ref, table_name, column_name); if (error.empty()) { - ref.alias = column_name; + ref.SetAlias(column_name); } } break; @@ -176,7 +176,7 @@ void ExpressionBinder::QualifyColumnNamesInLambda(FunctionExpression &function, vector> &lambda_params) { for (auto &child : function.children) { - if (child->expression_class != ExpressionClass::LAMBDA) { + if (child->GetExpressionClass() != ExpressionClass::LAMBDA) { // not a lambda expression QualifyColumnNames(child, lambda_params, true); continue; @@ -447,16 +447,16 @@ BindResult ExpressionBinder::BindExpression(ColumnRefExpression &col_ref_p, idx_ return BindResult(std::move(error)); } - expr->query_location = col_ref_p.query_location; + expr->SetQueryLocation(col_ref_p.GetQueryLocation()); // the above QualifyColumName returns a generated expression for a generated // column, and struct_extract for a struct, or a lambda reference expression, // all of them are not column reference expressions, so we return here - if (expr->type != ExpressionType::COLUMN_REF) { - auto alias = expr->alias; + if (expr->GetExpressionType() != ExpressionType::COLUMN_REF) { + auto alias = expr->GetAlias(); auto result = BindExpression(expr, depth); if (result.expression) { - result.expression->alias = std::move(alias); + result.expression->SetAlias(std::move(alias)); } return result; } @@ -483,7 +483,7 @@ BindResult ExpressionBinder::BindExpression(ColumnRefExpression &col_ref_p, idx_ // we bound the column reference BoundColumnReferenceInfo ref; ref.name = col_ref.column_names.back(); - ref.query_location = col_ref.query_location; + ref.query_location = col_ref.GetQueryLocation(); bound_columns.push_back(std::move(ref)); return result; } diff --git a/src/duckdb/src/planner/binder/expression/bind_comparison_expression.cpp b/src/duckdb/src/planner/binder/expression/bind_comparison_expression.cpp index d66c76ff..cd490f43 100644 --- a/src/duckdb/src/planner/binder/expression/bind_comparison_expression.cpp +++ b/src/duckdb/src/planner/binder/expression/bind_comparison_expression.cpp @@ -139,7 +139,7 @@ LogicalType BoundComparisonExpression::BindComparison(ClientContext &context, co } LogicalType ExpressionBinder::GetExpressionReturnType(const Expression &expr) { - if (expr.expression_class == ExpressionClass::BOUND_CONSTANT) { + if (expr.GetExpressionClass() == ExpressionClass::BOUND_CONSTANT) { if (expr.return_type == LogicalTypeId::VARCHAR && StringType::GetCollation(expr.return_type).empty()) { return LogicalTypeId::STRING_LITERAL; } @@ -170,7 +170,8 @@ BindResult ExpressionBinder::BindExpression(ComparisonExpression &expr, idx_t de // cast the input types to the same type // now obtain the result type of the input types LogicalType input_type; - if (!BoundComparisonExpression::TryBindComparison(context, left_sql_type, right_sql_type, input_type, expr.type)) { + if (!BoundComparisonExpression::TryBindComparison(context, left_sql_type, right_sql_type, input_type, + expr.GetExpressionType())) { return BindResult(BinderException(expr, "Cannot compare values of type %s and type %s - an explicit cast is required", left_sql_type.ToString(), right_sql_type.ToString())); @@ -185,7 +186,8 @@ BindResult ExpressionBinder::BindExpression(ComparisonExpression &expr, idx_t de PushCollation(context, right, input_type); // now create the bound comparison expression - return BindResult(make_uniq(expr.type, std::move(left), std::move(right))); + return BindResult( + make_uniq(expr.GetExpressionType(), std::move(left), std::move(right))); } } // namespace duckdb diff --git a/src/duckdb/src/planner/binder/expression/bind_conjunction_expression.cpp b/src/duckdb/src/planner/binder/expression/bind_conjunction_expression.cpp index 5125b1db..b93cb5a2 100644 --- a/src/duckdb/src/planner/binder/expression/bind_conjunction_expression.cpp +++ b/src/duckdb/src/planner/binder/expression/bind_conjunction_expression.cpp @@ -17,7 +17,7 @@ BindResult ExpressionBinder::BindExpression(ConjunctionExpression &expr, idx_t d // the children have been successfully resolved // cast the input types to boolean (if necessary) // and construct the bound conjunction expression - auto result = make_uniq(expr.type); + auto result = make_uniq(expr.GetExpressionType()); for (auto &child_expr : expr.children) { auto &child = BoundExpression::GetExpression(*child_expr); result->children.push_back(BoundCastExpression::AddCastToType(context, std::move(child), LogicalType::BOOLEAN)); diff --git a/src/duckdb/src/planner/binder/expression/bind_function_expression.cpp b/src/duckdb/src/planner/binder/expression/bind_function_expression.cpp index 6af70584..b2a44072 100644 --- a/src/duckdb/src/planner/binder/expression/bind_function_expression.cpp +++ b/src/duckdb/src/planner/binder/expression/bind_function_expression.cpp @@ -37,7 +37,7 @@ BindResult ExpressionBinder::TryBindLambdaOrJson(FunctionExpression &function, i BindResult ExpressionBinder::BindExpression(FunctionExpression &function, idx_t depth, unique_ptr &expr_ptr) { // lookup the function in the catalog - QueryErrorContext error_context(function.query_location); + QueryErrorContext error_context(function.GetQueryLocation()); binder.BindSchemaOrCatalog(function.catalog, function.schema); auto func = GetCatalogEntry(CatalogType::SCALAR_FUNCTION_ENTRY, function.catalog, function.schema, function.function_name, OnEntryNotFound::RETURN_NULL, error_context); @@ -131,7 +131,7 @@ BindResult ExpressionBinder::BindFunction(FunctionExpression &function, ScalarFu error.AddQueryLocation(function); error.Throw(); } - if (result->type == ExpressionType::BOUND_FUNCTION) { + if (result->GetExpressionType() == ExpressionType::BOUND_FUNCTION) { auto &bound_function = result->Cast(); if (bound_function.function.stability == FunctionStability::CONSISTENT_WITHIN_QUERY) { binder.SetAlwaysRequireRebind(); @@ -195,10 +195,10 @@ BindResult ExpressionBinder::BindLambdaFunction(FunctionExpression &function, Sc } // successfully bound: replace the node with a BoundExpression - auto alias = function.children[1]->alias; - bind_lambda_result.expression->alias = alias; + auto alias = function.children[1]->GetAlias(); + bind_lambda_result.expression->SetAlias(alias); if (!alias.empty()) { - bind_lambda_result.expression->alias = alias; + bind_lambda_result.expression->SetAlias(alias); } function.children[1] = make_uniq(std::move(bind_lambda_result.expression)); diff --git a/src/duckdb/src/planner/binder/expression/bind_lambda.cpp b/src/duckdb/src/planner/binder/expression/bind_lambda.cpp index 7da2c592..acc68ed0 100644 --- a/src/duckdb/src/planner/binder/expression/bind_lambda.cpp +++ b/src/duckdb/src/planner/binder/expression/bind_lambda.cpp @@ -126,10 +126,10 @@ void ExpressionBinder::TransformCapturedLambdaColumn(unique_ptr &ori const LogicalType &list_child_type) { // check if the original expression is a lambda parameter - if (original->expression_class == ExpressionClass::BOUND_LAMBDA_REF) { + if (original->GetExpressionClass() == ExpressionClass::BOUND_LAMBDA_REF) { auto &bound_lambda_ref = original->Cast(); - auto alias = bound_lambda_ref.alias; + auto alias = bound_lambda_ref.GetAlias(); // refers to a lambda parameter outside the current lambda function // so the lambda parameter will be inside the lambda_bindings @@ -169,7 +169,7 @@ void ExpressionBinder::TransformCapturedLambdaColumn(unique_ptr &ori offset += bound_lambda_expr.parameter_count; offset += bound_lambda_expr.captures.size(); - replacement = make_uniq(original->alias, original->return_type, offset); + replacement = make_uniq(original->GetAlias(), original->return_type, offset); bound_lambda_expr.captures.push_back(std::move(original)); } @@ -177,25 +177,25 @@ void ExpressionBinder::CaptureLambdaColumns(BoundLambdaExpression &bound_lambda_ const optional_ptr bind_lambda_function, const LogicalType &list_child_type) { - if (expr->expression_class == ExpressionClass::BOUND_SUBQUERY) { + if (expr->GetExpressionClass() == ExpressionClass::BOUND_SUBQUERY) { throw BinderException("subqueries in lambda expressions are not supported"); } // these are bound depth-first - D_ASSERT(expr->expression_class != ExpressionClass::BOUND_LAMBDA); + D_ASSERT(expr->GetExpressionClass() != ExpressionClass::BOUND_LAMBDA); // we do not need to replace anything, as these will be constant in the lambda expression // when executed by the expression executor - if (expr->expression_class == ExpressionClass::BOUND_CONSTANT) { + if (expr->GetExpressionClass() == ExpressionClass::BOUND_CONSTANT) { return; } // these expression classes do not have children, transform them - if (expr->expression_class == ExpressionClass::BOUND_COLUMN_REF || - expr->expression_class == ExpressionClass::BOUND_PARAMETER || - expr->expression_class == ExpressionClass::BOUND_LAMBDA_REF) { + if (expr->GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF || + expr->GetExpressionClass() == ExpressionClass::BOUND_PARAMETER || + expr->GetExpressionClass() == ExpressionClass::BOUND_LAMBDA_REF) { - if (expr->expression_class == ExpressionClass::BOUND_COLUMN_REF) { + if (expr->GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF) { // Search for UNNEST. auto &column_binding = expr->Cast().binding; ThrowIfUnnestInLambda(column_binding); diff --git a/src/duckdb/src/planner/binder/expression/bind_macro_expression.cpp b/src/duckdb/src/planner/binder/expression/bind_macro_expression.cpp index 3856ecbf..c6c12a98 100644 --- a/src/duckdb/src/planner/binder/expression/bind_macro_expression.cpp +++ b/src/duckdb/src/planner/binder/expression/bind_macro_expression.cpp @@ -13,7 +13,7 @@ void ExpressionBinder::ReplaceMacroParametersInLambda(FunctionExpression &functi vector> &lambda_params) { for (auto &child : function.children) { - if (child->expression_class != ExpressionClass::LAMBDA) { + if (child->GetExpressionClass() != ExpressionClass::LAMBDA) { ReplaceMacroParameters(child, lambda_params); continue; } diff --git a/src/duckdb/src/planner/binder/expression/bind_operator_expression.cpp b/src/duckdb/src/planner/binder/expression/bind_operator_expression.cpp index 7738d9fb..81addd40 100644 --- a/src/duckdb/src/planner/binder/expression/bind_operator_expression.cpp +++ b/src/duckdb/src/planner/binder/expression/bind_operator_expression.cpp @@ -24,16 +24,18 @@ LogicalType ExpressionBinder::ResolveCoalesceType(OperatorExpression &op, vector } // get the maximum type from the children LogicalType max_type = ExpressionBinder::GetExpressionReturnType(*children[0]); - bool is_in_operator = (op.type == ExpressionType::COMPARE_IN || op.type == ExpressionType::COMPARE_NOT_IN); + bool is_in_operator = (op.GetExpressionType() == ExpressionType::COMPARE_IN || + op.GetExpressionType() == ExpressionType::COMPARE_NOT_IN); for (idx_t i = 1; i < children.size(); i++) { auto child_return = ExpressionBinder::GetExpressionReturnType(*children[i]); if (is_in_operator) { // If it's IN/NOT_IN operator, adjust DECIMAL and VARCHAR returned type. - if (!BoundComparisonExpression::TryBindComparison(context, max_type, child_return, max_type, op.type)) { + if (!BoundComparisonExpression::TryBindComparison(context, max_type, child_return, max_type, + op.GetExpressionType())) { throw BinderException(op, "Cannot mix values of type %s and %s in %s clause - an explicit cast is required", max_type.ToString(), child_return.ToString(), - op.type == ExpressionType::COMPARE_IN ? "IN" : "NOT IN"); + op.GetExpressionType() == ExpressionType::COMPARE_IN ? "IN" : "NOT IN"); } } else { // If it's COALESCE operator, don't do extra adjustment. @@ -57,7 +59,7 @@ LogicalType ExpressionBinder::ResolveCoalesceType(OperatorExpression &op, vector } LogicalType ExpressionBinder::ResolveOperatorType(OperatorExpression &op, vector> &children) { - switch (op.type) { + switch (op.GetExpressionType()) { case ExpressionType::OPERATOR_IS_NULL: case ExpressionType::OPERATOR_IS_NOT_NULL: // IS (NOT) NULL always returns a boolean, and does not cast its children @@ -85,7 +87,7 @@ BindResult ExpressionBinder::BindGroupingFunction(OperatorExpression &op, idx_t } BindResult ExpressionBinder::BindExpression(OperatorExpression &op, idx_t depth) { - if (op.type == ExpressionType::GROUPING_FUNCTION) { + if (op.GetExpressionType() == ExpressionType::GROUPING_FUNCTION) { return BindGroupingFunction(op, depth); } @@ -101,9 +103,9 @@ BindResult ExpressionBinder::BindExpression(OperatorExpression &op, idx_t depth) // all children bound successfully string function_name; - switch (op.type) { + switch (op.GetExpressionType()) { case ExpressionType::ARRAY_EXTRACT: { - D_ASSERT(op.children[0]->expression_class == ExpressionClass::BOUND_EXPRESSION); + D_ASSERT(op.children[0]->GetExpressionClass() == ExpressionClass::BOUND_EXPRESSION); auto &b_exp = BoundExpression::GetExpression(*op.children[0]); const auto &b_exp_type = b_exp->return_type; if (b_exp_type.id() == LogicalTypeId::MAP) { @@ -129,8 +131,8 @@ BindResult ExpressionBinder::BindExpression(OperatorExpression &op, idx_t depth) break; case ExpressionType::STRUCT_EXTRACT: { D_ASSERT(op.children.size() == 2); - D_ASSERT(op.children[0]->expression_class == ExpressionClass::BOUND_EXPRESSION); - D_ASSERT(op.children[1]->expression_class == ExpressionClass::BOUND_EXPRESSION); + D_ASSERT(op.children[0]->GetExpressionClass() == ExpressionClass::BOUND_EXPRESSION); + D_ASSERT(op.children[1]->GetExpressionClass() == ExpressionClass::BOUND_EXPRESSION); auto &extract_exp = BoundExpression::GetExpression(*op.children[0]); auto &name_exp = BoundExpression::GetExpression(*op.children[1]); const auto &extract_expr_type = extract_exp->return_type; @@ -176,12 +178,12 @@ BindResult ExpressionBinder::BindExpression(OperatorExpression &op, idx_t depth) vector> children; for (idx_t i = 0; i < op.children.size(); i++) { - D_ASSERT(op.children[i]->expression_class == ExpressionClass::BOUND_EXPRESSION); + D_ASSERT(op.children[i]->GetExpressionClass() == ExpressionClass::BOUND_EXPRESSION); children.push_back(std::move(BoundExpression::GetExpression(*op.children[i]))); } // now resolve the types LogicalType result_type = ResolveOperatorType(op, children); - if (op.type == ExpressionType::OPERATOR_COALESCE) { + if (op.GetExpressionType() == ExpressionType::OPERATOR_COALESCE) { if (children.empty()) { throw BinderException("COALESCE needs at least one child"); } @@ -190,7 +192,7 @@ BindResult ExpressionBinder::BindExpression(OperatorExpression &op, idx_t depth) } } - auto result = make_uniq(op.type, result_type); + auto result = make_uniq(op.GetExpressionType(), result_type); for (auto &child : children) { result->children.push_back(std::move(child)); } diff --git a/src/duckdb/src/planner/binder/expression/bind_parameter_expression.cpp b/src/duckdb/src/planner/binder/expression/bind_parameter_expression.cpp index 678faf26..109c0ecb 100644 --- a/src/duckdb/src/planner/binder/expression/bind_parameter_expression.cpp +++ b/src/duckdb/src/planner/binder/expression/bind_parameter_expression.cpp @@ -24,7 +24,7 @@ BindResult ExpressionBinder::BindExpression(ParameterExpression &expr, idx_t dep bool is_literal = return_type.id() == LogicalTypeId::INTEGER_LITERAL || return_type.id() == LogicalTypeId::STRING_LITERAL; auto constant = make_uniq(data.GetValue()); - constant->alias = expr.alias; + constant->SetAlias(expr.GetAlias()); if (is_literal) { return BindResult(std::move(constant)); } diff --git a/src/duckdb/src/planner/binder/expression/bind_star_expression.cpp b/src/duckdb/src/planner/binder/expression/bind_star_expression.cpp index 40704836..179fad7d 100644 --- a/src/duckdb/src/planner/binder/expression/bind_star_expression.cpp +++ b/src/duckdb/src/planner/binder/expression/bind_star_expression.cpp @@ -12,7 +12,7 @@ namespace duckdb { string GetColumnsStringValue(ParsedExpression &expr) { - if (expr.type == ExpressionType::COLUMN_REF) { + if (expr.GetExpressionType() == ExpressionType::COLUMN_REF) { auto &colref = expr.Cast(); return colref.GetColumnName(); } else { @@ -91,10 +91,10 @@ void Binder::ReplaceStarExpression(unique_ptr &expr, unique_pt D_ASSERT(expr); if (StarExpression::IsColumns(*expr) || StarExpression::IsStar(*expr)) { D_ASSERT(replacement); - auto alias = expr->alias; + auto alias = expr->GetAlias(); expr = replacement->Copy(); if (!alias.empty()) { - expr->alias = std::move(alias); + expr->SetAlias(std::move(alias)); } return; } @@ -141,7 +141,7 @@ static string ReplaceColumnsAlias(const string &alias, const string &column_name void TryTransformStarLike(unique_ptr &root) { // detect "* LIKE [literal]" and similar expressions - if (root->expression_class != ExpressionClass::FUNCTION) { + if (root->GetExpressionClass() != ExpressionClass::FUNCTION) { return; } auto &function = root->Cast(); @@ -150,7 +150,7 @@ void TryTransformStarLike(unique_ptr &root) { } auto &left = function.children[0]; // expression must have a star on the LHS, and a literal on the RHS - if (left->expression_class != ExpressionClass::STAR) { + if (left->GetExpressionClass() != ExpressionClass::STAR) { return; } auto &star = left->Cast(); @@ -164,7 +164,7 @@ void TryTransformStarLike(unique_ptr &root) { throw BinderException(*root, "Function \"%s\" cannot be applied to a star expression", function.function_name); } auto &right = function.children[1]; - if (right->expression_class != ExpressionClass::CONSTANT) { + if (right->GetExpressionClass() != ExpressionClass::CONSTANT) { throw BinderException(*root, "Pattern applied to a star expression must be a constant"); } if (!star.rename_list.empty()) { @@ -173,7 +173,7 @@ void TryTransformStarLike(unique_ptr &root) { if (!star.replace_list.empty()) { throw BinderException(*root, "Replace list cannot be combined with a filtering operation"); } - auto original_alias = root->alias; + auto original_alias = root->GetAlias(); auto star_expr = std::move(left); unique_ptr child_expr; if (function.function_name == "regexp_full_match" && star.exclude_list.empty()) { @@ -197,17 +197,17 @@ void TryTransformStarLike(unique_ptr &root) { auto columns_expr = make_uniq(); columns_expr->columns = true; columns_expr->expr = std::move(child_expr); - columns_expr->alias = std::move(original_alias); + columns_expr->SetAlias(std::move(original_alias)); root = std::move(columns_expr); } optional_ptr Binder::GetResolvedColumnExpression(ParsedExpression &root_expr) { optional_ptr expr = &root_expr; while (expr) { - if (expr->type == ExpressionType::COLUMN_REF) { + if (expr->GetExpressionType() == ExpressionType::COLUMN_REF) { break; } - if (expr->type == ExpressionType::OPERATOR_COALESCE) { + if (expr->GetExpressionType() == ExpressionType::OPERATOR_COALESCE) { expr = expr->Cast().children[0].get(); } else { // unknown expression @@ -336,10 +336,10 @@ void Binder::ExpandStarExpression(unique_ptr expr, auto expr = GetResolvedColumnExpression(*star_list[i]); if (expr) { auto &colref = expr->Cast(); - if (new_expr->alias.empty()) { - new_expr->alias = colref.GetColumnName(); + if (new_expr->GetAlias().empty()) { + new_expr->SetAlias(colref.GetColumnName()); } else { - new_expr->alias = ReplaceColumnsAlias(new_expr->alias, colref.GetColumnName(), regex.get()); + new_expr->SetAlias(ReplaceColumnsAlias(new_expr->GetAlias(), colref.GetColumnName(), regex.get())); } } } diff --git a/src/duckdb/src/planner/binder/expression/bind_subquery_expression.cpp b/src/duckdb/src/planner/binder/expression/bind_subquery_expression.cpp index 0bf4dd5a..45dc31a3 100644 --- a/src/duckdb/src/planner/binder/expression/bind_subquery_expression.cpp +++ b/src/duckdb/src/planner/binder/expression/bind_subquery_expression.cpp @@ -59,7 +59,7 @@ void ExtractSubqueryChildren(unique_ptr &child, vectorexpression_class != ExpressionClass::BOUND_FUNCTION) { + if (child->GetExpressionClass() != ExpressionClass::BOUND_FUNCTION) { // not a function return; } diff --git a/src/duckdb/src/planner/binder/expression/bind_unnest_expression.cpp b/src/duckdb/src/planner/binder/expression/bind_unnest_expression.cpp index 0f9ecc8b..ba9c0715 100644 --- a/src/duckdb/src/planner/binder/expression/bind_unnest_expression.cpp +++ b/src/duckdb/src/planner/binder/expression/bind_unnest_expression.cpp @@ -26,7 +26,7 @@ unique_ptr CreateBoundStructExtract(ClientContext &context, unique_p auto return_type = extract_function.return_type; auto result = make_uniq(return_type, std::move(extract_function), std::move(arguments), std::move(bind_info)); - result->alias = std::move(key); + result->SetAlias(std::move(key)); return std::move(result); } @@ -39,7 +39,7 @@ unique_ptr CreateBoundStructExtractIndex(ClientContext &context, uni auto return_type = extract_function.return_type; auto result = make_uniq(return_type, std::move(extract_function), std::move(arguments), std::move(bind_info)); - result->alias = "element" + to_string(key); + result->SetAlias("element" + to_string(key)); return std::move(result); } @@ -89,7 +89,7 @@ BindResult SelectBinder::BindUnnest(FunctionExpression &function, idx_t depth, b if (!function.children[i]->IsScalar()) { break; } - auto alias = StringUtil::Lower(function.children[i]->alias); + auto alias = StringUtil::Lower(function.children[i]->GetAlias()); BindChild(function.children[i], depth, error); if (error.HasError()) { return BindResult(std::move(error)); @@ -187,7 +187,7 @@ BindResult SelectBinder::BindUnnest(FunctionExpression &function, idx_t depth, b } auto result = make_uniq(return_type); result->child = std::move(unnest_expr); - auto alias = function.alias.empty() ? result->ToString() : function.alias; + auto alias = function.GetAlias().empty() ? result->ToString() : function.GetAlias(); auto current_level = unnest_level + list_unnests - current_depth - 1; auto entry = node.unnests.find(current_level); diff --git a/src/duckdb/src/planner/binder/expression/bind_window_expression.cpp b/src/duckdb/src/planner/binder/expression/bind_window_expression.cpp index 73231402..7fcf96e6 100644 --- a/src/duckdb/src/planner/binder/expression/bind_window_expression.cpp +++ b/src/duckdb/src/planner/binder/expression/bind_window_expression.cpp @@ -69,7 +69,7 @@ static unique_ptr GetExpression(unique_ptr &expr) return nullptr; } D_ASSERT(expr.get()); - D_ASSERT(expr->expression_class == ExpressionClass::BOUND_EXPRESSION); + D_ASSERT(expr->GetExpressionClass() == ExpressionClass::BOUND_EXPRESSION); return std::move(BoundExpression::GetExpression(*expr)); } @@ -78,7 +78,7 @@ static unique_ptr CastWindowExpression(unique_ptr return nullptr; } D_ASSERT(expr.get()); - D_ASSERT(expr->expression_class == ExpressionClass::BOUND_EXPRESSION); + D_ASSERT(expr->GetExpressionClass() == ExpressionClass::BOUND_EXPRESSION); auto &bound = BoundExpression::GetExpression(*expr); bound = BoundCastExpression::AddDefaultCastToType(std::move(bound), type); @@ -113,14 +113,14 @@ static LogicalType BindRangeExpression(ClientContext &context, const string &nam vector> children; D_ASSERT(order_expr.get()); - D_ASSERT(order_expr->expression_class == ExpressionClass::BOUND_EXPRESSION); + D_ASSERT(order_expr->GetExpressionClass() == ExpressionClass::BOUND_EXPRESSION); auto &bound_order = BoundExpression::GetExpression(*order_expr); children.emplace_back(bound_order->Copy()); D_ASSERT(expr.get()); - D_ASSERT(expr->expression_class == ExpressionClass::BOUND_EXPRESSION); + D_ASSERT(expr->GetExpressionClass() == ExpressionClass::BOUND_EXPRESSION); auto &bound = BoundExpression::GetExpression(*expr); - QueryErrorContext error_context(bound->query_location); + QueryErrorContext error_context(bound->GetQueryLocation()); if (bound->return_type == LogicalType::SQLNULL) { throw BinderException(error_context, "Window RANGE expressions cannot be NULL"); } @@ -142,11 +142,12 @@ static LogicalType BindRangeExpression(ClientContext &context, const string &nam } BindResult BaseSelectBinder::BindWindow(WindowExpression &window, idx_t depth) { - QueryErrorContext error_context(window.query_location); + QueryErrorContext error_context(window.GetQueryLocation()); // Check for macros pretending to be aggregates auto entry = GetCatalogEntry(CatalogType::SCALAR_FUNCTION_ENTRY, window.catalog, window.schema, window.function_name, OnEntryNotFound::RETURN_NULL, error_context); - if (window.type == ExpressionType::WINDOW_AGGREGATE && entry && entry->type == CatalogType::MACRO_ENTRY) { + if (window.GetExpressionType() == ExpressionType::WINDOW_AGGREGATE && entry && + entry->type == CatalogType::MACRO_ENTRY) { auto macro = make_uniq(window.catalog, window.schema, window.function_name, std::move(window.children), std::move(window.filter_expr), nullptr, window.distinct); @@ -234,11 +235,11 @@ BindResult BaseSelectBinder::BindWindow(WindowExpression &window, idx_t depth) { vector> children; for (auto &child : window.children) { D_ASSERT(child.get()); - D_ASSERT(child->expression_class == ExpressionClass::BOUND_EXPRESSION); + D_ASSERT(child->GetExpressionClass() == ExpressionClass::BOUND_EXPRESSION); auto &bound = BoundExpression::GetExpression(*child); // Add casts for positional arguments const auto argno = children.size(); - switch (window.type) { + switch (window.GetExpressionType()) { case ExpressionType::WINDOW_NTILE: // ntile(bigint) if (argno == 0) { @@ -261,7 +262,7 @@ BindResult BaseSelectBinder::BindWindow(WindowExpression &window, idx_t depth) { LogicalType sql_type; unique_ptr aggregate; unique_ptr bind_info; - if (window.type == ExpressionType::WINDOW_AGGREGATE) { + if (window.GetExpressionType() == ExpressionType::WINDOW_AGGREGATE) { // Look up the aggregate function in the catalog if (!entry || entry->type != CatalogType::AGGREGATE_FUNCTION_ENTRY) { // Not an aggregate: Look it up to generate error @@ -291,9 +292,10 @@ BindResult BaseSelectBinder::BindWindow(WindowExpression &window, idx_t depth) { } else { // fetch the child of the non-aggregate window function (if any) - sql_type = ResolveWindowExpressionType(window.type, types); + sql_type = ResolveWindowExpressionType(window.GetExpressionType(), types); } - auto result = make_uniq(window.type, sql_type, std::move(aggregate), std::move(bind_info)); + auto result = make_uniq(window.GetExpressionType(), sql_type, std::move(aggregate), + std::move(bind_info)); result->children = std::move(children); for (auto &child : window.partitions) { result->partitions.push_back(GetExpression(child)); @@ -341,7 +343,7 @@ BindResult BaseSelectBinder::BindWindow(WindowExpression &window, idx_t depth) { auto &order_expr = window.orders[0].expression; D_ASSERT(order_expr.get()); - D_ASSERT(order_expr->expression_class == ExpressionClass::BOUND_EXPRESSION); + D_ASSERT(order_expr->GetExpressionClass() == ExpressionClass::BOUND_EXPRESSION); auto &bound_order = BoundExpression::GetExpression(*order_expr); auto order_type = bound_order->return_type; if (window.start_expr) { diff --git a/src/duckdb/src/planner/binder/query_node/bind_select_node.cpp b/src/duckdb/src/planner/binder/query_node/bind_select_node.cpp index 590da7ae..126ae001 100644 --- a/src/duckdb/src/planner/binder/query_node/bind_select_node.cpp +++ b/src/duckdb/src/planner/binder/query_node/bind_select_node.cpp @@ -40,7 +40,7 @@ unique_ptr Binder::BindOrderExpression(OrderBinder &order_binder, un // remove the expression from the DISTINCT ON list return nullptr; } - D_ASSERT(bound_expr->type == ExpressionType::VALUE_CONSTANT); + D_ASSERT(bound_expr->GetExpressionType() == ExpressionType::VALUE_CONSTANT); return bound_expr; } @@ -86,7 +86,7 @@ BoundLimitNode Binder::BindLimitValue(OrderBinder &order_binder, unique_ptr(); } if (constant_val < 0) { - throw BinderException(expr->query_location, "LIMIT/OFFSET cannot be negative"); + throw BinderException(expr->GetQueryLocation(), "LIMIT/OFFSET cannot be negative"); } return BoundLimitNode::ConstantValue(constant_val); } @@ -160,7 +160,7 @@ void Binder::PrepareModifiers(OrderBinder &order_binder, QueryNode &statement, B auto &config = DBConfig::GetConfig(context); D_ASSERT(!order.orders.empty()); auto &order_binders = order_binder.GetBinders(); - if (order.orders.size() == 1 && order.orders[0].expression->type == ExpressionType::STAR) { + if (order.orders.size() == 1 && order.orders[0].expression->GetExpressionType() == ExpressionType::STAR) { auto &star = order.orders[0].expression->Cast(); if (star.exclude_list.empty() && star.replace_list.empty() && !star.expr) { // ORDER BY ALL @@ -179,7 +179,7 @@ void Binder::PrepareModifiers(OrderBinder &order_binder, QueryNode &statement, B // e.g. it breaks EXPLAIN output on queries bool can_replace = true; for (auto &order_node : order.orders) { - if (order_node.expression->type == ExpressionType::VALUE_CONSTANT) { + if (order_node.expression->GetExpressionType() == ExpressionType::VALUE_CONSTANT) { // we cannot replace the sort key when we order by literals (e.g. ORDER BY 1, 2` can_replace = false; break; @@ -242,10 +242,10 @@ unique_ptr CreateOrderExpression(unique_ptr expr, const if (index >= sql_types.size()) { throw BinderException(*expr, "ORDER term out of range - should be between 1 and %lld", sql_types.size()); } - auto result = make_uniq(std::move(expr->alias), sql_types[index], - ColumnBinding(table_index, index)); - if (result->alias.empty() && index < names.size()) { - result->alias = names[index]; + auto result = + make_uniq(expr->GetAlias(), sql_types[index], ColumnBinding(table_index, index)); + if (result->GetAlias().empty() && index < names.size()) { + result->SetAlias(names[index]); } return std::move(result); } @@ -294,10 +294,10 @@ static void AssignReturnType(unique_ptr &expr, idx_t table_index, co if (!expr) { return; } - if (expr->type == ExpressionType::VALUE_CONSTANT) { + if (expr->GetExpressionType() == ExpressionType::VALUE_CONSTANT) { expr = FinalizeBindOrderExpression(std::move(expr), table_index, names, sql_types, bind_state); } - if (expr->type != ExpressionType::BOUND_COLUMN_REF) { + if (expr->GetExpressionType() != ExpressionType::BOUND_COLUMN_REF) { return; } auto &bound_colref = expr->Cast(); @@ -346,7 +346,7 @@ void Binder::BindModifiers(BoundQueryNode &result, idx_t table_index, const vect for (idx_t i = 0; i < sql_types.size(); i++) { auto expr = make_uniq(sql_types[i], ColumnBinding(table_index, i)); if (i < names.size()) { - expr->alias = names[i]; + expr->SetAlias(names[i]); } order.orders.emplace_back(order_type, null_order, std::move(expr)); } @@ -374,14 +374,14 @@ unique_ptr Binder::BindNode(SelectNode &statement) { void Binder::BindWhereStarExpression(unique_ptr &expr) { // expand any expressions in the upper AND recursively - if (expr->type == ExpressionType::CONJUNCTION_AND) { + if (expr->GetExpressionType() == ExpressionType::CONJUNCTION_AND) { auto &conj = expr->Cast(); for (auto &child : conj.children) { BindWhereStarExpression(child); } return; } - if (expr->type == ExpressionType::STAR) { + if (expr->GetExpressionType() == ExpressionType::STAR) { auto &star = expr->Cast(); if (!star.columns) { throw ParserException("STAR expression is not allowed in the WHERE clause. Use COLUMNS(*) instead."); @@ -434,9 +434,9 @@ unique_ptr Binder::BindSelectNode(SelectNode &statement, unique_ auto &expr = statement.select_list[i]; result->names.push_back(expr->GetName()); ExpressionBinder::QualifyColumnNames(*this, expr); - if (!expr->alias.empty()) { - bind_state.alias_map[expr->alias] = i; - result->names[i] = expr->alias; + if (!expr->GetAlias().empty()) { + bind_state.alias_map[expr->GetAlias()] = i; + result->names[i] = expr->GetAlias(); } bind_state.projection_map[*expr] = i; bind_state.original_expressions.push_back(expr->Copy()); @@ -498,7 +498,7 @@ unique_ptr Binder::BindSelectNode(SelectNode &statement, unique_ FunctionBinder function_binder(*this); auto function = function_binder.BindAggregateFunction(first_fun, std::move(first_children)); - function->alias = "__collated_group"; + function->SetAlias("__collated_group"); result->aggregates.push_back(std::move(function)); } result->groups.group_expressions.push_back(std::move(bound_expr)); @@ -557,7 +557,7 @@ unique_ptr Binder::BindSelectNode(SelectNode &statement, unique_ statement.aggregate_handling == AggregateHandling::FORCE_AGGREGATES && is_original_column; result->bound_column_count++; - if (expr->type == ExpressionType::BOUND_EXPANDED) { + if (expr->GetExpressionType() == ExpressionType::BOUND_EXPANDED) { if (!is_original_column) { throw BinderException("UNNEST of struct cannot be used in ORDER BY/DISTINCT ON clause"); } diff --git a/src/duckdb/src/planner/binder/query_node/plan_setop.cpp b/src/duckdb/src/planner/binder/query_node/plan_setop.cpp index 41988bbe..ba929bcd 100644 --- a/src/duckdb/src/planner/binder/query_node/plan_setop.cpp +++ b/src/duckdb/src/planner/binder/query_node/plan_setop.cpp @@ -33,7 +33,7 @@ unique_ptr Binder::CastLogicalOperatorToTypes(vector new_column_types; bool do_pushdown = true; for (idx_t i = 0; i < op->expressions.size(); i++) { - if (op->expressions[i]->type == ExpressionType::BOUND_COLUMN_REF) { + if (op->expressions[i]->GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { auto &col_ref = op->expressions[i]->Cast(); auto column_id = column_ids[col_ref.binding.column_index].GetPrimaryIndex(); if (new_column_types.find(column_id) != new_column_types.end()) { @@ -61,10 +61,10 @@ unique_ptr Binder::CastLogicalOperatorToTypes(vectorexpressions[i]->alias; + string cur_alias = node->expressions[i]->GetAlias(); node->expressions[i] = BoundCastExpression::AddCastToType(context, std::move(node->expressions[i]), target_types[i]); - node->expressions[i]->alias = cur_alias; + node->expressions[i]->SetAlias(cur_alias); } } return op; diff --git a/src/duckdb/src/planner/binder/query_node/plan_subquery.cpp b/src/duckdb/src/planner/binder/query_node/plan_subquery.cpp index 647939c2..1e1c06c1 100644 --- a/src/duckdb/src/planner/binder/query_node/plan_subquery.cpp +++ b/src/duckdb/src/planner/binder/query_node/plan_subquery.cpp @@ -193,7 +193,7 @@ CreateDuplicateEliminatedJoin(const vector &correlated_col make_uniq(ExpressionType::WINDOW_ROW_NUMBER, LogicalType::BIGINT, nullptr, nullptr); row_number->start = WindowBoundary::UNBOUNDED_PRECEDING; row_number->end = WindowBoundary::CURRENT_ROW_ROWS; - row_number->alias = "delim_index"; + row_number->SetAlias("delim_index"); window->expressions.push_back(std::move(row_number)); window->AddChild(std::move(original_plan)); original_plan = std::move(window); @@ -449,7 +449,7 @@ void Binder::PlanSubqueries(unique_ptr &expr_ptr, unique_ptr &expr) { PlanSubqueries(expr, root); }); // check if this is a subquery node - if (expr.expression_class == ExpressionClass::BOUND_SUBQUERY) { + if (expr.GetExpressionClass() == ExpressionClass::BOUND_SUBQUERY) { auto &subquery = expr.Cast(); // subquery node! plan it if (!is_outside_flattened) { diff --git a/src/duckdb/src/planner/binder/statement/bind_create.cpp b/src/duckdb/src/planner/binder/statement/bind_create.cpp index 9c494787..5ebd5681 100644 --- a/src/duckdb/src/planner/binder/statement/bind_create.cpp +++ b/src/duckdb/src/planner/binder/statement/bind_create.cpp @@ -497,7 +497,7 @@ void ExpressionContainsGeneratedColumn(const ParsedExpression &expr, const unord if (contains_gcol) { return; } - if (expr.type == ExpressionType::COLUMN_REF) { + if (expr.GetExpressionType() == ExpressionType::COLUMN_REF) { auto &column_ref = expr.Cast(); auto &name = column_ref.GetColumnName(); if (gcols.count(name)) { diff --git a/src/duckdb/src/planner/binder/statement/bind_execute.cpp b/src/duckdb/src/planner/binder/statement/bind_execute.cpp index 31255101..3e3af4d6 100644 --- a/src/duckdb/src/planner/binder/statement/bind_execute.cpp +++ b/src/duckdb/src/planner/binder/statement/bind_execute.cpp @@ -35,7 +35,7 @@ BoundStatement Binder::Bind(ExecuteStatement &stmt) { auto constant_binder = Binder::CreateBinder(context); constant_binder->SetCanContainNulls(true); for (auto &pair : mapped_named_values) { - bool is_literal = pair.second->type == ExpressionType::VALUE_CONSTANT; + bool is_literal = pair.second->GetExpressionType() == ExpressionType::VALUE_CONSTANT; ConstantBinder cbinder(*constant_binder, context, "EXECUTE statement"); auto bound_expr = cbinder.Bind(pair.second); diff --git a/src/duckdb/src/planner/binder/statement/bind_insert.cpp b/src/duckdb/src/planner/binder/statement/bind_insert.cpp index 3b0d38a4..d4af5ab4 100644 --- a/src/duckdb/src/planner/binder/statement/bind_insert.cpp +++ b/src/duckdb/src/planner/binder/statement/bind_insert.cpp @@ -48,7 +48,7 @@ unique_ptr ExpandDefaultExpression(const ColumnDefinition &col } void ReplaceDefaultExpression(unique_ptr &expr, const ColumnDefinition &column) { - D_ASSERT(expr->type == ExpressionType::VALUE_DEFAULT); + D_ASSERT(expr->GetExpressionType() == ExpressionType::VALUE_DEFAULT); expr = ExpandDefaultExpression(column); } @@ -56,7 +56,7 @@ void ExpressionBinder::DoUpdateSetQualifyInLambda(FunctionExpression &function, vector> &lambda_params) { for (auto &child : function.children) { - if (child->expression_class != ExpressionClass::LAMBDA) { + if (child->GetExpressionClass() != ExpressionClass::LAMBDA) { DoUpdateSetQualify(child, table_name, lambda_params); continue; } @@ -135,7 +135,7 @@ void ExpressionBinder::DoUpdateSetQualify(unique_ptr &expr, co // Replace binding.table_index with 'dest' if it's 'source' void ReplaceColumnBindings(Expression &expr, idx_t source, idx_t dest) { - if (expr.type == ExpressionType::BOUND_COLUMN_REF) { + if (expr.GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { auto &bound_columnref = expr.Cast(); if (bound_columnref.binding.table_index == source) { bound_columnref.binding.table_index = dest; @@ -176,7 +176,7 @@ void Binder::BindDoUpdateSetExpressions(const string &table_alias, LogicalInsert logical_column_ids.push_back(column.Oid()); insert.set_types.push_back(column.Type()); column_names.push_back(colname); - if (expr->type == ExpressionType::VALUE_DEFAULT) { + if (expr->GetExpressionType() == ExpressionType::VALUE_DEFAULT) { expr = ExpandDefaultExpression(column); } @@ -589,7 +589,7 @@ BoundStatement Binder::Bind(InsertStatement &stmt) { // now replace any DEFAULT values with the corresponding default expression for (idx_t list_idx = 0; list_idx < expr_list.values.size(); list_idx++) { - if (expr_list.values[list_idx][col_idx]->type == ExpressionType::VALUE_DEFAULT) { + if (expr_list.values[list_idx][col_idx]->GetExpressionType() == ExpressionType::VALUE_DEFAULT) { // DEFAULT value! replace the entry ReplaceDefaultExpression(expr_list.values[list_idx][col_idx], column); } diff --git a/src/duckdb/src/planner/binder/statement/bind_summarize.cpp b/src/duckdb/src/planner/binder/statement/bind_summarize.cpp index dac43d8f..b5c87e1a 100644 --- a/src/duckdb/src/planner/binder/statement/bind_summarize.cpp +++ b/src/duckdb/src/planner/binder/statement/bind_summarize.cpp @@ -19,7 +19,7 @@ static unique_ptr SummarizeWrapUnnest(vector> unnest_children; unnest_children.push_back(std::move(list_function)); auto unnest_function = make_uniq("unnest", std::move(unnest_children)); - unnest_function->alias = alias; + unnest_function->SetAlias(alias); return std::move(unnest_function); } diff --git a/src/duckdb/src/planner/binder/statement/bind_update.cpp b/src/duckdb/src/planner/binder/statement/bind_update.cpp index 83afa5a8..ba25497e 100644 --- a/src/duckdb/src/planner/binder/statement/bind_update.cpp +++ b/src/duckdb/src/planner/binder/statement/bind_update.cpp @@ -43,7 +43,7 @@ unique_ptr Binder::BindUpdateSet(LogicalOperator &op, unique_pt throw BinderException("Multiple assignments to same column \"%s\"", colname); } columns.push_back(column.Physical()); - if (expr->type == ExpressionType::VALUE_DEFAULT) { + if (expr->GetExpressionType() == ExpressionType::VALUE_DEFAULT) { op.expressions.push_back(make_uniq(column.Type())); } else { UpdateBinder binder(*this, context); diff --git a/src/duckdb/src/planner/binder/tableref/bind_pivot.cpp b/src/duckdb/src/planner/binder/tableref/bind_pivot.cpp index f81c09d3..3899ecdd 100644 --- a/src/duckdb/src/planner/binder/tableref/bind_pivot.cpp +++ b/src/duckdb/src/planner/binder/tableref/bind_pivot.cpp @@ -58,7 +58,7 @@ static void ConstructPivots(PivotRef &ref, vector &pivot_valu } static void ExtractPivotExpressions(ParsedExpression &expr, case_insensitive_set_t &handled_columns) { - if (expr.type == ExpressionType::COLUMN_REF) { + if (expr.GetExpressionType() == ExpressionType::COLUMN_REF) { auto &child_colref = expr.Cast(); if (child_colref.IsQualified()) { throw BinderException("PIVOT expression cannot contain qualified columns"); @@ -71,7 +71,7 @@ static void ExtractPivotExpressions(ParsedExpression &expr, case_insensitive_set void ExtractPivotAggregateExpression(ClientContext &context, ParsedExpression &expr, vector> &aggregates) { - if (expr.type == ExpressionType::FUNCTION) { + if (expr.GetExpressionType() == ExpressionType::FUNCTION) { auto &aggr_function = expr.Cast(); // check if this is an aggregate to ensure it is an aggregate and not a scalar function @@ -83,7 +83,7 @@ void ExtractPivotAggregateExpression(ClientContext &context, ParsedExpression &e return; } } - if (expr.type == ExpressionType::COLUMN_REF) { + if (expr.GetExpressionType() == ExpressionType::COLUMN_REF) { throw BinderException(expr, "Columns can only be referenced within the aggregate of a PIVOT expression"); } ParsedExpressionIterator::EnumerateChildren( @@ -154,13 +154,13 @@ static unique_ptr PivotFilteredAggregate(ClientContext &context, Piv auto &aggr = aggregates[0].get().Cast(); aggr.filter = filter->Copy(); - auto &aggr_name = aggregate->alias; + auto &aggr_name = aggregate->GetAlias(); auto name = pivot_value.name; if (ref.aggregates.size() > 1 || !aggr_name.empty()) { // if there are multiple aggregates specified we add the name of the aggregate as well name += "_" + (aggr_name.empty() ? aggregate->GetName() : aggr_name); } - copied_aggr->alias = name; + copied_aggr->SetAlias(name); subquery->select_list.push_back(std::move(copied_aggr)); } } @@ -182,19 +182,19 @@ static unique_ptr PivotInitialAggregate(PivotBindState &bind_state, idx_t group_count = 0; for (auto &expr : subquery_stage1->select_list) { bind_state.group_names.push_back(expr->GetName()); - if (expr->alias.empty()) { - expr->alias = "__internal_pivot_group" + std::to_string(++group_count); + if (expr->GetAlias().empty()) { + expr->SetAlias("__internal_pivot_group" + std::to_string(++group_count)); } - bind_state.internal_group_names.push_back(expr->alias); + bind_state.internal_group_names.push_back(expr->GetAlias()); } // group by all of the pivot values idx_t pivot_count = 0; for (auto &pivot_column : ref.pivots) { for (auto &pivot_expr : pivot_column.pivot_expressions) { - if (pivot_expr->alias.empty()) { - pivot_expr->alias = "__internal_pivot_ref" + std::to_string(++pivot_count); + if (pivot_expr->GetAlias().empty()) { + pivot_expr->SetAlias("__internal_pivot_ref" + std::to_string(++pivot_count)); } - auto pivot_alias = pivot_expr->alias; + auto pivot_alias = pivot_expr->GetAlias(); subquery_stage1->groups.group_expressions.push_back(make_uniq( Value::INTEGER(UnsafeNumericCast(subquery_stage1->select_list.size() + 1)))); subquery_stage1->select_list.push_back(std::move(pivot_expr)); @@ -205,9 +205,9 @@ static unique_ptr PivotInitialAggregate(PivotBindState &bind_state, // finally add the aggregates for (auto &aggregate : ref.aggregates) { auto aggregate_alias = "__internal_pivot_aggregate" + std::to_string(++aggregate_count); - bind_state.aggregate_names.push_back(aggregate->alias); + bind_state.aggregate_names.push_back(aggregate->GetAlias()); bind_state.internal_aggregate_names.push_back(aggregate_alias); - aggregate->alias = std::move(aggregate_alias); + aggregate->SetAlias(std::move(aggregate_alias)); subquery_stage1->select_list.push_back(std::move(aggregate)); } return subquery_stage1; @@ -235,7 +235,7 @@ static unique_ptr PivotListAggregate(PivotBindState &bind_state, Piv subquery_stage2->groups.group_expressions.push_back(make_uniq( Value::INTEGER(UnsafeNumericCast(subquery_stage2->select_list.size() + 1)))); auto group_reference = make_uniq(bind_state.internal_group_names[gr]); - group_reference->alias = bind_state.internal_group_names[gr]; + group_reference->SetAlias(bind_state.internal_group_names[gr]); subquery_stage2->select_list.push_back(std::move(group_reference)); } @@ -245,7 +245,7 @@ static unique_ptr PivotListAggregate(PivotBindState &bind_state, Piv vector> list_children; list_children.push_back(std::move(colref)); auto aggregate = make_uniq("list", std::move(list_children)); - aggregate->alias = bind_state.internal_aggregate_names[aggr]; + aggregate->SetAlias(bind_state.internal_aggregate_names[aggr]); subquery_stage2->select_list.push_back(std::move(aggregate)); } // construct the pivot list @@ -273,7 +273,7 @@ static unique_ptr PivotListAggregate(PivotBindState &bind_state, Piv list_children.push_back(std::move(expr)); auto aggregate = make_uniq("list", std::move(list_children)); - aggregate->alias = pivot_name; + aggregate->SetAlias(pivot_name); subquery_stage2->select_list.push_back(std::move(aggregate)); subquery_stage2->from_table = std::move(subquery_ref); @@ -318,7 +318,7 @@ void ExtractPivotAggregates(BoundTableRef &node, vector> } auto &select2 = subq2.subquery->Cast(); for (auto &aggr : select2.aggregates) { - if (aggr->alias == "__collated_group") { + if (aggr->GetAlias() == "__collated_group") { continue; } aggregates.push_back(aggr->Copy()); @@ -540,8 +540,8 @@ void Binder::ExtractUnpivotEntries(Binder &child_binder, PivotColumnEntry &entry for (auto &expr : star_columns) { // create one pivot entry per result column UnpivotEntry unpivot_entry; - if (!expr->alias.empty()) { - unpivot_entry.alias = std::move(expr->alias); + if (!expr->GetAlias().empty()) { + unpivot_entry.alias = expr->GetAlias(); } unpivot_entry.expressions.push_back(std::move(expr)); unpivot_entries.push_back(std::move(unpivot_entry)); @@ -549,12 +549,12 @@ void Binder::ExtractUnpivotEntries(Binder &child_binder, PivotColumnEntry &entry } void Binder::ExtractUnpivotColumnName(ParsedExpression &expr, vector &result) { - if (expr.type == ExpressionType::COLUMN_REF) { + if (expr.GetExpressionType() == ExpressionType::COLUMN_REF) { auto &colref = expr.Cast(); result.push_back(colref.GetColumnName()); return; } - if (expr.type == ExpressionType::SUBQUERY) { + if (expr.GetExpressionType() == ExpressionType::SUBQUERY) { throw BinderException(expr, "UNPIVOT list cannot contain subqueries"); } ParsedExpressionIterator::EnumerateChildren( @@ -607,7 +607,7 @@ unique_ptr Binder::BindUnpivot(Binder &child_binder, PivotRef &ref, } for (auto &col_expr : all_columns) { - if (col_expr->type != ExpressionType::COLUMN_REF) { + if (col_expr->GetExpressionType() != ExpressionType::COLUMN_REF) { throw InternalException("Unexpected child of pivot source - not a ColumnRef"); } auto &columnref = col_expr->Cast(); @@ -668,7 +668,7 @@ unique_ptr Binder::BindUnpivot(Binder &child_binder, PivotRef &ref, vector> unnest_name_children; unnest_name_children.push_back(std::move(unpivot_name_expr)); auto unnest_name_expr = make_uniq("unnest", std::move(unnest_name_children)); - unnest_name_expr->alias = unpivot.unpivot_names[0]; + unnest_name_expr->SetAlias(unpivot.unpivot_names[0]); select_node->select_list.push_back(std::move(unnest_name_expr)); // construct the UNNEST expression for the set of unpivoted columns @@ -682,7 +682,7 @@ unique_ptr Binder::BindUnpivot(Binder &child_binder, PivotRef &ref, unnest_val_children.push_back(std::move(list_expr)); auto unnest_val_expr = make_uniq("unnest", std::move(unnest_val_children)); auto unnest_name = i < ref.column_name_alias.size() ? ref.column_name_alias[i] : ref.unpivot_names[i]; - unnest_val_expr->alias = unnest_name; + unnest_val_expr->SetAlias(unnest_name); select_node->select_list.push_back(std::move(unnest_val_expr)); if (!ref.include_nulls) { // if we are running with EXCLUDE NULLS we need to add an IS NOT NULL filter diff --git a/src/duckdb/src/planner/binder/tableref/bind_showref.cpp b/src/duckdb/src/planner/binder/tableref/bind_showref.cpp index 5a0ddc7f..d61b98f6 100644 --- a/src/duckdb/src/planner/binder/tableref/bind_showref.cpp +++ b/src/duckdb/src/planner/binder/tableref/bind_showref.cpp @@ -43,7 +43,7 @@ BaseTableColumnInfo FindBaseTableColumn(LogicalOperator &op, ColumnBinding bindi break; } auto &expr = projection.expressions[binding.column_index]; - if (expr->type == ExpressionType::BOUND_COLUMN_REF) { + if (expr->GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { // if the projection at this index only has a column reference we can directly trace it to the base table auto &bound_colref = expr->Cast(); return FindBaseTableColumn(*projection.children[0], bound_colref.binding); diff --git a/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp b/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp index e82baf63..2d222b4f 100644 --- a/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp +++ b/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp @@ -108,21 +108,22 @@ bool Binder::BindTableFunctionParameters(TableFunctionCatalogEntry &table_functi string parameter_name; // hack to make named parameters work - if (child->type == ExpressionType::COMPARE_EQUAL) { + if (child->GetExpressionType() == ExpressionType::COMPARE_EQUAL) { // comparison, check if the LHS is a columnref auto &comp = child->Cast(); - if (comp.left->type == ExpressionType::COLUMN_REF) { + if (comp.left->GetExpressionType() == ExpressionType::COLUMN_REF) { auto &colref = comp.left->Cast(); if (!colref.IsQualified()) { parameter_name = colref.GetColumnName(); child = std::move(comp.right); } } - } else if (!child->alias.empty()) { + } else if (!child->GetAlias().empty()) { // => will set the alias of to - parameter_name = child->alias; + parameter_name = child->GetAlias(); } - if (bind_type == TableFunctionBindType::TABLE_PARAMETER_FUNCTION && child->type == ExpressionType::SUBQUERY) { + if (bind_type == TableFunctionBindType::TABLE_PARAMETER_FUNCTION && + child->GetExpressionType() == ExpressionType::SUBQUERY) { D_ASSERT(table_function.functions.Size() == 1); auto fun = table_function.functions.GetFunctionByOffset(0); if (table_function.functions.Size() != 1 || fun.arguments.empty() || @@ -177,7 +178,7 @@ static string GetAlias(const TableFunctionRef &ref) { if (!ref.alias.empty()) { return ref.alias; } - if (ref.function && ref.function->type == ExpressionType::FUNCTION) { + if (ref.function && ref.function->GetExpressionType() == ExpressionType::FUNCTION) { auto &function_expr = ref.function->Cast(); return function_expr.function_name; } @@ -262,7 +263,7 @@ unique_ptr Binder::BindTableFunction(TableFunction &function, v unique_ptr Binder::Bind(TableFunctionRef &ref) { QueryErrorContext error_context(ref.query_location); - D_ASSERT(ref.function->type == ExpressionType::FUNCTION); + D_ASSERT(ref.function->GetExpressionType() == ExpressionType::FUNCTION); auto &fexpr = ref.function->Cast(); string catalog = fexpr.catalog; diff --git a/src/duckdb/src/planner/binder/tableref/plan_joinref.cpp b/src/duckdb/src/planner/binder/tableref/plan_joinref.cpp index 86638d5c..aa96ff85 100644 --- a/src/duckdb/src/planner/binder/tableref/plan_joinref.cpp +++ b/src/duckdb/src/planner/binder/tableref/plan_joinref.cpp @@ -51,13 +51,13 @@ static bool CreateJoinCondition(Expression &expr, const unordered_set &le if (left_side != JoinSide::BOTH && right_side != JoinSide::BOTH) { // join condition can be divided in a left/right side JoinCondition condition; - condition.comparison = expr.type; + condition.comparison = expr.GetExpressionType(); auto left = std::move(comparison.left); auto right = std::move(comparison.right); if (left_side == JoinSide::RIGHT) { // left = right, right = left, flip the comparison symbol and reverse sides swap(left, right); - condition.comparison = FlipComparisonExpression(expr.type); + condition.comparison = FlipComparisonExpression(expr.GetExpressionType()); } condition.left = std::move(left); condition.right = std::move(right); @@ -99,19 +99,20 @@ void LogicalComparisonJoin::ExtractJoinConditions( continue; } } - } else if (expr->type == ExpressionType::COMPARE_EQUAL || expr->type == ExpressionType::COMPARE_NOTEQUAL || - expr->type == ExpressionType::COMPARE_BOUNDARY_START || - expr->type == ExpressionType::COMPARE_LESSTHAN || - expr->type == ExpressionType::COMPARE_GREATERTHAN || - expr->type == ExpressionType::COMPARE_LESSTHANOREQUALTO || - expr->type == ExpressionType::COMPARE_GREATERTHANOREQUALTO || - expr->type == ExpressionType::COMPARE_BOUNDARY_START || - expr->type == ExpressionType::COMPARE_NOT_DISTINCT_FROM || - expr->type == ExpressionType::COMPARE_DISTINCT_FROM) + } else if (expr->GetExpressionType() == ExpressionType::COMPARE_EQUAL || + expr->GetExpressionType() == ExpressionType::COMPARE_NOTEQUAL || + expr->GetExpressionType() == ExpressionType::COMPARE_BOUNDARY_START || + expr->GetExpressionType() == ExpressionType::COMPARE_LESSTHAN || + expr->GetExpressionType() == ExpressionType::COMPARE_GREATERTHAN || + expr->GetExpressionType() == ExpressionType::COMPARE_LESSTHANOREQUALTO || + expr->GetExpressionType() == ExpressionType::COMPARE_GREATERTHANOREQUALTO || + expr->GetExpressionType() == ExpressionType::COMPARE_BOUNDARY_START || + expr->GetExpressionType() == ExpressionType::COMPARE_NOT_DISTINCT_FROM || + expr->GetExpressionType() == ExpressionType::COMPARE_DISTINCT_FROM) { // comparison, check if we can create a comparison JoinCondition - if (IsJoinTypeCondition(ref_type, expr->type) && + if (IsJoinTypeCondition(ref_type, expr->GetExpressionType()) && CreateJoinCondition(*expr, left_bindings, right_bindings, conditions)) { // successfully created the join condition continue; @@ -246,7 +247,7 @@ unique_ptr LogicalComparisonJoin::CreateJoin(ClientContext &con } static bool HasCorrelatedColumns(Expression &expression) { - if (expression.type == ExpressionType::BOUND_COLUMN_REF) { + if (expression.GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { auto &colref = expression.Cast(); if (colref.depth > 0) { return true; diff --git a/src/duckdb/src/planner/bound_parameter_map.cpp b/src/duckdb/src/planner/bound_parameter_map.cpp index aac75230..112a1793 100644 --- a/src/duckdb/src/planner/bound_parameter_map.cpp +++ b/src/duckdb/src/planner/bound_parameter_map.cpp @@ -54,7 +54,7 @@ unique_ptr BoundParameterMap::BindParameterExpression( auto bound_expr = make_uniq(identifier); bound_expr->parameter_data = param_data; - bound_expr->alias = expr.alias; + bound_expr->SetAlias(expr.GetAlias()); auto param_type = param_data->return_type; auto identifier_type = GetReturnType(identifier); diff --git a/src/duckdb/src/planner/expression.cpp b/src/duckdb/src/planner/expression.cpp index 3e9539b0..3eb0118c 100644 --- a/src/duckdb/src/planner/expression.cpp +++ b/src/duckdb/src/planner/expression.cpp @@ -104,7 +104,7 @@ bool Expression::HasSubquery() const { } hash_t Expression::Hash() const { - hash_t hash = duckdb::Hash((uint32_t)type); + hash_t hash = duckdb::Hash(static_cast(type)); hash = CombineHash(hash, return_type.Hash()); ExpressionIterator::EnumerateChildren(*this, [&](const Expression &child) { hash = CombineHash(child.Hash(), hash); }); diff --git a/src/duckdb/src/planner/expression/bound_cast_expression.cpp b/src/duckdb/src/planner/expression/bound_cast_expression.cpp index 2cd3869d..4168bf3e 100644 --- a/src/duckdb/src/planner/expression/bound_cast_expression.cpp +++ b/src/duckdb/src/planner/expression/bound_cast_expression.cpp @@ -42,7 +42,7 @@ unique_ptr AddCastExpressionInternal(unique_ptr expr, co } } auto result = make_uniq(std::move(expr), target_type, std::move(bound_cast), try_cast); - result->query_location = result->child->query_location; + result->SetQueryLocation(result->child->GetQueryLocation()); return std::move(result); } @@ -50,7 +50,7 @@ unique_ptr AddCastToTypeInternal(unique_ptr expr, const CastFunctionSet &cast_functions, GetCastFunctionInput &get_input, bool try_cast) { D_ASSERT(expr); - if (expr->expression_class == ExpressionClass::BOUND_PARAMETER) { + if (expr->GetExpressionClass() == ExpressionClass::BOUND_PARAMETER) { auto ¶meter = expr->Cast(); if (!target_type.IsValid()) { // invalidate the parameter @@ -79,7 +79,7 @@ unique_ptr AddCastToTypeInternal(unique_ptr expr, const parameter.parameter_data->return_type = LogicalType::INVALID; parameter.return_type = target_type; return expr; - } else if (expr->expression_class == ExpressionClass::BOUND_DEFAULT) { + } else if (expr->GetExpressionClass() == ExpressionClass::BOUND_DEFAULT) { D_ASSERT(target_type.IsValid()); auto &def = expr->Cast(); def.return_type = target_type; @@ -96,7 +96,7 @@ unique_ptr BoundCastExpression::AddDefaultCastToType(unique_ptrquery_location; + get_input.query_location = expr->GetQueryLocation(); return AddCastToTypeInternal(std::move(expr), target_type, default_set, get_input, try_cast); } @@ -104,7 +104,7 @@ unique_ptr BoundCastExpression::AddCastToType(ClientContext &context const LogicalType &target_type, bool try_cast) { auto &cast_functions = DBConfig::GetConfig(context).GetCastFunctions(); GetCastFunctionInput get_input(context); - get_input.query_location = expr->query_location; + get_input.query_location = expr->GetQueryLocation(); return AddCastToTypeInternal(std::move(expr), target_type, cast_functions, get_input, try_cast); } diff --git a/src/duckdb/src/planner/expression/bound_expression.cpp b/src/duckdb/src/planner/expression/bound_expression.cpp index 864357ff..b475c4f4 100644 --- a/src/duckdb/src/planner/expression/bound_expression.cpp +++ b/src/duckdb/src/planner/expression/bound_expression.cpp @@ -5,7 +5,7 @@ namespace duckdb { BoundExpression::BoundExpression(unique_ptr expr_p) : ParsedExpression(ExpressionType::INVALID, ExpressionClass::BOUND_EXPRESSION), expr(std::move(expr_p)) { - this->alias = expr->alias; + this->alias = expr->GetAlias(); } unique_ptr &BoundExpression::GetExpression(ParsedExpression &expr) { diff --git a/src/duckdb/src/planner/expression/bound_parameter_expression.cpp b/src/duckdb/src/planner/expression/bound_parameter_expression.cpp index 65357d80..82ceca2d 100644 --- a/src/duckdb/src/planner/expression/bound_parameter_expression.cpp +++ b/src/duckdb/src/planner/expression/bound_parameter_expression.cpp @@ -29,7 +29,7 @@ BoundParameterExpression::BoundParameterExpression(bound_parameter_map_t &global } void BoundParameterExpression::Invalidate(Expression &expr) { - if (expr.type != ExpressionType::VALUE_PARAMETER) { + if (expr.GetExpressionType() != ExpressionType::VALUE_PARAMETER) { throw InternalException("BoundParameterExpression::Invalidate requires a parameter as input"); } auto &bound_parameter = expr.Cast(); @@ -38,7 +38,7 @@ void BoundParameterExpression::Invalidate(Expression &expr) { } void BoundParameterExpression::InvalidateRecursive(Expression &expr) { - if (expr.type == ExpressionType::VALUE_PARAMETER) { + if (expr.GetExpressionType() == ExpressionType::VALUE_PARAMETER) { Invalidate(expr); return; } diff --git a/src/duckdb/src/planner/expression_binder.cpp b/src/duckdb/src/planner/expression_binder.cpp index 7d36654e..d09f796b 100644 --- a/src/duckdb/src/planner/expression_binder.cpp +++ b/src/duckdb/src/planner/expression_binder.cpp @@ -60,7 +60,7 @@ BindResult ExpressionBinder::BindExpression(unique_ptr &expr, auto stack_checker = StackCheck(*expr); auto &expr_ref = *expr; - switch (expr_ref.expression_class) { + switch (expr_ref.GetExpressionClass()) { case ExpressionClass::BETWEEN: return BindExpression(expr_ref.Cast(), depth); case ExpressionClass::CASE: @@ -228,7 +228,7 @@ void ExpressionBinder::BindChild(unique_ptr &expr, idx_t depth } void ExpressionBinder::ExtractCorrelatedExpressions(Binder &binder, Expression &expr) { - if (expr.type == ExpressionType::BOUND_COLUMN_REF) { + if (expr.GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { auto &bound_colref = expr.Cast(); if (bound_colref.depth > 0) { binder.AddCorrelatedColumn(CorrelatedColumnInfo(bound_colref)); @@ -354,9 +354,9 @@ unique_ptr ExpressionBinder::Bind(unique_ptr &expr ErrorData ExpressionBinder::Bind(unique_ptr &expr, idx_t depth, bool root_expression) { // bind the node, but only if it has not been bound yet - auto query_location = expr->query_location; + auto query_location = expr->GetQueryLocation(); auto &expression = *expr; - auto alias = expression.alias; + auto alias = expression.GetAlias(); if (expression.GetExpressionClass() == ExpressionClass::BOUND_EXPRESSION) { // already bound, don't bind it again return ErrorData(); @@ -367,12 +367,12 @@ ErrorData ExpressionBinder::Bind(unique_ptr &expr, idx_t depth return std::move(result.error); } // successfully bound: replace the node with a BoundExpression - result.expression->query_location = query_location; + result.expression->SetQueryLocation(query_location); expr = make_uniq(std::move(result.expression)); auto &be = expr->Cast(); - be.alias = alias; + be.SetAlias(alias); if (!alias.empty()) { - be.expr->alias = alias; + be.expr->SetAlias(alias); } return ErrorData(); } diff --git a/src/duckdb/src/planner/expression_binder/aggregate_binder.cpp b/src/duckdb/src/planner/expression_binder/aggregate_binder.cpp index 353002b5..b02cbf97 100644 --- a/src/duckdb/src/planner/expression_binder/aggregate_binder.cpp +++ b/src/duckdb/src/planner/expression_binder/aggregate_binder.cpp @@ -9,7 +9,7 @@ AggregateBinder::AggregateBinder(Binder &binder, ClientContext &context) : Expre BindResult AggregateBinder::BindExpression(unique_ptr &expr_ptr, idx_t depth, bool root_expression) { auto &expr = *expr_ptr; - switch (expr.expression_class) { + switch (expr.GetExpressionClass()) { case ExpressionClass::WINDOW: throw BinderException::Unsupported(expr, "aggregate function calls cannot contain window function calls"); default: diff --git a/src/duckdb/src/planner/expression_binder/base_select_binder.cpp b/src/duckdb/src/planner/expression_binder/base_select_binder.cpp index a8b1addc..e0adf539 100644 --- a/src/duckdb/src/planner/expression_binder/base_select_binder.cpp +++ b/src/duckdb/src/planner/expression_binder/base_select_binder.cpp @@ -27,7 +27,7 @@ BindResult BaseSelectBinder::BindExpression(unique_ptr &expr_p if (group_index != DConstants::INVALID_INDEX) { return BindGroup(expr, depth, group_index); } - switch (expr.expression_class) { + switch (expr.GetExpressionClass()) { case ExpressionClass::COLUMN_REF: return BindColumnRef(expr_ptr, depth, root_expression); case ExpressionClass::DEFAULT: @@ -41,7 +41,7 @@ BindResult BaseSelectBinder::BindExpression(unique_ptr &expr_p idx_t BaseSelectBinder::TryBindGroup(ParsedExpression &expr) { // first check the group alias map, if expr is a ColumnRefExpression - if (expr.type == ExpressionType::COLUMN_REF) { + if (expr.GetExpressionType() == ExpressionType::COLUMN_REF) { auto &colref = expr.Cast(); if (!colref.IsQualified()) { auto alias_entry = info.alias_map.find(colref.column_names[0]); diff --git a/src/duckdb/src/planner/expression_binder/group_binder.cpp b/src/duckdb/src/planner/expression_binder/group_binder.cpp index 36ef5e62..cdec41e1 100644 --- a/src/duckdb/src/planner/expression_binder/group_binder.cpp +++ b/src/duckdb/src/planner/expression_binder/group_binder.cpp @@ -18,7 +18,7 @@ GroupBinder::GroupBinder(Binder &binder, ClientContext &context, SelectNode &nod BindResult GroupBinder::BindExpression(unique_ptr &expr_ptr, idx_t depth, bool root_expression) { auto &expr = *expr_ptr; if (root_expression && depth == 0) { - switch (expr.expression_class) { + switch (expr.GetExpressionClass()) { case ExpressionClass::COLUMN_REF: return BindColumnRef(expr.Cast()); case ExpressionClass::CONSTANT: @@ -29,7 +29,7 @@ BindResult GroupBinder::BindExpression(unique_ptr &expr_ptr, i break; } } - switch (expr.expression_class) { + switch (expr.GetExpressionClass()) { case ExpressionClass::DEFAULT: return BindUnsupportedExpression(expr, depth, "GROUP BY clause cannot contain DEFAULT clause"); case ExpressionClass::WINDOW: diff --git a/src/duckdb/src/planner/expression_binder/index_binder.cpp b/src/duckdb/src/planner/expression_binder/index_binder.cpp index a890ffd5..1d9d46bb 100644 --- a/src/duckdb/src/planner/expression_binder/index_binder.cpp +++ b/src/duckdb/src/planner/expression_binder/index_binder.cpp @@ -96,7 +96,7 @@ unique_ptr IndexBinder::BindCreateIndex(ClientContext &context, BindResult IndexBinder::BindExpression(unique_ptr &expr_ptr, idx_t depth, bool root_expression) { auto &expr = *expr_ptr; - switch (expr.expression_class) { + switch (expr.GetExpressionClass()) { case ExpressionClass::WINDOW: return BindResult(BinderException::Unsupported(expr, "window functions are not allowed in index expressions")); case ExpressionClass::SUBQUERY: diff --git a/src/duckdb/src/planner/expression_binder/lateral_binder.cpp b/src/duckdb/src/planner/expression_binder/lateral_binder.cpp index a2c56611..205b644e 100644 --- a/src/duckdb/src/planner/expression_binder/lateral_binder.cpp +++ b/src/duckdb/src/planner/expression_binder/lateral_binder.cpp @@ -11,7 +11,7 @@ LateralBinder::LateralBinder(Binder &binder, ClientContext &context) : Expressio } void LateralBinder::ExtractCorrelatedColumns(Expression &expr) { - if (expr.type == ExpressionType::BOUND_COLUMN_REF) { + if (expr.GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { auto &bound_colref = expr.Cast(); if (bound_colref.depth > 0) { // add the correlated column info @@ -88,9 +88,9 @@ class ExpressionDepthReducerRecursive : public BoundNodeVisitor { } void VisitExpression(unique_ptr &expression) override { - if (expression->type == ExpressionType::BOUND_COLUMN_REF) { + if (expression->GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { ReduceColumnRefDepth(expression->Cast(), correlated_columns); - } else if (expression->type == ExpressionType::SUBQUERY) { + } else if (expression->GetExpressionType() == ExpressionType::SUBQUERY) { ReduceExpressionSubquery(expression->Cast(), correlated_columns); } BoundNodeVisitor::VisitExpression(expression); diff --git a/src/duckdb/src/planner/expression_binder/order_binder.cpp b/src/duckdb/src/planner/expression_binder/order_binder.cpp index ff864bbb..af78102b 100644 --- a/src/duckdb/src/planner/expression_binder/order_binder.cpp +++ b/src/duckdb/src/planner/expression_binder/order_binder.cpp @@ -30,13 +30,13 @@ unique_ptr OrderBinder::CreateProjectionReference(ParsedExpression & if (extra_list && index < extra_list->size()) { alias = extra_list->at(index)->ToString(); } else { - if (!expr.alias.empty()) { - alias = expr.alias; + if (!expr.GetAlias().empty()) { + alias = expr.GetAlias(); } } auto result = make_uniq(Value::UBIGINT(index)); - result->alias = std::move(alias); - result->query_location = expr.query_location; + result->SetAlias(std::move(alias)); + result->SetQueryLocation(expr.GetQueryLocation()); return std::move(result); } @@ -51,7 +51,7 @@ unique_ptr OrderBinder::CreateExtraReference(unique_ptr(); // ORDER BY a constant @@ -112,8 +112,8 @@ unique_ptr OrderBinder::BindConstant(ParsedExpression &expr) { child_list_t values; values.push_back(make_pair("index", Value::UBIGINT(index.GetIndex()))); auto result = make_uniq(Value::STRUCT(std::move(values))); - result->alias = std::move(expr.alias); - result->query_location = expr.query_location; + result->SetAlias(expr.GetAlias()); + result->SetQueryLocation(expr.GetQueryLocation()); return std::move(result); } @@ -123,7 +123,7 @@ unique_ptr OrderBinder::Bind(unique_ptr expr) { // if there is no matching entry in the SELECT list already, we add the expression to the SELECT list and refer the // new expression the new entry will then be bound later during the binding of the SELECT list we also don't do type // resolution here: this only happens after the SELECT list has been bound - switch (expr->expression_class) { + switch (expr->GetExpressionClass()) { case ExpressionClass::CONSTANT: { // ORDER BY constant // is the ORDER BY expression a constant integer? (e.g. ORDER BY 1) diff --git a/src/duckdb/src/planner/expression_binder/relation_binder.cpp b/src/duckdb/src/planner/expression_binder/relation_binder.cpp index d6cfe83c..10a0516c 100644 --- a/src/duckdb/src/planner/expression_binder/relation_binder.cpp +++ b/src/duckdb/src/planner/expression_binder/relation_binder.cpp @@ -8,7 +8,7 @@ RelationBinder::RelationBinder(Binder &binder, ClientContext &context, string op BindResult RelationBinder::BindExpression(unique_ptr &expr_ptr, idx_t depth, bool root_expression) { auto &expr = *expr_ptr; - switch (expr.expression_class) { + switch (expr.GetExpressionClass()) { case ExpressionClass::AGGREGATE: return BindResult(BinderException::Unsupported(expr, "aggregate functions are not allowed in " + op)); case ExpressionClass::DEFAULT: diff --git a/src/duckdb/src/planner/expression_binder/select_bind_state.cpp b/src/duckdb/src/planner/expression_binder/select_bind_state.cpp index 23ada81d..dbdbcf0f 100644 --- a/src/duckdb/src/planner/expression_binder/select_bind_state.cpp +++ b/src/duckdb/src/planner/expression_binder/select_bind_state.cpp @@ -7,7 +7,7 @@ unique_ptr SelectBindState::BindAlias(idx_t index) { if (volatile_expressions.find(index) != volatile_expressions.end()) { throw BinderException("Alias \"%s\" referenced - but the expression has side " "effects. This is not yet supported.", - original_expressions[index]->alias); + original_expressions[index]->GetAlias()); } referenced_aliases.insert(index); return original_expressions[index]->Copy(); @@ -18,7 +18,7 @@ void SelectBindState::SetExpressionIsVolatile(idx_t index) { if (referenced_aliases.find(index) != referenced_aliases.end()) { throw BinderException("Alias \"%s\" referenced - but the expression has side " "effects. This is not yet supported.", - original_expressions[index]->alias); + original_expressions[index]->GetAlias()); } volatile_expressions.insert(index); } diff --git a/src/duckdb/src/planner/expression_binder/table_function_binder.cpp b/src/duckdb/src/planner/expression_binder/table_function_binder.cpp index f1bdac9c..fca04a10 100644 --- a/src/duckdb/src/planner/expression_binder/table_function_binder.cpp +++ b/src/duckdb/src/planner/expression_binder/table_function_binder.cpp @@ -30,7 +30,7 @@ BindResult TableFunctionBinder::BindColumnReference(unique_ptr throw ParameterNotResolvedException(); } } - auto query_location = col_ref.query_location; + auto query_location = col_ref.GetQueryLocation(); auto column_names = col_ref.column_names; auto result_name = StringUtil::Join(column_names, "."); if (!table_function_name.empty()) { diff --git a/src/duckdb/src/planner/expression_binder/update_binder.cpp b/src/duckdb/src/planner/expression_binder/update_binder.cpp index b3f7e638..5d69e94b 100644 --- a/src/duckdb/src/planner/expression_binder/update_binder.cpp +++ b/src/duckdb/src/planner/expression_binder/update_binder.cpp @@ -7,7 +7,7 @@ UpdateBinder::UpdateBinder(Binder &binder, ClientContext &context) : ExpressionB BindResult UpdateBinder::BindExpression(unique_ptr &expr_ptr, idx_t depth, bool root_expression) { auto &expr = *expr_ptr; - switch (expr.expression_class) { + switch (expr.GetExpressionClass()) { case ExpressionClass::WINDOW: return BindResult(BinderException::Unsupported(expr, "window functions are not allowed in UPDATE")); default: diff --git a/src/duckdb/src/planner/expression_iterator.cpp b/src/duckdb/src/planner/expression_iterator.cpp index 31f4fccc..af2afe82 100644 --- a/src/duckdb/src/planner/expression_iterator.cpp +++ b/src/duckdb/src/planner/expression_iterator.cpp @@ -22,7 +22,7 @@ void ExpressionIterator::EnumerateChildren(Expression &expr, const std::function void ExpressionIterator::EnumerateChildren(Expression &expr, const std::function &child)> &callback) { - switch (expr.expression_class) { + switch (expr.GetExpressionClass()) { case ExpressionClass::BOUND_AGGREGATE: { auto &aggr_expr = expr.Cast(); for (auto &child : aggr_expr.children) { diff --git a/src/duckdb/src/planner/joinside.cpp b/src/duckdb/src/planner/joinside.cpp index 38cf0f68..b4c571b9 100644 --- a/src/duckdb/src/planner/joinside.cpp +++ b/src/duckdb/src/planner/joinside.cpp @@ -57,15 +57,15 @@ JoinSide JoinSide::GetJoinSide(idx_t table_binding, const unordered_set & JoinSide JoinSide::GetJoinSide(Expression &expression, const unordered_set &left_bindings, const unordered_set &right_bindings) { - if (expression.type == ExpressionType::BOUND_COLUMN_REF) { + if (expression.GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { auto &colref = expression.Cast(); if (colref.depth > 0) { throw NotImplementedException("Non-inner join on correlated columns not supported"); } return GetJoinSide(colref.binding.table_index, left_bindings, right_bindings); } - D_ASSERT(expression.type != ExpressionType::BOUND_REF); - if (expression.type == ExpressionType::SUBQUERY) { + D_ASSERT(expression.GetExpressionType() != ExpressionType::BOUND_REF); + if (expression.GetExpressionType() == ExpressionType::SUBQUERY) { D_ASSERT(expression.GetExpressionClass() == ExpressionClass::BOUND_SUBQUERY); auto &subquery = expression.Cast(); JoinSide side = JoinSide::NONE; diff --git a/src/duckdb/src/planner/operator/logical_filter.cpp b/src/duckdb/src/planner/operator/logical_filter.cpp index 4fc18c08..aa9b2164 100644 --- a/src/duckdb/src/planner/operator/logical_filter.cpp +++ b/src/duckdb/src/planner/operator/logical_filter.cpp @@ -25,7 +25,7 @@ vector LogicalFilter::GetColumnBindings() { bool LogicalFilter::SplitPredicates(vector> &expressions) { bool found_conjunction = false; for (idx_t i = 0; i < expressions.size(); i++) { - if (expressions[i]->type == ExpressionType::CONJUNCTION_AND) { + if (expressions[i]->GetExpressionType() == ExpressionType::CONJUNCTION_AND) { auto &conjunction = expressions[i]->Cast(); found_conjunction = true; // AND expression, append the other children diff --git a/src/duckdb/src/planner/operator/logical_join.cpp b/src/duckdb/src/planner/operator/logical_join.cpp index eacf7b8e..9545e660 100644 --- a/src/duckdb/src/planner/operator/logical_join.cpp +++ b/src/duckdb/src/planner/operator/logical_join.cpp @@ -58,7 +58,7 @@ void LogicalJoin::GetTableReferences(LogicalOperator &op, unordered_set & } void LogicalJoin::GetExpressionBindings(Expression &expr, unordered_set &bindings) { - if (expr.type == ExpressionType::BOUND_COLUMN_REF) { + if (expr.GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { auto &colref = expr.Cast(); D_ASSERT(colref.depth == 0); bindings.insert(colref.binding.table_index); diff --git a/src/duckdb/src/planner/subquery/flatten_dependent_join.cpp b/src/duckdb/src/planner/subquery/flatten_dependent_join.cpp index d6070a6e..da4336a4 100644 --- a/src/duckdb/src/planner/subquery/flatten_dependent_join.cpp +++ b/src/duckdb/src/planner/subquery/flatten_dependent_join.cpp @@ -100,7 +100,7 @@ unique_ptr FlattenDependentJoins::PushDownDependentJoin(unique_ } bool SubqueryDependentFilter(Expression &expr) { - if (expr.expression_class == ExpressionClass::BOUND_CONJUNCTION && + if (expr.GetExpressionClass() == ExpressionClass::BOUND_CONJUNCTION && expr.GetExpressionType() == ExpressionType::CONJUNCTION_AND) { auto &bound_conjunction = expr.Cast(); for (auto &child : bound_conjunction.children) { @@ -109,7 +109,7 @@ bool SubqueryDependentFilter(Expression &expr) { } } } - if (expr.expression_class == ExpressionClass::BOUND_SUBQUERY) { + if (expr.GetExpressionClass() == ExpressionClass::BOUND_SUBQUERY) { return true; } return false; diff --git a/src/duckdb/src/planner/subquery/rewrite_correlated_expressions.cpp b/src/duckdb/src/planner/subquery/rewrite_correlated_expressions.cpp index 00444dcf..61c9c7ba 100644 --- a/src/duckdb/src/planner/subquery/rewrite_correlated_expressions.cpp +++ b/src/duckdb/src/planner/subquery/rewrite_correlated_expressions.cpp @@ -132,7 +132,7 @@ void RewriteCorrelatedRecursive::RewriteCorrelatedSubquery(Binder &binder, Bound } void RewriteCorrelatedRecursive::VisitExpression(unique_ptr &expression) { - if (expression->type == ExpressionType::BOUND_COLUMN_REF) { + if (expression->GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { // bound column reference auto &bound_colref = expression->Cast(); if (bound_colref.depth == 0) { @@ -148,7 +148,7 @@ void RewriteCorrelatedRecursive::VisitExpression(unique_ptr &express bound_colref.binding = ColumnBinding(base_binding.table_index, base_binding.column_index + entry->second); bound_colref.depth--; } - } else if (expression->type == ExpressionType::SUBQUERY) { + } else if (expression->GetExpressionType() == ExpressionType::SUBQUERY) { // we encountered another subquery: rewrite recursively auto &bound_subquery = expression->Cast(); RewriteCorrelatedSubquery(*bound_subquery.binder, *bound_subquery.subquery); diff --git a/src/duckdb/src/planner/table_binding.cpp b/src/duckdb/src/planner/table_binding.cpp index 92ae84d2..119db130 100644 --- a/src/duckdb/src/planner/table_binding.cpp +++ b/src/duckdb/src/planner/table_binding.cpp @@ -73,8 +73,8 @@ BindResult Binding::Bind(ColumnRefExpression &colref, idx_t depth) { binding.table_index = index; binding.column_index = column_index; LogicalType sql_type = types[column_index]; - if (colref.alias.empty()) { - colref.alias = names[column_index]; + if (colref.GetAlias().empty()) { + colref.SetAlias(names[column_index]); } return BindResult(make_uniq(colref.GetName(), sql_type, binding, depth)); } @@ -126,7 +126,7 @@ TableBinding::TableBinding(const string &alias, vector types_p, vec static void ReplaceAliases(ParsedExpression &expr, const ColumnList &list, const unordered_map &alias_map) { - if (expr.type == ExpressionType::COLUMN_REF) { + if (expr.GetExpressionType() == ExpressionType::COLUMN_REF) { auto &colref = expr.Cast(); D_ASSERT(!colref.IsQualified()); auto &col_names = colref.column_names; @@ -140,7 +140,7 @@ static void ReplaceAliases(ParsedExpression &expr, const ColumnList &list, } static void BakeTableName(ParsedExpression &expr, const BindingAlias &binding_alias) { - if (expr.type == ExpressionType::COLUMN_REF) { + if (expr.GetExpressionType() == ExpressionType::COLUMN_REF) { auto &colref = expr.Cast(); D_ASSERT(!colref.IsQualified()); auto &col_names = colref.column_names; @@ -242,8 +242,8 @@ BindResult TableBinding::Bind(ColumnRefExpression &colref, idx_t depth) { } else { // normal column: fetch type from base column col_type = types[column_index]; - if (colref.alias.empty()) { - colref.alias = names[column_index]; + if (colref.GetAlias().empty()) { + colref.SetAlias(names[column_index]); } } ColumnBinding binding = GetColumnBinding(column_index); @@ -293,7 +293,7 @@ unique_ptr DummyBinding::ParamToArg(ColumnRefExpression &colre throw InternalException("Column %s not found in macro", colref.GetColumnName()); } auto arg = (*arguments)[column_index]->Copy(); - arg->alias = colref.alias; + arg->SetAlias(colref.GetAlias()); return arg; } diff --git a/src/duckdb/src/storage/compression/bitpacking.cpp b/src/duckdb/src/storage/compression/bitpacking.cpp index 0d5cd171..aa7f2487 100644 --- a/src/duckdb/src/storage/compression/bitpacking.cpp +++ b/src/duckdb/src/storage/compression/bitpacking.cpp @@ -500,7 +500,6 @@ struct BitpackingCompressState : public CompressionState { auto compressed_segment = ColumnSegment::CreateTransientSegment(db, function, type, row_start, info.GetBlockSize(), info.GetBlockSize()); - compressed_segment->function = function; current_segment = std::move(compressed_segment); auto &buffer_manager = BufferManager::GetBufferManager(db); diff --git a/src/duckdb/src/storage/compression/dictionary/compression.cpp b/src/duckdb/src/storage/compression/dictionary/compression.cpp index eeb42953..0b9a47e9 100644 --- a/src/duckdb/src/storage/compression/dictionary/compression.cpp +++ b/src/duckdb/src/storage/compression/dictionary/compression.cpp @@ -18,7 +18,6 @@ void DictionaryCompressionCompressState::CreateEmptySegment(idx_t row_start) { auto compressed_segment = ColumnSegment::CreateTransientSegment(db, function, type, row_start, info.GetBlockSize(), info.GetBlockSize()); current_segment = std::move(compressed_segment); - current_segment->function = function; // Reset the buffers and the string map. current_string_map.clear(); diff --git a/src/duckdb/src/storage/compression/fsst.cpp b/src/duckdb/src/storage/compression/fsst.cpp index bad01783..6d0bb9b3 100644 --- a/src/duckdb/src/storage/compression/fsst.cpp +++ b/src/duckdb/src/storage/compression/fsst.cpp @@ -240,7 +240,6 @@ class FSSTCompressionState : public CompressionState { auto compressed_segment = ColumnSegment::CreateTransientSegment(db, function, type, row_start, info.GetBlockSize(), info.GetBlockSize()); current_segment = std::move(compressed_segment); - current_segment->function = function; Reset(); } diff --git a/src/duckdb/src/storage/compression/rle.cpp b/src/duckdb/src/storage/compression/rle.cpp index d7ea929a..d453f9b8 100644 --- a/src/duckdb/src/storage/compression/rle.cpp +++ b/src/duckdb/src/storage/compression/rle.cpp @@ -152,7 +152,6 @@ struct RLECompressState : public CompressionState { auto column_segment = ColumnSegment::CreateTransientSegment(db, function, type, row_start, info.GetBlockSize(), info.GetBlockSize()); - column_segment->function = function; current_segment = std::move(column_segment); auto &buffer_manager = BufferManager::GetBufferManager(db); diff --git a/src/duckdb/src/storage/compression/roaring/compress.cpp b/src/duckdb/src/storage/compression/roaring/compress.cpp index 1430178d..7de695b9 100644 --- a/src/duckdb/src/storage/compression/roaring/compress.cpp +++ b/src/duckdb/src/storage/compression/roaring/compress.cpp @@ -281,7 +281,6 @@ void RoaringCompressState::CreateEmptySegment(idx_t row_start) { auto compressed_segment = ColumnSegment::CreateTransientSegment(db, function, type, row_start, info.GetBlockSize(), info.GetBlockSize()); - compressed_segment->function = function; current_segment = std::move(compressed_segment); auto &buffer_manager = BufferManager::GetBufferManager(db); diff --git a/src/duckdb/src/storage/compression/zstd.cpp b/src/duckdb/src/storage/compression/zstd.cpp index 4ac798a5..945cd644 100644 --- a/src/duckdb/src/storage/compression/zstd.cpp +++ b/src/duckdb/src/storage/compression/zstd.cpp @@ -522,7 +522,6 @@ class ZSTDCompressionState : public CompressionState { auto compressed_segment = ColumnSegment::CreateTransientSegment(db, function, type, row_start, info.GetBlockSize(), info.GetBlockSize()); segment = std::move(compressed_segment); - segment->function = function; auto &buffer_manager = BufferManager::GetBufferManager(checkpointer.GetDatabase()); segment_handle = buffer_manager.Pin(segment->block); @@ -889,7 +888,7 @@ struct ZSTDScanState : public SegmentScanState { void ScanInternal(ZSTDVectorScanState &scan_state, idx_t count, Vector &result, idx_t result_offset) { D_ASSERT(scan_state.scanned_count + count <= scan_state.metadata.count); - D_ASSERT(result.GetType().id() == LogicalTypeId::VARCHAR); + D_ASSERT(result.GetType().InternalType() == PhysicalType::VARCHAR); string_length_t *string_lengths = &scan_state.string_lengths[scan_state.scanned_count]; idx_t uncompressed_length = 0; diff --git a/src/duckdb/src/storage/table/column_checkpoint_state.cpp b/src/duckdb/src/storage/table/column_checkpoint_state.cpp index b6c1da0a..a67daa06 100644 --- a/src/duckdb/src/storage/table/column_checkpoint_state.cpp +++ b/src/duckdb/src/storage/table/column_checkpoint_state.cpp @@ -171,11 +171,6 @@ void ColumnCheckpointState::FlushSegmentInternal(unique_ptr segme // Writer will decide whether to reuse this block. partial_block_manager.RegisterPartialBlock(std::move(allocation)); } else { - // constant block: no need to write anything to disk besides the stats - // set up the compression function to constant - auto &config = DBConfig::GetConfig(db); - segment->function = - *config.GetCompressionFunction(CompressionType::COMPRESSION_CONSTANT, segment->type.InternalType()); segment->ConvertToPersistent(nullptr, INVALID_BLOCK); } @@ -189,9 +184,10 @@ void ColumnCheckpointState::FlushSegmentInternal(unique_ptr segme data_pointer.row_start = last_pointer.row_start + last_pointer.tuple_count; } data_pointer.tuple_count = tuple_count; - data_pointer.compression_type = segment->function.get().type; - if (segment->function.get().serialize_state) { - data_pointer.segment_state = segment->function.get().serialize_state(*segment); + auto &compression_function = segment->GetCompressionFunction(); + data_pointer.compression_type = compression_function.type; + if (compression_function.serialize_state) { + data_pointer.segment_state = compression_function.serialize_state(*segment); } // append the segment to the new segment tree diff --git a/src/duckdb/src/storage/table/column_data.cpp b/src/duckdb/src/storage/table/column_data.cpp index 56b74a67..7db0c535 100644 --- a/src/duckdb/src/storage/table/column_data.cpp +++ b/src/duckdb/src/storage/table/column_data.cpp @@ -438,7 +438,7 @@ void ColumnData::InitializeAppend(ColumnAppendState &state) { AppendTransientSegment(l, start); } auto segment = data.GetLastSegment(l); - if (segment->segment_type == ColumnSegmentType::PERSISTENT || !segment->function.get().init_append) { + if (segment->segment_type == ColumnSegmentType::PERSISTENT || !segment->GetCompressionFunction().init_append) { // we cannot append to this segment - append a new segment auto total_rows = segment->start + segment->count; AppendTransientSegment(l, total_rows); @@ -449,7 +449,7 @@ void ColumnData::InitializeAppend(ColumnAppendState &state) { D_ASSERT(state.current->segment_type == ColumnSegmentType::TRANSIENT); state.current->InitializeAppend(state); - D_ASSERT(state.current->function.get().append); + D_ASSERT(state.current->GetCompressionFunction().append); } void ColumnData::AppendData(BaseStatistics &append_stats, ColumnAppendState &state, UnifiedVectorFormat &vdata, @@ -565,7 +565,7 @@ void ColumnData::AppendTransientSegment(SegmentLock &l, idx_t start_row) { AppendSegment(l, std::move(new_segment)); } -void ColumnData::UpdateCompressionFunction(SegmentLock &l, CompressionFunction &function) { +void ColumnData::UpdateCompressionFunction(SegmentLock &l, const CompressionFunction &function) { if (!compression) { // compression is empty... // if we have no segments - we have not set it yet, so assign it @@ -581,7 +581,7 @@ void ColumnData::UpdateCompressionFunction(SegmentLock &l, CompressionFunction & } void ColumnData::AppendSegment(SegmentLock &l, unique_ptr segment) { - UpdateCompressionFunction(l, segment->function); + UpdateCompressionFunction(l, segment->GetCompressionFunction()); data.AppendSegment(l, std::move(segment)); } @@ -874,7 +874,7 @@ void ColumnData::GetColumnSegmentInfo(idx_t row_group_index, vector col_p column_info.segment_type = type.ToString(); column_info.segment_start = segment->start; column_info.segment_count = segment->count; - column_info.compression_type = CompressionTypeToString(segment->function.get().type); + column_info.compression_type = CompressionTypeToString(segment->GetCompressionFunction().type); { lock_guard l(stats_lock); column_info.segment_stats = segment->stats.statistics.ToString(); diff --git a/src/duckdb/src/storage/table/column_segment.cpp b/src/duckdb/src/storage/table/column_segment.cpp index 491096b7..207c663f 100644 --- a/src/duckdb/src/storage/table/column_segment.cpp +++ b/src/duckdb/src/storage/table/column_segment.cpp @@ -67,7 +67,7 @@ ColumnSegment::ColumnSegment(DatabaseInstance &db, shared_ptr block const unique_ptr segment_state_p) : SegmentBase(start, count), db(db), type(type), type_size(GetTypeIdSize(type.InternalType())), - segment_type(segment_type), function(function_p), stats(std::move(statistics)), block(std::move(block_p)), + segment_type(segment_type), stats(std::move(statistics)), block(std::move(block_p)), function(function_p), block_id(block_id_p), offset(offset), segment_size(segment_size_p) { if (function.get().init_segment) { @@ -81,8 +81,8 @@ ColumnSegment::ColumnSegment(DatabaseInstance &db, shared_ptr block ColumnSegment::ColumnSegment(ColumnSegment &other, const idx_t start) : SegmentBase(start, other.count.load()), db(other.db), type(std::move(other.type)), - type_size(other.type_size), segment_type(other.segment_type), function(other.function), - stats(std::move(other.stats)), block(std::move(other.block)), block_id(other.block_id), offset(other.offset), + type_size(other.type_size), segment_type(other.segment_type), stats(std::move(other.stats)), + block(std::move(other.block)), function(other.function), block_id(other.block_id), offset(other.offset), segment_size(other.segment_size), segment_state(std::move(other.segment_state)) { // For constant segments (CompressionType::COMPRESSION_CONSTANT) the block is a nullptr. @@ -228,8 +228,12 @@ void ColumnSegment::ConvertToPersistent(optional_ptr block_manager offset = 0; if (block_id == INVALID_BLOCK) { - // constant block: reset the block buffer + // constant block: no need to write anything to disk besides the stats + // set up the compression function to constant D_ASSERT(stats.statistics.IsConstant()); + auto &config = DBConfig::GetConfig(db); + function = *config.GetCompressionFunction(CompressionType::COMPRESSION_CONSTANT, type.InternalType()); + // reset the block buffer block.reset(); } else { D_ASSERT(!stats.statistics.IsConstant()); @@ -550,4 +554,8 @@ idx_t ColumnSegment::FilterSelection(SelectionVector &sel, Vector &vector, Unifi } } +const CompressionFunction &ColumnSegment::GetCompressionFunction() { + return function.get(); +} + } // namespace duckdb diff --git a/src/duckdb/src/verification/prepared_statement_verifier.cpp b/src/duckdb/src/verification/prepared_statement_verifier.cpp index 9199bed5..2458d471 100644 --- a/src/duckdb/src/verification/prepared_statement_verifier.cpp +++ b/src/duckdb/src/verification/prepared_statement_verifier.cpp @@ -48,10 +48,10 @@ void PreparedStatementVerifier::Extract() { } void PreparedStatementVerifier::ConvertConstants(unique_ptr &child) { - if (child->type == ExpressionType::VALUE_CONSTANT) { + if (child->GetExpressionType() == ExpressionType::VALUE_CONSTANT) { // constant: extract the constant value - auto alias = child->alias; - child->alias = string(); + auto alias = child->GetAlias(); + child->ClearAlias(); // check if the value already exists idx_t index = values.size(); auto identifier = std::to_string(index + 1); @@ -69,7 +69,7 @@ void PreparedStatementVerifier::ConvertConstants(unique_ptr &c // replace it with an expression auto parameter = make_uniq(); parameter->identifier = identifier; - parameter->alias = alias; + parameter->SetAlias(alias); child = std::move(parameter); return; }